ID:139260
 
Code:
mob/var
equip=0
obj/var
inbag=0
weapon
sword
icon = 'weapons.dmi'
icon_state="sword"
verb
Get()
set src in oview(0)
set category=null
usr.contents+=new/obj/weapon/sword
src.inbag=1
del(src)
Click()
if(inbag==1)
if(usr.equip==0)
usr<<"You Equip The weapon"
usr.equip=1
else
usr<<"You are already weilding this weapon!"
else
return


Problem description:
I can pick up the sword but cant equip it.
Sorry im kinda new so excuse me if I get this wrong but I think your "Equip=0" var is not indented under the var code.


// Like this
mob/var
equip=0

// Not like this
mob/var
equip=0


Feel free to correct me if im wrong.
In response to Saladon
Sorry those two top vars are there so your can see I did indeed create the vars and its not a problem with that. I think the problem is it's deleting the item that that you pick up so the inbag still = 0 even after picking it up but I dont know how to change it.
In response to Animekid09
Oh I see your problem now. take the del(src) out completely. It is already moved into your bag. the del(src) is just removing it from your bag after you pick it up
In response to Saladon
but...
[code]usr.contents+=new/obj/weapon/sword[/code]
puts an entire new item in my bag so if I dont del(src) then the item would remain on the map.
In response to Animekid09
Ok i see. I think you should rather use the Move() proc.
sword.Move(usr) // will put the sword into usr.contents
// No need to use del() proc


Or to make the over all get() verb more flexible, put it as an obj verb. For example
obj/verb/Get() // Verb will work with any obj
set src in oview(1)
src.loc = usr


Thats how I did it.
In response to Saladon
Why would you delete the item after picking it up?
In response to Shaoni
because he didnt hange the loc of the obj. he is creating a new obj inside his "bag" and then the one thats on the ground, needed to be deleted. Thats why I suggested moving the location of it into the bag. less stress
In response to Saladon
Thanks salason for the help. I currently got it right heres the code I ended up with
    weapon
icon='weapons.dmi'
sword
name="Starter Sword"
icon_state="sword"
unmovable=0
Click()
if(src.inbag==1)
if(src.equip==0)
if(usr.equipmh==0)
usr<<"You equip \icon[src] [src]"
usr.equipmh=1
src.equip=1
src.suffix="Equip"
else
usr<<"You already have a different weapon equip in that hand"
else
usr<<"You un-equip \icon[src] [src]"
src.equip=0
usr.equipmh=0
src.suffix=""
else
if(src in oview(2))
usr<<"You picked up a \icon[src] [src]"
src.inbag=1
src.Move(usr)
In response to Animekid09
You could lose the unnecessary "inbag" variable and instead use:

if(src in usr.contents)
Yep, that's definitely not right. You should not be using the equip and inbag vars like this. The mob alone should keep track of whether the weapon is equipped and if so which one. Right now you're using two vars to track this, one of which belongs to the obj which shouldn't be responsible for tracking any of this, and one of which belongs to the mob but doesn't tell you anything about which weapon is in use.

mob/var/obj/item/weapon/weapon  // weapon equipped

obj/item/weapon
verb/Equip()
set src un usr
if(usr.weapon == src) return
if(usr.weapon) usr.weapon.Unequip()
usr.weapon = src
usr << "You equip [src]."
verb/Unequip()
set src in usr
if(usr.weapon != src) return
usr.weapon = null
usr << "You stop using [src]."
Click()
if(src in usr)
if(usr.weapon == src) Unequip()
else Equip()


That's all you need. I put this under /obj/item because then you only have to define Get() and Drop() once, for the /obj/item type.

Lummox JR
In response to Lummox JR
obj/weapon
verb/Equip()
set hidden=1
set src in usr
if(usr.weapon == src) return
if(usr.weapon) usr.weapon.Unequip()
usr.weapon = src
usr << "You equip [src]."
verb/Unequip()
set hidden=1
set src in usr
if(usr.weapon != src) return
usr.weapon = null
usr << "You stop using [src]."
Click()
if(src in usr)
if(usr.weapon == src) Unequip()
else Equip()


Thats what I edited it to but I cant seem to get the click() proc to work.