Weapon upgrade system, tips?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Weapon upgrade system, tips?

Post by XASSASSINX »

Hello, i'm making a mod and i'm trying to make a "gear and parts" upgrade system for my mod. basically, some weapons or items when they enter the "Spawn state" have a chance to spawn a certain gear or part that you can pickup and remain in your inventory. This would stay as a number, similar to trailblazer scrap system.

Upon using this inventory item with a weapon in your hand, if you have enough parts to that weapon, it would remove this weapon from your inventory and replace it with another version.

What is a good start to make this system using not so much DECORATE? I"ve looked at trailblazer code and understood some parts of it, and i know how to make the most basics parts, such as the gears inventory items and such, but i'm lost.

Any help? Functions or mods to look at?
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

I don't think it's possible using only DECORATE.
I made it work using ACS and DECORATE, or just ZScript.
Spoiler: DECORATE and ACS method
Spoiler: ZScript method
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Well, after looking at it, it's not so complex. From what i understood, suppose i upgraded weapon 1 to weapon 2, and then i find weapon 1 again, i would have weapon 2 AND weapon 1 in my inventory, correct? As this only replace the said weapon.

The "UpgradeWeaponX" state would do a quick inventory check to see if i had enough "scrap" to upgrade, if yes, Use a simple A_TakeInventory and A_GiveInventory to give said new weapon, and if not, just print on the screen the message displaying that you do not have enough scrap.

One last thing, I'm VERY bad at ACS, so how do you exactly make a "This weapon cost X scrap to upgrade, are you sure?" Do you use a

{
"If {CheckWeapon}{"Weapon1"} == Log{"This weapon costs 50 scraps to upgrade. are you sure?"}
}

Something along those lines.
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

Yes, the player would have both weapon1 and weapon2, so the weapon pickup has to be a CustomInventory with a A_JumpIfInventory check to see if the player already has the upgraded weapon.
Yes, the "UpgradeWeaponX" states would do just that.

As for it needing a confirmation, I think something in DECORATE like this would be better:

Code: Select all

      UpgradeWeapon1:
        TNT1 A 0 A_JumpIfInventory("UpgradeConfirm",1,"UpgradeWeapon1Really")
        TNT1 A 0 A_GiveInventory("UpgradeConfirm",1)
        TNT1 A 0 A_Print("This weapon cost X scrap to upgrade, are you sure?")
        Fail
Where UpgradeConfirm would be a dummy powerup that lasts some time. (For example 4 seconds or so)

Code: Select all

ACTOR UpgradeConfirm : Powerup
{
  Powerup.Duration -4 //Negative duration is in seconds, positive duration is in tics: -4 is 140
} 
Then put the actual upgrade code in the UpgradeWeaponXReally state.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

So in sum, use the custom inventory item, check to see if i have the "UpgradeConfirm", if yes, then do the actual upgrade and weapon replacement and that's it? The upgrade confirm dummy powerup would be given everytime i tried to use the "Scrap" inventory item, pretty much the same in trailblazer.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Hey! Everything worked great, except for the fact that i can upgrade despite any weapon that i'm using? I've looked into everything and i cannot find anything to fix this. Any final help?

Code: Select all

	States
	{
	Spawn:
	 SCBX A -1
	 Stop
	Use:
	 TNT1 A 0 A_JumpIf(CallACS("CheckWeaponHand", 0, 0, 0) == 1, "UpgradeMinigun")
     TNT1 A 0 A_Log("This weapon cannot be upgraded!")
     Fail
    UpgradeMinigun:
	 TNT1 A 0 A_JumpIfInventory("UpgradeConfirm", 1, "UpgradeMinigunTRUE")
	 TNT1 A 0 A_GiveInventory("UpgradeConfirm", 1)
	 TNT1 A 0 A_Print("This upgrade cost 50 scraps. Are you sure? (Use again)")
     Fail
	UpgradeMinigunTrue:
	 TNT1 A 0 A_JumpIf(CallACS("CheckWeaponHand", 0, 0, 0) == 1, "UpgradeMinigunTrue2")
	 TTN1 A 0 A_Print("You cannot upgrade this weapon!")
	 Fail
	UpgradeMinigunTrue2:
	 TNT1 A 0 A_GiveInventory("CZ57")
	 TNT1 A 0 A_TakeInventory("F3Minigun")
	 TNT1 A 0 A_Print("Congratulations, your weapon has upgraded to: Minigun ---> Avenger Minigun")
	 Fail
	}
} 
I tried this as the final solution, i'm gonna look stupid if its something minor. Any help?
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

This was my mistake.
If CallACS successfully calls a script, it will always return 1.
Use result numbers over 1 to fix it. (SetResultValue(2); in ACS and CallACS(script,0,0,0)==2 in DECORATE)
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Oooh, no problem. Yep, this would be another thing that i would never figured out on my own without asking here lol. Gonna test and see if it works. EDIT: Now i can't even reach the weapon upgrade state. This might be my mistake though.

The problem is that it never leaves the "use" state, it only goes immediatly by the "A_Log("This weapon cannot be upgraded!"), I tried to fix it using NoDelay on the first frame, no hope. Let me post the acs to see if theres any small mistake.

Code: Select all

Script "CheckWeaponHand" (void)
{
    If(CheckWeapon("F3minigun")){SetResultValue(2); Terminate;} 
} 

Code: Select all

	
Use:
	 TNT1 A 0 NoDelay A_JumpIf(CallACS("CheckWeaponHand", 0, 0, 0)==2, "UpgradeMinigun")
     TNT1 A 0 A_Log("This weapon cannot be upgraded!")
     Fail
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

I don't see what exactly is wrong here.
Though looking at the previously posted code, there's also another check in the UpgradeMinigunTrue state.
That state isn't exactly needed and can be skipped, so the jump in the UpgradeMinigun state can jump instantly to UpgradeMinigunTrue2.

Also NoDelay only works on Spawn states.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Yeah, this is the final version, I will look more into it, because everything looks fine. It could be a external thing, like file order? Maybe a wrong code in the weapon itself? Just to guarantee, the weapon i use in the ACS WeaponCheck is the Decorate name of the weapon, not the tag or anything like that, the Decorate actor name.

Code: Select all

	
Use:
	 TNT1 A 0 NoDelay A_JumpIf(CallACS("CheckWeaponHand", 0, 0, 0)==2, "UpgradeMinigun")
     TNT1 A 0 A_Log("This weapon cannot be upgraded!")
     Fail
    UpgradeMinigun:
	 TNT1 A 0 A_JumpIfInventory("UpgradeConfirm", 1, "UpgradeMinigun2")
	 TNT1 A 0 A_GiveInventory("UpgradeConfirm", 1)
	 TNT1 A 0 A_Log("This upgrade cost 50 scraps. Are you sure? (Use again)")
     Fail
	UpgradeMinigun2:
	 TNT1 A 0 A_GiveInventory("CZ57")
	 TNT1 A 0 A_TakeInventory("F3Minigun")
	 TNT1 A 0 A_Log("Congratulations, your weapon has upgraded to: Minigun ---> Avenger Minigun")
	 Fail
	}
} 
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Hey, i think you're supposed to use "ACS_ExecuteWithResult", no? I've looking into the wiki and this might be the error.
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

CallACS is a shortened version of ACS_ExecuteWithResult.
It's used so it takes less space.

After copying the code into SLADE and running it, it works fine for me.
Is the script compiled and loaded?
Does the script have a library set up?
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Yes, it's all compiled and correct. About the library, i'm pretty sure its correct, as it was upgrading the gun yesterday, but just to guarantee, how do you "library" it? I've just used a A_START and A_End, and with the regular "LOADACS" to load up the ACS. Do i have to put anything on the beggining of the file?
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon upgrade system, tips?

Post by Jarewill »

When it comes to adding a library to scripts, it only needs one line at the beginning of the script file:

Code: Select all

#library "modname"
#include "zcommon.acs"   
To my knowledge, it helps when loading a gameplay mod with an ACS script with a map with another ACS script.
Otherwise the two somehow get tangled up together and break the scripts.

I'm really not certain what's wrong here.
Try changing the CheckWeapon("F3minigun") into CheckWeapon("F3Minigun"), as it might be case sensitive.

If that doesn't work, could you upload a small example file here so I could see what's wrong?
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Weapon upgrade system, tips?

Post by XASSASSINX »

Oh well, i fixed it, Apparently it was the lack of the "library" of the ACS name, which is weird, because i SWEAR i put it the night before, probably deleted it after coming back of work. oh well :shrug:

Also, i was a bit reluctant to post the file because there are alot of files in this mod, like sprites and such and sending on the example would take some time, but it's fine now.

Thank you so much, i will include your name in the commentaries if this remake of the mod ever see the light of here. have a good day!
Post Reply

Return to “Scripting”