ID:165799
 
how do i make an equip verb?, so i can have weapons in my game
obj
Sword
verb
Equip()
suffix = "Equipped"
mob     //Mobile
var //Setting a variable to all mobiles
Equip //Making a variable to objects called "Equip" (Will be used later)
mob/var/obj/Weapon/W //Make a variable to the mob, with a path type of Weapon.
obj/Weapon/verb //Giving a verb to only obj/Weapon types as delcared above
Equip() //Name the verb Equip.
if(usr.W) //If the user's W is not null
usr.W.suffix = "" //The weapon, which would be assigned to the user's W will have no suffix
usr.W = src //Make W equal to the weapon
src.suffix = "Handling" //Add a suffix after the weapon
UnEquip() //Name the verb UnEquip.
if(usr.W) //If the user already has something equipped. This means that Equip doesnt have a null value.
usr.Equip = 0 //Set equip to 0 (also known as "null")
usr.W.suffix = "" //Take away the suffix
usr.W = "" //Reset W to 0 so the user can equip again.
VolksBlade wrote:
how do i make an equip verb?, so i can have weapons in my game

The most important thing for an equipment system is to set it up properly. The mob should have vars telling it which weapons/armor/etc. it has equipped; those vars need to point to the objects themselves, or be null if none is in use. A simple equipment system might be set up like this:

mob
var/obj/item/weapon/weapon
var/obj/item/armor/armor

obj/item/weapon
verb/Equip()
set src in usr
if(!(src in usr)) return // avoid bugs
if(usr.weapon) usr.weapon.Unequip()
usr.weapon = src
usr << "You equip \a [src]."

verb/Unequip()
set src in usr
if(usr.weapon != src)
// it's possible this might have been accidentally called for
// a different item with the same name, so look
if(usr.weapon.name == name) usr.weapon.Unequip()
return
usr.weapon = null
usr << "You unequip [src]."


For armor you'd use the same thing, but for the armor var. A more complex system--but not much more--might assign equipment slots instead.

mob
var/list/equipment

obj/item
var/slot

verb/Equip()
set src in usr
if(!(src in usr)) return // avoid bugs
if(!slot) return
if(!usr.equipment) usr.equipment = new
else if(usr.equipment[slot])
var/obj/item/I = usr.equipment[slot]
if(I==src) return
I.Unequip()
usr.equipment[slot] = src
usr << "You equip \a [src]."

verb/Unequip()
set src in usr
if(!slot) return
if(usr.equipment[slot] != src)
// it's possible this might have been accidentally called for
// a different item with the same name, so look
var/obj/item/I = usr.equipment[slot]
if(I.name == name) I.Unequip()
return
usr.equipment[slot] = null
if(!usr.equipment.len) usr.equipment = null // reclaim the list if not needed
usr << "You unequip [src]."


With this you can give weapon a var of slot="weapon", armor slot="armor", etc. Runt uses this system, with slots for a weapon, armor, shield, helmet, gloves, boots, ring (only one), and amulet.

Lummox JR
In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
obj
Sword
verb
Equip()
suffix = "Equipped"


Incorrect. Any equipment system must always always always give the mob a var telling it which item is in use, not just set a suffix or tell the item itself. The mob must always be able to easily find the item it's using.

Lummox JR
In response to Miran94
This system will basically work because the W var will show if a weapon is in use. The Equip var, however, is useless and should go; W is all you need. Also when unequipping the weapon, W should be set to null, not "", although it will still work the way you did it with minimal potential for problems.

Lummox JR