This seems strange to me, considering I've went over the code so many times (even adding desperate DEBUG messages) and nothing's adding up... Everything seems perfectly in order.
**This only happens when it's my first weapon being bought. If I already have more than one weapon, there's no problem.
Here's the 'buy' procedure.
mob
proc
buy(obj/gun/o)
var/obj/gun/w=new o
world<<"[src.lastgun] switches to:"
src.lastgun=w
world<<"[src.lastgun]"
src<<"\red [w] costs [w.value] coins, are you sure you want to buy?"
var/yes=input("[w] costs [w.value] coins, are you sure you want to buy? (You have [src.coins] coins.)") in list("Yes","No")
if(yes=="Yes")
if(w.value>src.coins)
src<<"<b>You don't have enough money."
return
for(var/obj/gun/a in src.weapons)
if(a.name==w.name)
world<<"[a] has [a.ammo] ammo." //desperate DEBUG testing..
a.ammo+=a.maxammo
world<<"[a] has [a.ammo] ammo."
world<<"[src] has [src.ammo] ammo"
src.ammo=a.ammo
world<<"[src] has [src.ammo] ammo"
src.coins-=a.value
src<<"\red Weapon restocked!"
//usr.selected_weapon.update()
src.selection_in_progress=0
I've been trying to figure out what's wrong with it. Is my for loop checking through all the weapons I have wrong? Like is it not 'really' adding the ammo to 'a'? That was one of my many many many suspicions, but I'm not sure. Here's the part of the 'Click' procedure attached to the on-screen weapons: As you can see, I have a large amount of DEBUG tests because I've been stuck on this for so long.
if(usr.selected_weapon) //This is part of a click procedure.
usr.overlays-=usr.selected_weapon
usr.selected_weapon=src.owner
world<<"[usr] has [src.owner.ammo] ammo, as usr.owner.ammo."
world<<"[usr] has [usr.selected_weapon] selected and it has [usr.selected_weapon.ammo] ammo."
usr.selected_weapon.dir=usr.dir
usr.overlays+=usr.selected_weapon
usr.ammo=src.owner.ammo
world<<"[usr] has [usr.selected_weapon] selected and it has [usr.selected_weapon.ammo] ammo."
usr<<"<b>You have equipped <font size=5> \icon [src] </font> ([src])"
usr.selection_in_progress=0
If I'm leaving any pieces of code out, I'll add them in.
Thanks for reading.
EDIT: I'm not sure why the indentation is wrong, just ignore it.