• 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 How exactly does movements.xml work?

Drakkhan

Illuria Project Lead
Joined
Oct 3, 2013
Messages
141
Reaction score
22
In my movements.xml I have lines like:

Code:
<movevent event="StepIn" fromid="4620" toid="4625" script="swimming.lua"/>
<movevent event="StepOut" fromid="4620" toid="4625" script="swimming.lua"/>

and lines like:

Code:
<movevent event="Equip" itemid="2195" slot="feet" function="onEquipItem"/>
<movevent event="DeEquip" itemid="2195" slot="feet" function="onDeEquipItem"/>

So I understand that these lines activate when certain events occur (i.e. event="StepIn" triggers script "swimming.lua' when someone steps on item "4620").. but:

What is the difference between script and function?

Can one of these lines have both a script and a function?

How do the events pass information to the corresponding .lua script (how does swimming.lua know to use function OnStepIn() instead of function OnStepOut())?

What kind of lua functions are there to react to these events in the called scripts?

If I want to add a script that triggers when a person equips an item AND when they de-equip an item, how do I change my movements.xml and what functions must I include in the .lua script to catch the events?


I know it's a lot of questions, but if they could be answered, then I don't have to beg for scripts :p .

Regards,

Drakkhan
 
Code:
<movevent event="StepIn" fromid="4620" toid="4625" script="swimming.lua"/>
<movevent event="StepOut" fromid="4620" toid="4625" script="swimming.lua"/>

As you can see in this part you have the ids from 4620 to 4625 that means the items 4620,4621,4622,4623,4624,4625 got the effect which is in data/movements/scripts/swimming.lua

if you open the swimming lua you can see what it does

example

if you step on any of 4620-4625 ID you get looktype 267 and all other effects in the script mentioned
PHP:
local outfit = {lookType = 267, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 0}

local BORDERS = {
    [7943] = {x = 0, y = -2, back = SOUTH},
    [7944] = {x = -2, y = 0, back = EAST},
    [7945] = {x = 0, y = 2, back = NORTH},
    [7946] = {x = 2, y = 0, back = WEST},
    [7947] = {x = 2, y = 1, back = WEST},
    [7948] = {x = -2, y = 1, back = NORTH},
    [7949] = {x = 2, y = -1, back = WEST},
    [7950] = {x = -2, y = -1, back = EAST},
    [7951] = {x = 2, y = 2, back = WEST},
    [7952] = {x = -2, y = 2, back = NORTH},
    [7953] = {x = 2, y = -2, back = WEST},
    [7954] = {x = -2, y = -2, back = SOUTH}
}

BORDERS[4828] = BORDERS[7943]
BORDERS[4829] = BORDERS[7946]
BORDERS[4830] = BORDERS[7945]
BORDERS[4831] = BORDERS[7944]

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if(not isPlayer(cid)) then
        return true
    end

    local border = BORDERS[item.itemid]
    if(not border) then
        return false
    end

    local pos, newPos = getCreaturePosition(cid), {}
    newPos = pos
    newPos.x = pos.x + border.x
    newPos.y = pos.y + border.y

    if(hasCondition(cid, CONDITION_OUTFIT) and getCreatureOutfit(cid).lookType == outfit.lookType) then
        doMoveCreature(cid, border.back)
        doRemoveCondition(cid, CONDITION_OUTFIT)
    else
        if(doTileQueryAdd(cid, pos, 4) ~= RETURNVALUE_NOERROR) then
            return false
        end

        local tmp = getCreaturePosition(cid)
        doTeleportThing(cid, newPos)

        if(not isPlayerGhost(cid)) then
            doSendMagicEffect(tmp, CONST_ME_POFF)
            doSendMagicEffect(newPos, CONST_ME_WATERSPLASH)
        end

        doRemoveConditions(cid, true)
        doSetCreatureOutfit(cid, outfit, -1)
    end

    return true
end

about the equip and deequip if you want to add an own item like donate things you have to put this inside the movements.xml and edit the specify item in the items.xml

Donate Helmet for Paladin Example
PHP:
    <movevent type="Equip" itemid="12645" slot="head" event="function" value="onEquipItem">
        <vocation id="3"/>
        <vocation id="3" showInDescription="0"/>
    </movevent>
    <movevent type="DeEquip" itemid="12645" slot="head" event="function" value="onDeEquipItem"/>
 
@DaPlaya: Thank you, I'm not sure what you were trying to say at the end there with donate helmet, but I get that the item ID's correspond to the script.. I guess I'm just asking what kind of power I have here. What functions are available to .lua scripts called by movements.xml? What things in items.xml are activated by events in movements.xml? etc..

@Maladnay: Thank you for answering a specific question I asked! Do you know if "onEquipItem" in movements.xml calls a similar onEquip() function in .lua script? I guess I just want to be able to write a script that runs when a character equips an item. I asked all the other questions just to broaden the discussion.

@Everyone, List of remaining questions:

What is the difference between script and function?

Can one of these lines have both a script and a function?

What kind of lua functions are there to react to these events in the called scripts?

If I want to add a script that triggers when a person equips an item AND when they de-equip an item, how do I change my movements.xml and what functions must I include in the .lua script to catch the events?

Regards,

Drakkhan
 
@Drakkhan

The movements.xml is working for the "on wearing function" if an item grants you 500 Health points in items.xml and you wear it on and off it always change your total amount of hitpoints that means movements is used for turn on/off the special abitilies of an item while wearing it on and wearing it off

Difference between Script and Function!


a Script take place when you do something which is named for the script for example the ID 1234 which is the ActionID of a lever. The script only happens when someone pull the lever.

a function always have an input and output parameter


The biggest difference between scripts and functions is that functions have input and output parameters. As you can see, functions much more flexible. They are therefore more suitable for general purpose tasks that will be applied to different data.
 
@DaPlaya Thanks for all your help! :) So if I wanted to write a script that activates when a player equips an item... would I replace the line that has "function="onEquipItem""? or would I add another line so the item has that function line and a script line? or is it not possible?


@Everyone, list of remaining questions:

Can one of these lines have both a script and a function?

What kind of lua functions are there to react to these events in the called scripts?

If I want to add a script that triggers when a person equips an item AND when they de-equip an item, how do I change my movements.xml and what functions must I include in the .lua script to catch the events?
 
@Drakkhan Sure you can script a lot this way (ex. ring that change ur outfitt)

<movevent event="Equip" itemid="00000" slot="ring" function="onEquipItem" script="magic_ring.lua" />
<movevent event="DeEquip" itemid="00000" slot="ring" function="onDeEquipItem" script="magic_ring.lua" />


In your .lua script some simple schema:
Code:
local value1 = 1111 -- if u want to get or set something, do it here
local value2 = 2222

function onEquip(cid, item, slot)
--- your code ---
return true
end

function onDeEquip(cid, item, slot)
--- your code ---
return true
end
 
@Maladnay Excellent! This is the core of what I wanted to know.

I just acquired my source code, so I'll be able to answer any further technical questions I have.
 
Back
Top