thisbecasper, on 17 October 2017 - 12:05 PM, said:
I think I need the var SHOTGUNAMMO inorder to keep track of current ammo of the shotgun?. Can I do it without the var and without causing an out-of-sync error? I've btw also managed to get rid of the out-of-sync thing - I still don't see the big difference between using a var like I do to keep track of the players current weapon and a call to currentweapon, which was what caused it..
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:
Where you have
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'.