• 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!

Lua Remove condition on deEquip

Crevasse

惡名昭彰
Joined
Jan 13, 2017
Messages
149
Solutions
16
Reaction score
109
Location
Washington, D.C.
Hey guys,

I'm using OTX3, and I am trying to make a helmet that, when worn, increases the players distance fighting by +50%. I did this by creating a movement script and then adding that item to my movements.xml:

XML:
<movevent event="Equip" itemid="2663" slot="head" script="mysticturban.lua" /> <!--msytic turban -->
    <movevent event="DeEquip" itemid="2663" slot="head" script="mysticturban.lua" />

Here is the lua script for mysticturban.lua:

Lua:
local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCEPERCENT, 150)
condition:setParameter(CONDITION_PARAM_TICKS, -1)


function onEquip(cid, item)
    local player = Player(cid)
        player:addCondition(condition)
    return true
end

function onDeEquip(cid, item)
    local player = Player(cid)
    player:removeCondition(condition)
    return true
end


The problem is that it only half works: when I put the helmet on, my distance increases by 50% (e.g. I have 30 distance, put on the helmet, it goes up to 45). However, when I take the helmet off, my distance fighting stays at 45. It does not go back down to 30. I have searched for a while now and I cannot seem to figure out what I am doing wrong. I am not getting any errors in my server console.

Thanks!
 
Solution
Great, remember you don't need any script
you could do like this:
Code:
    <movevent event="Equip" itemid="2663" slot="head" function="onEquipItem"/>
    <movevent event="DeEquip" itemid="2663" slot="head" function="onDeEquipItem"/>

or by vocation
Code:
    <movevent event="Equip" itemid="2663" slot="head" function="onEquipItem">
        <vocation id="1"/>
        <vocation id="5" showInDescription="0"/>
        <vocation id="2"/>
        <vocation id="6" showInDescription="0"/>
    </movevent>
    <movevent event="DeEquip" itemid="2663" slot="head" function="onDeEquipItem"/>
~~~SOLVED~~~

I needed to add a second condition for the DeEquip function:

Lua:
local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCEPERCENT, 150)
condition:setParameter(CONDITION_PARAM_TICKS, -1)

local condition2 = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCEPERCENT, 150)
condition:setParameter(CONDITION_PARAM_TICKS, -1)


function onEquip(cid, item)
    local player = Player(cid)
        player:addCondition(condition)
    return true
end

function onDeEquip(cid, item)
    local player = Player(cid)
    player:addCondition(condition2)
    return true
end

Now works as expected.
 
Great, remember you don't need any script
you could do like this:
Code:
    <movevent event="Equip" itemid="2663" slot="head" function="onEquipItem"/>
    <movevent event="DeEquip" itemid="2663" slot="head" function="onDeEquipItem"/>

or by vocation
Code:
    <movevent event="Equip" itemid="2663" slot="head" function="onEquipItem">
        <vocation id="1"/>
        <vocation id="5" showInDescription="0"/>
        <vocation id="2"/>
        <vocation id="6" showInDescription="0"/>
    </movevent>
    <movevent event="DeEquip" itemid="2663" slot="head" function="onDeEquipItem"/>
 
Solution
I need the script for this part:

Lua:
CONDITION_PARAM_SKILL_DISTANCEPERCENT

In my distribution this cannot be done in XML.

Some distributions you could do:

XML:
<attribute key="skillDistPercent" value="150"/>

But that returns an error in mine.
 
Back
Top