ID:161168
 
Im trying to make a weapon that you can pick up and equip and fire by pressing "Tab" or "5" can u help me i started it and u can pick it up.

obj
Staff
name = "Staff Weapon"
icon_state = "Staff"
desc = "A Jaffa's Weapon"
DblClick()
if(src.loc==usr)
src.loc=locate(usr.x,usr.y-1,usr.z)
else
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
verb
Equip()
if(src.loc==usr)
if(usr.equip==1)
usr.equip = 0
usr<<"You unequip yourself with a [src]"
if(usr.equip==0)
usr.equip = 1
usr<<"You equip yourself with a [src]"
set src in oview(1)

First, settings should be done at the beginning of the proc.

Second, that would work in a verb only.
if(!(src in oview(1))) return


Instead of directly setting loc, you may want to use the Move proc or a combination of the two (kaioken's SetLoc proc), though it should still work.

The equip var shouldn't be a number. You should derive all items (stuff that can be picked up and equipped) from something like /obj/item. The variable should then be /mob/var/obj/item/equip.

obj/item
staff
verb
Equip()
if(src in usr)
if(usr.equip)
usr.equip = null
usr<<"You unequip yourself with \a [src]"
//Here you may want to put the staff on the ground.
else
usr.equip = src
usr<<"You equip yourself with a [src]"
In response to Nickr5
Note that default movement restrictions such as density only apply when moving into turfs; so picking up items with Move() should be perfectly fine. Given the item is probably nondense, you would also likely prefer using Move() for dropping it as well. This allows you to make use of the Enter() and Exit() procs if you wish.

Also,
Nickr5 wrote:
if(src in usr)

Well, here, as you know, you can use an src setting, which looks cleaner. It is actually a good idea to additionally leave this check in place, though.
In response to Kaioken
Hmm i dont get nearly anything u guys are saying i have the DblClick for picking and droping items and also i have a equip and unequip verb i just need u guys to show me how to make the gun shoot by pressing 5 or Tab. and also how to make a projectile fire when u press 5 or tab.

Also why do ppl say dont use usr wth's that about?
In response to Chrislee123
To make something "Fire" when pressing 5 or tab, you set the macros according to those keys. Macros are set in .dms script files or .dmf interface files. You need to make your own verb to fire it and set the macro to call that verb when pressed.

As for the actual shooting projectile, create a projectile object and make it move the direction you shoot, and check with Bump() to delete or damage things.
In response to Kaiochao
Oh i get it thats so simple they made it really compliicated but thanks kaiochao