• 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 scripting question

Floris

Member
Joined
Apr 17, 2008
Messages
223
Reaction score
10
Location
Netherlands, The
I was thinking about using all movement scripts in 1 file, assigning them all to the same aid, but I don't know if it's good to do so. Maybe it's looping too much or idk.

Like this:

Will this cause lagg?

Code:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)

if getTopCreature({x = 31607, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 31405, y = 31755, z = 9})

elseif getTopCreature({x = 32237, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 33015, y = 31015, z = 9})

elseif getTopCreature({x = 32347, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 31305, y = 31515, z = 9})

elseif getTopCreature({x = 31237, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 35032, y = 31435, z = 9})

elseif getTopCreature({x = 32237, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 36015, y = 31715, z = 9})

elseif getTopCreature({x = 32337, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 31603, y = 31845, z = 9})

elseif getTopCreature({x = 32437, y = 30753, z = 9}).uid > 0 then
doTeleportThing(cid,{x = 31204, y = 31935, z = 9})
 
Last edited:
Not really. If it was three different scripts with the same actionid it would be slower than just one with all their functions. And you are doing an if - else, so if it's in one case it will not check the others, while if it was different scripts it would.
 
Looks fine to me :p I don't think it'll cause lag.
Code:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if getTopCreature({x = 31607, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 31405, y = 31755, z = 9})
    elseif getTopCreature({x = 32237, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 33015, y = 31015, z = 9})
    elseif getTopCreature({x = 32347, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 31305, y = 31515, z = 9})
    elseif getTopCreature({x = 31237, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 35032, y = 31435, z = 9})
    elseif getTopCreature({x = 32237, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 36015, y = 31715, z = 9})
    elseif getTopCreature({x = 32337, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 31603, y = 31845, z = 9})
    elseif getTopCreature({x = 32437, y = 30753, z = 9}).uid > 0 then
        doTeleportThing(cid,{x = 31204, y = 31935, z = 9})
    end
    return true
end
 
Thanks guys.

Actually I think I came to a conclusion myself.
Correct me if I'm wrong.

If you use 1 actionid on all your movements, then the server has to go through all the ifs to see which one applies to your situation.

But if you use different actionids, the server sees which actionid you use and runs the script attached to it which is a lot faster.
 
Last edited:
Thanks guys.

Actually I think I came to a conclusion myself.
Correct me if I'm wrong.

If you use 1 actionid on all your movements, then the server has to go through all the ifs to see which one applies to your situation.

But if you use different actionids, the server sees which actionid you use and runs the script attached to it which is a lot faster.

You're right.
 
That isen't the best way, ALWAYS if you are doing the exact same thing its better to loop it.
Example:
Code:
function onStepIn(cid, item, position, fromPosition)
    local config = {
        [1] = {{x = 31607, y = 30753, z = 9}, {x = 31405, y = 31755, z = 9}},
        [2] = {{x = 32237, y = 30753, z = 9}, {x = 33015, y = 31015, z = 9}},
        [3] = {{x = 32347, y = 30753, z = 9}, {x = 31305, y = 31515, z = 9}},
        [4] = {{x = 31237, y = 30753, z = 9}, {x = 35032, y = 31435, z = 9}},
        [5] = {{x = 32237, y = 30753, z = 9}, {x = 36015, y = 31715, z = 9}},
        [6] = {{x = 32337, y = 30753, z = 9}, {x = 31603, y = 31845, z = 9}},
        [7] = {{x = 32437, y = 30753, z = 9}, {x = 31204, y = 31935, z = 9}}
    }
   
    for _, positionArray in pairs(config) do
        if(getTopCreature(positionArray[1]).uid > 0) then
            doTeleportThing(cid, positionArray[2])
        end
    end
return true
end
 
Back
Top