Weapon upgrade system, tips?
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!)
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!)
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Weapon upgrade system, tips?
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?
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?
Re: Weapon upgrade system, tips?
I don't think it's possible using only DECORATE.
I made it work using ACS and DECORATE, or just ZScript.
I made it work using ACS and DECORATE, or just ZScript.
Spoiler: DECORATE and ACS method
Spoiler: ZScript method
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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.
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.
Re: Weapon upgrade system, tips?
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:
Where UpgradeConfirm would be a dummy powerup that lasts some time. (For example 4 seconds or so)
Then put the actual upgrade code in the UpgradeWeaponXReally state.
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
Code: Select all
ACTOR UpgradeConfirm : Powerup
{
Powerup.Duration -4 //Negative duration is in seconds, positive duration is in tics: -4 is 140
}
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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.
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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?
I tried this as the final solution, i'm gonna look stupid if its something minor. Any 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
}
}
Re: Weapon upgrade system, tips?
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)
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)
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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.
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
Re: Weapon upgrade system, tips?
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.
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.
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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
}
}
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
Hey, i think you're supposed to use "ACS_ExecuteWithResult", no? I've looking into the wiki and this might be the error.
Re: Weapon upgrade system, tips?
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?
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?
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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?
Re: Weapon upgrade system, tips?
When it comes to adding a library to scripts, it only needs one line at the beginning of the script file:
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?
Code: Select all
#library "modname"
#include "zcommon.acs"
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?
-
- Posts: 380
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: Weapon upgrade system, tips?
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
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!

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!