thisbecasper, on 17 October 2017 - 12:05 PM, said:
The game already keeps track of things like ammo counts and current weapon. Attempting to circumvent this by using your own vars at best is a duplication of effort, and at worst is asking for a lot of trouble when you let them get out of sync.
Yeah, currentweapon was a mistake, it should only be used in HUD drawing events.
You're going to need to get comfortable with global scratch variables. While you're at it, take the time to indent your code correctly. (8 spaces per tab stop is unnecessary, use 4 at the max.)
definegamefuncname 36 Switch_Weapon_Function gamevar temp 0 0 gamevar subweapon_choice 0 1 onevent EVENT_TURNAROUND setvar RETURN -1 getplayer[THISACTOR].curr_weapon temp ifvare temp 2 { ifvare subweapon_choice 0 { ifvarl SHOTGUNAMMO 10 { quote 36 break } setvar subweapon_choice 1 sound SELECT_WEAPON setvar WEAPON2_SHOOTS 1092 setvar WEAPON2_SHOTSPERBURST 10 setvar WEAPON2_FIRESOUND PISTOL_RICOCHET setvar WEAPON2_FLAGS 17472 quote 34 } else { setvar subweapon_choice 0 sound SHOTGUN_COCK setvar WEAPON2_SHOOTS SHOTGUN setvar WEAPON2_SHOTSPERBURST 7 setvar WEAPON2_FIRESOUND SHOTGUN_FIRE setvar WEAPON2_FLAGS 1024 quote 35 } } endevent onevent EVENT_DOFIRE getplayer[THISACTOR].curr_weapon temp ifvare temp 2 { ifvare subweapon_choice 1 { getplayer[THISACTOR].ammo_amount SHOTGUN_WEAPON temp ifvarl temp 10 { setvar subweapon_choice 0 sound SHOTGUN_COCK setvar WEAPON2_SHOOTS SHOTGUN setvar WEAPON2_SHOTSPERBURST 7 setvar WEAPON2_FIRESOUND SHOTGUN_FIRE setvar WEAPON2_FLAGS 1024 quote 40 } } } endevent
Trooper Dan, on 17 October 2017 - 12:11 PM, said:
ifvarl SHOTGUNAMMO 10
you should be able to replace it with
ifvarl player[THISACTOR].ammo_amount 2 10
He's using OldMP, which doesn't support quick structure access. Also, use SHOTGUN_WEAPON instead of the magic constant '2'.