ID:146139
 
Code:
obj/guns/mm  
name = "9mm"
icon = 'Guns.dmi'
icon_state = "9mm"
verb
Equip()
if(usr.weapon) usr << "<font color=red><font size=1>You have another weapon"
else
usr.ammo = 5
usr.mammo = 35
suffix=("Equipped")
usr.weapon = "9mm"
usr.verbs += /mob/gun/verb/Shoot
Unequip()
usr.weapon = null
usr.verbs -= /mob/gun/verb/Shoot
suffix=(null)
usr.ammo = 0
usr.mammo = 0


Problem description:
When you shoot the gun it take away the ammo and clips, but when you unequip and equip it again it has full ammo. I know why it does it, but I can't figure out how to fix it...plz help

    verb
Equip()
if(usr.weapon) usr << "<font color=red><font size=1>You have another weapon"
else
usr.ammo = 5
usr.mammo = 35


You are giving them ammo every time they equip it. Why not have a get() verb so when they pick it up their ammo gets set.
In response to Polaruis
Think how it is in real... there is some ammo in the weapon, but if you use it the weapon has no ammo anymore, so the gun needs an ammo var, which is used and not the player's ammo. The player can only reaload it.
obj/guns
var/ammo
var/maxammo
verb/shot/Shoot()
if(ammo<=0) return
ammo--
//other code
obj/ammo/verb/reload()
var/reloadl=list()
for(var/obj/guns/G in usr.contents)
realoadl+=G
var/obj/gun/reload=input("What do you want to reload?") in reloadl+"Cancel"
if(reload=="Cancel") return
reload.ammo+=10
if(reload.ammo>reload.maxammo) reload.ammo=reload.maxammo
del(src)
In response to CIB
Please for the love of...me :P

Use

for codes!
In response to GhostAnime
I thought I did ^^
In response to CIB
CIB wrote:
I thought I did ^^

Severely need to fix your indentation.
-Sin()
Here, you're having a design issue. Instead of keeping track of the equipped weapon's name, your player.weapon variable should really be keeping track of the weapon object itself.

You're having an HTML problems too. You should close your font tag, and you should have combined those two font tags into one with two attributes, like so:

"<font color=\"red\" size=\"1\">You already have a weapon equipped, so you cannot equip this.</font>"


Why did I put the escaped quotes around "red" and "1"? Well, in HTML, attribute values should have quotes around them. =)
Why not just set the ammo/maxammo var to the wqapon instead of the player?

mob/gun/mm
icon="blah.dmi'
icon_state="gun1"
ammo=5
maxammo=35
verb
Equip(mob/M)
if(!M.weapon)
M.weapon=src
src.suffix="Equipped"
M<<"<font color=\"red\">You equip a gun!</font>"
M.verbs+=/mob/gun/verb/Shoot
else {src<<"<font color=\"yellow\">You already have a gun equipped.</font>"
Unequip(mob/M)
if(M.weapon)
M.weapon=null
src.suffix=null
M<<"<font color=\"blue\">You unequip the gun!</font>"
M.verbs-=/mob/gun/verb/Shoot
else {src<<"<font color=\"yellow\">You don't have a gun equipped!</font>


Since the ammo var is not edited through out the equip code, the ammo var will stay that same, after it was modified somewhere else, so it doesn't refill back to 5, 35 whatever.
In response to Mega fart cannon
You're on the right track here, but any equipment system worth its salt will simply replace an already-equipped item with one you're trying to equip in its place. You need to include an automatic unequip here.

Lummox JR
In response to Wizkidd0123
Wizkidd0123 wrote:
Why did I put the escaped quotes around "red" and "1"? Well, in HTML, attribute values should have quotes around them. =)

That's really more of an XML/XHTML thing, or for extremely anal standards checkers. Really I would only bother putting quotes around URLs and a few other items; things like colors, classes, etc., and especially numerical values don't really need them.

Of course, anyone who puts spaces between an attribute and the value, like around the = sign, must die.

Lummox JR