ID:149470
 
I get a runtime error every time i try to equip a weapon. This is the runtime error:

runtime error: Cannot create objects of type
/obj/weapon.
proc name: use (/mob/verb/use)
usr: Me (/mob/pc)
src: Me (/mob/pc)
call stack:
Me (/mob/pc): use(Dagger (/obj/weapon/Dagger))

This is the code I have for equipping it:

mob/verb/use(obj/O as obj in usr)
if(istype(O,/obj/weapon))
usr.right_hand=new O
del(O)

Is there a problem with telling it to create a new O? Any help is appreciated.
Loduwijk wrote:
I get a runtime error every time i try to equip a weapon. This is the runtime error:

runtime error: Cannot create objects of type
/obj/weapon.
proc name: use (/mob/verb/use)
usr: Me (/mob/pc)
src: Me (/mob/pc)
call stack:
Me (/mob/pc): use(Dagger (/obj/weapon/Dagger))

This is the code I have for equipping it:

mob/verb/use(obj/O as obj in usr)
if(istype(O,/obj/weapon))
usr.right_hand=new O
del(O)

Is there a problem with telling it to create a new O? Any help is appreciated.

New needs a type passed to it, not an instance of the type. But the question is really, why are you creating a new weapon? Don't you already have one in the inventory? Why not just point to the one you already have:

mob/verb/use(obj/O as obj in usr)
if(istype(O,/obj/weapon))
usr.right_hand=O
In response to Skysaw
I tried that, but the weapon also stays in the contents, so it is two places at once. When it is equipped I do not want it in usr.contents anymore.
Instead of new O, you want new O.t ype. That should fix things up.
In response to Loduwijk
Loduwijk wrote:
I tried that, but the weapon also stays in the contents, so it is two places at once. When it is equipped I do not want it in usr.contents anymore.

Well it's still part of your inventory, right? It all depends on how you're displaying things. Why not just add in this:

O.suffix = "equipped"

That way you can see it in your inventory, but you know it's equipped. Otherwise people may wonder why items seem to disappear when they equip them.

If you really want to take it out of inventory, it would make more sense to Move() the gun, instead of creating a new one, and deleting the old one. Otherwise, if you change a variable in the gun, (such as number of bullets in chamber) the new gun won't pick it up.
In response to Skysaw
I did try to Move() it, but it wouldnt show in the statpanel. The reason I wanted it like this just has to do with the way I have the game set up. Thank you for the helpful info though. It is much appreciated.
In response to Lord of Water
Thanks.
In response to Loduwijk
If you really don't want it to show up in usr.contents, I'm guessing you have a statpanel set up like this:
statpanel("Inventory",contents)

You could show contents minus right_hand, like this:
statpanel("Inventory",contents - right_hand)
In response to WizDragon
That is a good idea, and when I read it at first I thought maybe I could do that, but that not work with things that I am going to put in later. I can't just make it invisible, I have to actually remove it. You would understand if you knew what I am going to do with it.

I allready have it set up though, LoW's replie works with what I need. Thank you all for helping though.