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

sqm which adds effect to the player when passing by

Diogo souza

New Member
Joined
Dec 11, 2018
Messages
22
Reaction score
1
I need to change this script so that the player gains an effect when stepping on 2 different sqm and when the player dies or disconnects, the effect is removed.

The script to be changed below
|
|
V


effect.lua
Lua:
local effect = 30 -- Effect that will use

local storage = 9994 -- Storage that the player needs to have

local time = 5 -- Time in seconds


function onLogin(cid)

if getPlayerStorageValue(cid, storage) == 1 then

SendEffect(cid )

end

return TRUE

end


function SendEffect(cid)

doSendMagicEffect(getCreaturePosition(cid), effect)

addEvent(SendEffect, time*1000, cid)

return TRUE

end

Now add this to login.lua
Code:
registerCreatureEvent(cid, "Effect")

Now add this code in creaturescripts.xml
Lua:
<event type="login" name="Effect" event="script" value="effect.lua"/>
 
Solution
Lua:
local magicEffect = CONST_ME_POFF
local delay = 5 -- seconds
local actionIds = {45001, 45002} -- set these to whatever you put in movements.xml

local creatures = {}

local function sendEffect(cid, effect, delay)
    if not isCreature(cid) then -- if creature no longer exists, will end the function. (logout, die)
        if creatures[cid] then
            creatures[cid] = nil
        end
        return
    end
    doSendMagicEffect(getCreaturePosition(cid), effect)
    addEvent(sendEffect, delay * 1000, cid, effect, delay) -- infinite loop.
end

function onStepIn(cid, item, position, fromPosition)
    if not creatures[cid] then
        creatures[cid] = 1
        addEvent(sendEffect, 0, cid, magicEffect, delay)
    end
    return true
end
I need to change this script so that the player gains an effect when stepping on 2 different sqm and when the player dies or disconnects, the effect is removed.

The script to be changed below
|
|
V


effect.lua
Lua:
local effect = 30 -- Effect that will use

local storage = 9994 -- Storage that the player needs to have

local time = 5 -- Time in seconds


function onLogin(cid)

if getPlayerStorageValue(cid, storage) == 1 then

SendEffect(cid )

end

return TRUE

end


function SendEffect(cid)

doSendMagicEffect(getCreaturePosition(cid), effect)

addEvent(SendEffect, time*1000, cid)

return TRUE

end

Now add this to login.lua
Code:
registerCreatureEvent(cid, "Effect")

Now add this code in creaturescripts.xml
Lua:
<event type="login" name="Effect" event="script" value="effect.lua"/>
Lua:
local magicEffect = CONST_ME_POFF
local delay = 5 -- seconds
local actionIds = {45001, 45002} -- set these to whatever you put in movements.xml

local creatures = {}

local function sendEffect(cid, effect, delay)
    if not isCreature(cid) then -- if creature no longer exists, will end the function. (logout, die)
        return
    end
    doSendMagicEffect(getCreaturePosition(cid), effect)
    addEvent(sendEffect, delay * 1000, cid, effect, delay) -- infinite loop.
end

function onStepIn(cid, item, position, fromPosition)
    -- if no tile has been stepped on
    if not creatures[cid] then
        if item.aid == actionIds[1] then
            creatures[cid] = 1 -- set to 1 or 2, depending on tile
        else
            creatures[cid] = 2
        end
        return true
    end
    -- if a tile has been stepped on, check which tile was previously stepped on and compare it to the tile currently being stepped on
    if creatures[cid] == 1 and item.aid == actionIds[2] or creatures[cid] == 2 and item.aid == actionIds[1] then
        -- if tile being stepped on is a different tile then stored, set to 3, meaning effect is 'active'
        creatures[cid] = 3
        addEvent(sendEffect, 0, cid, magicEffect, delay)
    end
    -- if it is set to 3, then both checks above will 'fail', and do nothing, since the addEvent is already started.
    return true
end
 
Lua:
local magicEffect = CONST_ME_POFF
local delay = 5 -- seconds
local actionIds = {45001, 45002} -- set these to whatever you put in movements.xml

local creatures = {}

local function sendEffect(cid, effect, delay)
    if not isCreature(cid) then -- if creature no longer exists, will end the function. (logout, die)
        return
    end
    doSendMagicEffect(getCreaturePosition(cid), effect)
    addEvent(sendEffect, delay * 1000, cid, effect, delay) -- infinite loop.
end

function onStepIn(cid, item, position, fromPosition)
    -- if no tile has been stepped on
    if not creatures[cid] then
        if item.aid == actionIds[1] then
            creatures[cid] = 1 -- set to 1 or 2, depending on tile
        else
            creatures[cid] = 2
        end
        return true
    end
    -- if a tile has been stepped on, check which tile was previously stepped on and compare it to the tile currently being stepped on
    if creatures[cid] == 1 and item.aid == actionIds[2] or creatures[cid] == 2 and item.aid == actionIds[1] then
        -- if tile being stepped on is a different tile then stored, set to 3, meaning effect is 'active'
        creatures[cid] = 3
        addEvent(sendEffect, 0, cid, magicEffect, delay)
    end
    -- if it is set to 3, then both checks above will 'fail', and do nothing, since the addEvent is already started.
    return true
end
where do i put the effect?


I want to put what is in the image

|
V

1635126676526.png
 
in movements.xml I define how?

for example: <movevent type = "StepIn" actionid = "4828-4831" event = "script" value = "anticastle.lua" />

How edict?
XML:
<movevent type="StepIn" actionid="45001" event="script" value="script_name.lua"/>
<movevent type="StepIn" actionid="45002" event="script" value="script_name.lua"/>
 
XML:
<movevent type="StepIn" actionid="45001" event="script" value="script_name.lua"/>
<movevent type="StepIn" actionid="45002" event="script" value="script_name.lua"/>
No need to add?

<event type="login" name="Effect" event="script" value="effect.lua"/>
 
Lua:
local magicEffect = CONST_ME_POFF
local delay = 5 -- seconds
local actionIds = {45001, 45002} -- set these to whatever you put in movements.xml

local creatures = {}

local function sendEffect(cid, effect, delay)
    if not isCreature(cid) then -- if creature no longer exists, will end the function. (logout, die)
        if creatures[cid] then
            creatures[cid] = nil
        end
        return
    end
    doSendMagicEffect(getCreaturePosition(cid), effect)
    addEvent(sendEffect, delay * 1000, cid, effect, delay) -- infinite loop.
end

function onStepIn(cid, item, position, fromPosition)
    if not creatures[cid] then
        creatures[cid] = 1
        addEvent(sendEffect, 0, cid, magicEffect, delay)
    end
    return true
end
 
Solution
Lua:
local magicEffect = CONST_ME_POFF
local delay = 5 -- seconds
local actionIds = {45001, 45002} -- set these to whatever you put in movements.xml

local creatures = {}

local function sendEffect(cid, effect, delay)
    if not isCreature(cid) then -- if creature no longer exists, will end the function. (logout, die)
        if creatures[cid] then
            creatures[cid] = nil
        end
        return
    end
    doSendMagicEffect(getCreaturePosition(cid), effect)
    addEvent(sendEffect, delay * 1000, cid, effect, delay) -- infinite loop.
end

function onStepIn(cid, item, position, fromPosition)
    if not creatures[cid] then
        creatures[cid] = 1
        addEvent(sendEffect, 0, cid, magicEffect, delay)
    end
    return true
end
Thank you very much
 
Back
Top