• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Help with OnEquip Function!

Ragna Story

New Member
Joined
Nov 27, 2014
Messages
17
Reaction score
1
Hey, I'm trying to make some new scripts, but I'm stucked in this part. I don't know how I use the OnEquip function...
Like I'm trying to make itens that have extra functions when you equip them, but i don't know how to start this.
If you could recomend me some tutorials, and even some scripts that use this function (I like to learn dismembering some scripts to understand).


Thanks!
 
I'm going to guess your server version since you forgot to post it. If you use TFS 1.0+ it will be a bit different but still will work similar.

Example of changing outfit on eq, added some comments for info.
Code:
local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SUBID, 8)
addOutfitCondition(condition, {lookType = 274, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 0})

function onEquip(cid, item, slot)
     if getPlayerSlotItem(cid, slot).itemid == item.itemid then -- this prevents that the script executes the functions more than once, so you won't get more than 1 textmessage
         doAddCondition(cid, condition)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You changed into a squirrel!")
     end
     return true  -- return true is needed else you can't equip the item
end

function onDeEquip(cid, item, slot) -- this happens when you unequip the item, so it should undo what the onEquip function does
     doRemoveCondition(cid, CONDITION_OUTFIT, 8)
     return true
end

In movements.xml add them with script instead of function.
Code:
<movevent type="Equip" itemid="2504" slot="legs" event="script" value="equip.lua"/>
<movevent type="DeEquip" itemid="2504" slot="legs" event="script" value="equip.lua"/>
 
I'm going to guess your server version since you forgot to post it. If you use TFS 1.0+ it will be a bit different but still will work similar.

Example of changing outfit on eq, added some comments for info.
Code:
local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SUBID, 8)
addOutfitCondition(condition, {lookType = 274, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 0})

function onEquip(cid, item, slot)
     if getPlayerSlotItem(cid, slot).itemid == item.itemid then -- this prevents that the script executes the functions more than once, so you won't get more than 1 textmessage
         doAddCondition(cid, condition)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You changed into a squirrel!")
     end
     return true  -- return true is needed else you can't equip the item
end

function onDeEquip(cid, item, slot) -- this happens when you unequip the item, so it should undo what the onEquip function does
     doRemoveCondition(cid, CONDITION_OUTFIT, 8)
     return true
end

In movements.xml add them with script instead of function.
Code:
<movevent type="Equip" itemid="2504" slot="legs" event="script" value="equip.lua"/>
<movevent type="DeEquip" itemid="2504" slot="legs" event="script" value="equip.lua"/>
I've never thought of dwarves and squirrels in the same sentence before.
But then again, dwarves do like to hide their treasures as well.
:p
 
Back
Top