ID:1539369
 
Code:
Pistol
icon = 'Pistol.dmi'
verb
Pick_Up()
set src in oview(1)
world << "You found a Pistol!"
src.Move (usr)

Load_Ammo()
set src in usr
if(usr.contents = /obj/Ammo)
world << "You have loaded the gun!"
del src


IT'S NOT WORKING! Please help me! Please!:

There are multiple items I would conciser wrong in this case with the load ammo.

1. comparisons are ==, not =
2. You need to find an object of a type, to do so - you should use the istype() procedure.
3.You need to check each value in the list, not just the list itself.

To fix these, take a look at the sample I provided below.

Pistol
verb
Load_Ammo()
set src in usr
for(var/obj/Ammo/a in usr.contents) //cycle through the contents
if(istype(a)) //if the obj in contents is the type /obj/Ammo, lets reload
del a //delete the ammo
world << "You have reloaded the gun!" //tell the user
. = 1 //return a 1
break //break (or return)
if(!.)//if it wasn't found
world << "There is no ammo in your inventory!"
Thanks man, not working at mo, but will update if I figure out what I did wrong XD No, it didn't work... any suggestions?
It's working now, thanks!
In response to Pirion
You should use locate() instead of a for() loop.
In response to Kaiochao
Kaiochao wrote:
You should use locate() instead of a for() loop.

Ikr. That wasn't the only redundant thing in there, though.

Pistol
verb
Load_Ammo()
set src in usr
var/obj/Ammo/a = locate() in usr
if(a)
del a //delete the ammo
world << "You have reloaded the gun!" //tell the user
else
world << "There is no ammo in your inventory!"
ok thanks guys. So what is the (a)? in the code.
In response to Flying1ace
This syntax:
var [type] [id] = locate() in [object or list]

It finds an object in [object or list] of the type [type] (or a sub-type) and stores it in the variable [id].

If it doesn't find an object, then the variable contains null.

e.g.
mob
Login()
new /obj/sword (src)
new /obj/shield (src)
new /obj/health_potion (src)

verb/check_sword()
// look for an object
// with the type /obj/sword
// in src
// and call it 'my_sword'
var/obj/sword/my_sword = locate() in src

// if my_sword was found (is not null)
if(my_sword)
src << "My sword does [my_sword.damage] damage!"

else
src << "I don't have a sword!"


obj
sword
var damage = 123
// ...

shield
// ...

health_potion
// ...
Cool, I got some cool code going on ;) You reload the gun, the ammo and pistol is del. a obj, Loaded Pistol, is added to invent, when you shoot zombie it dels your loaded pistol and gives you your normal pistol back. COOL!
No need to delete the pistol, just add an ammo_count variable to it, and use that to determine if it can be fired or not