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?
Re: Weapon upgrade system, tips?
Posted: Sun Aug 02, 2020 11:58 am
by Jarewill
I don't think it's possible using only DECORATE.
I made it work using ACS and DECORATE, or just ZScript.
Script "CheckWeapon" (void)
{
If(CheckWeapon("weapon1")){SetResultValue(1); Terminate;} //If currently selected weapon is "weapon1", set result value as 1 and terminate script
Else If(CheckWeapon("weapon2")){SetResultValue(2); Terminate;} //If weapon is "weapon2", set result value as 2
Else If(CheckWeapon("weapon3")){SetResultValue(3); Terminate;}
//So on
}
And then have a CustomInventory that has this as it's Use state:
Use:
TNT1 A 0 A_JumpIf(CallACS("CheckWeapon",0,0,0)==1,"UpgradeWeapon1") //If ACS returns 1, jump to "UpgradeWeapon1" state
TNT1 A 0 A_JumpIf(CallACS("CheckWeapon",0,0,0)==2,"UpgradeWeapon2") //If ACS returns 2, jump there
TNT1 A 0 A_JumpIf(CallACS("CheckWeapon",0,0,0)==3,"UpgradeWeapon3")
TNT1 A 0 A_Log("This weapon cannot be upgraded.")
Fail
In states "UpgradeWeaponX" you can make a check on how much item the player has and change weapons or such.
Keep in mind that if you make it replace a weapon with another weapon, you would also need to make your weapon pickups CustomInventory-based to also give ammo if the player has an upgraded version and not give the original weapon back.
For making an item spawn randomly next to a weapon, add a random check in the weapon's spawn state:
Spawn:
TNT1 A 0 NoDelay {If(random(1,4)==1){A_SpawnItemEx("UpgradeItem",Random(-16,16),Random(-16,16));}}
SGN2 A -1 //25% chance to spawn the item ^
Stop
Spoiler: ZScript method
Make a CustomInventory actor and in it's Use state have this:
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.
Re: Weapon upgrade system, tips?
Posted: Sun Aug 02, 2020 1:23 pm
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:
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)
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.
Re: Weapon upgrade system, tips?
Posted: Sun Aug 02, 2020 1:51 pm
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.
Re: Weapon upgrade system, tips?
Posted: Tue Aug 04, 2020 9:08 pm
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?
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?
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 1:10 am
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)
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 7:39 am
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.
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?
Posted: Wed Aug 05, 2020 7:58 am
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.
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:01 am
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.
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
}
}
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:07 am
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.
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:10 am
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?
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:14 am
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?
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:26 am
by Jarewill
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?
Re: Weapon upgrade system, tips?
Posted: Wed Aug 05, 2020 8:36 am
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
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!