• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua any loop for this?, ARE These Line harmful?

5lave Ots

Active Member
Joined
Oct 2, 2017
Messages
247
Solutions
1
Reaction score
40
Location
Ankrahmun
hey guys im using this code on tfs 0.4 for tibia 8.6
it should send some magic effects and I need to make these lines into a loop to save memory if possible
its working on login script so im asking if this codes are ok to use or they can harm the server? (I go three more similar to this in ot)


Code:
local pos =  getCreaturePosition(cid)
local effectPositions = {
{x = pos.x-3, y = pos.y-5, z = pos.z},
{x = pos.x-3, y = pos.y-5, z = pos.z},
{x = pos.x-3, y = pos.y-5, z = pos.z},
{x = pos.x-3, y = pos.y-5, z = pos.z},
{x = pos.x+3, y = pos.y-5, z = pos.z},
{x = pos.x+3, y = pos.y-5, z = pos.z},
{x = pos.x+3, y = pos.y-5, z = pos.z},
{x = pos.x+3, y = pos.y-4, z = pos.z},
{x = pos.x+3, y = pos.y-3, z = pos.z},
{x = pos.x+3, y = pos.y-1, z = pos.z},
{x = pos.x+3, y = pos.y, z = pos.z},
{x = pos.x+3, y = pos.y+1, z = pos.z},
{x = pos.x+3, y = pos.y+3, z = pos.z},
{x = pos.x+3, y = pos.y+4, z = pos.z},
{x = pos.x+3, y = pos.y+5, z = pos.z},
{x = pos.x+3, y = pos.y+5, z = pos.z},
{x = pos.x+3, y = pos.y+5, z = pos.z},
{x = pos.x, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+3, z = pos.z},
{x = pos.x-3, y = pos.y+1, z = pos.z},
{x = pos.x-5, y = pos.y, z = pos.z},
{x = pos.x-5, y = pos.y-1, z = pos.z},
{x = pos.x-5, y = pos.y-3, z = pos.z},
{x = pos.x-5, y = pos.y-4, z = pos.z}
}

for _, ePos in ipairs(effectPositions) do
doSendDistanceShoot(ePos, pos, 30)
end
 
I see several rows with identical positions. Should this loop be delayed? Or is every effect suppose to trigger at the same time? In which case there is no need to have duplicate positions.
 
they should all trigged at same time, its working fine with me but I need to save lines and asking about possibility of crash or something?
/i newbie :D
i think there is for x = start x to end x(1,5)
for y = start y to end (1,5) is that posiible?
 
What you have should be fine but as Znote said, there are some duplicates that don't really seem to serve a purpose.
Also another way it could be done is setting the positions outside of the function as offsets and then apply them as you need them. Not having to build the table every time the script is ran should be considerably faster, though the value of this really depends on how often it is being used.

Here would be an example:
LUA:
local effectPositions = {
    {x = -3, y = -5},
    {x = 3, y = -5},
    -- ect...
}

function someFunction(cid)
    local pos = getCreaturePosition(cid)
    for _, ePos in ipairs(effectPositions) do
        doSendDistanceShoot({x = pos.x + ePos.x, y = pos.y + ePos.y, x = pos.z}, pos, 30)
    end
end
 
I see several rows with identical positions. Should this loop be delayed? Or is every effect suppose to trigger at the same time? In which case there is no need to have duplicate positions.

I had modify it now and need to set a function on lib 50 to send effects in this area can you help me with that?
these are the positions
Code:
local effectPositions = {
{x = pos.x, y = pos.y-5, z = pos.z},
{x = pos.x+1, y = pos.y-5, z = pos.z},
{x = pos.x+2, y = pos.y-5, z = pos.z},
{x = pos.x+3, y = pos.y-5, z = pos.z},
{x = pos.x+4, y = pos.y-5, z = pos.z},
{x = pos.x+5, y = pos.y-5, z = pos.z},
{x = pos.x+5, y = pos.y-4, z = pos.z},
{x = pos.x+5, y = pos.y-3, z = pos.z},
{x = pos.x+5, y = pos.y-2, z = pos.z},
{x = pos.x+5, y = pos.y-1, z = pos.z},
{x = pos.x+5, y = pos.y, z = pos.z},
{x = pos.x+5, y = pos.y+1, z = pos.z},
{x = pos.x+5, y = pos.y+2, z = pos.z},
{x = pos.x+5, y = pos.y+3, z = pos.z},
{x = pos.x+5, y = pos.y+4, z = pos.z},
{x = pos.x+5, y = pos.y+5, z = pos.z},
{x = pos.x+4, y = pos.y+5, z = pos.z},
{x = pos.x+3, y = pos.y+5, z = pos.z},
{x = pos.x+2, y = pos.y+5, z = pos.z},
{x = pos.x+1, y = pos.y+5, z = pos.z},
{x = pos.x, y = pos.y+5, z = pos.z},
{x = pos.x-1, y = pos.y+5, z = pos.z},
{x = pos.x-2, y = pos.y+5, z = pos.z},
{x = pos.x-3, y = pos.y+5, z = pos.z},
{x = pos.x-4, y = pos.y+5, z = pos.z},
{x = pos.x-5, y = pos.y+5, z = pos.z},
{x = pos.x-5, y = pos.y+4, z = pos.z},
{x = pos.x-5, y = pos.y+3, z = pos.z},
{x = pos.x-5, y = pos.y+2, z = pos.z},
{x = pos.x-5, y = pos.y+1, z = pos.z},
{x = pos.x-5, y = pos.y, z = pos.z},
{x = pos.x-5, y = pos.y-1, z = pos.z},
{x = pos.x-5, y = pos.y-2, z = pos.z},
{x = pos.x-5, y = pos.y-3, z = pos.z},
{x = pos.x-5, y = pos.y-4, z = pos.z},
{x = pos.x-5, y = pos.y-5, z = pos.z},
{x = pos.x-4, y = pos.y-5, z = pos.z},
{x = pos.x-3, y = pos.y-5, z = pos.z},
{x = pos.x-2, y = pos.y-5, z = pos.z},
{x = pos.x-1, y = pos.y-5, z = pos.z},

this is the function

Code:
for _, ePos in ipairs(effectPositions) do
doSendDistanceShoot(ePos, pos, 30)
doSendDistanceShoot(pos,ePos, 37)
end

just need to make a loops, so these all lines modified into 2 loops and ill insert a function in lib
 
i got this loop in talkactions
Code:
function SendMyEffect(cid,eff1,eff2)
local position =  getCreaturePosition(cid)
 for i = 1, 30 do
  doSendDistanceShoot(position, {x = position.x + math.random(-7, 7), y = position.y + math.random(-5, 5), z = position.z}, eff1)
  doSendDistanceShoot({x = position.x + math.random(-7, 7), y = position.y + math.random(-5, 5), z = position.z},position, eff2)
 end
end
this function is ok?
 
it works oki but i need to set it to set effects from a square 5x5 of players,
any idea?
as it should send effect from and to ( the 5 sqm square around the player)
 
Last edited:
Back
Top