• 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 Script that has effect while player isn't moving.

Drakkhan

Illuria Project Lead
Joined
Oct 3, 2013
Messages
141
Reaction score
22
I'm wondering if there is a way to loop a script so that it repeats every 1 second unless the player moves or changes the direction they're facing. Any ideas how this could be done?


Regards,

Drakkhan
 
Code:
function sendMessage()
    if(not isPlayer(cid)) then
    return true
    end
    if(isPlayer(cid)) then
        doSendMagicEffect(getPlayerPosition(cid), 5)
    end
return true 
end

To "load" the function
Code:
addEvent(sendMessage, 1000)

Add that into your script and it should loop the function.
WibbenZ
 
Just to cap this thread off, here's my solution to this:

Code:
function whatever(cid)
    local playerPos = getCreaturePosition(cid)
    local playerDir = getPlayerLookDir(cid)

    --STORAGE_GEN is 99990010, a storage index number for this scripts generation of storage values.
    ----the next script will use STORAGE_GEN2 99990020 etc..
    storageIDX = STORAGE_GEN + 1
    storageIDY = STORAGE_GEN + 2
    storageIDZ = STORAGE_GEN + 3
    storageIDDir = STORAGE_GEN + 4

    setPlayerStorageValue(cid, storageIDX, playerPos.x)
    setPlayerStorageValue(cid, storageIDY, playerPos.y)
    setPlayerStorageValue(cid, storageIDZ, playerPos.z)
    setPlayerStorageValue(cid, storageIDDir, playerDir)

    addEvent(repeater, 500, cid)
end

repeater(cid)
    local playerPos = getCreaturePosition(cid)
    local playerDir = getPlayerLookDir(cid)

    storageIDX = STORAGE_GEN + 1
    storageIDY = STORAGE_GEN + 2
    storageIDZ = STORAGE_GEN + 3
    storageIDDir = STORAGE_GEN + 4

    oldX = getPlayerStorageValue(cid, storageIDX)
    oldY = getPlayerStorageValue(cid, storageIDY)
    oldZ = getPlayerStorageValue(cid, storageIDZ)
    oldDir = getPlayerStorageValue(cid, storageIDDir)

    newX = playerPos.x
    newY = playerPos.y
    newZ = playerPos.z
    newDir = playerDir

    if((newX == oldX) and (newY == oldY) and (newZ == oldZ) and (newDir == oldDir)) then
        --insert any code that should be repeated here
        addEvent(repeater, 1500, cid)
    else
        --code before repeat stops goes here
        return true
    end
end
 
Last edited:

Similar threads

Replies
3
Views
449
Back
Top