• 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 onStep setGlobalStorageValue

MadMOOK

Hoo
Joined
Apr 20, 2011
Messages
802
Reaction score
44
Is this what I would use to set storage to keep players out of magic teleporter for x amount of time?
If so how would i do that?
 
Code:
if globalexhaustion.check(storage) then
   doTeleportThing(cid, fromPosition)
end

-- to set storage
globalexhaustion.set(storage, time)

globalexhaustion function
Code:
globalexhaustion =
{
   check = function (storage)
     return getGlobalStorageValue(storage) >= os.time(t)
   end,

   get = function (storage)
     local exhaust = getGlobalStorageValue(storage)
     if(exhaust > 0) then
       local left = exhaust - os.time(t)
       if(left >= 0) then
         return left
       end
     end

     return false
   end,

   set = function (storage, time)
     setGlobalStorageValue(storage, os.time(t) + time)
   end,

   make = function (storage, time)
     local exhaust = globalexhaustion.get(storage)
     if(not exhaust) then
       globalexhaustion.set(storage, time)
       return true
     end

     return false
   end
}
 
Code:
local storage = 9853
local time = 10 -- time in seconds

function onStepIn(cid, item, position, fromPosition)
     -- this part will check if the time isn't over yet, then it will teleport/push the player back
     if globalexhaustion.check(storage) then
           return doTeleportThing(cid, fromPosition)
     end

     -- what your script does here
     -- to set storage
     globalexhaustion.set(storage, time)
     return true
end

The function globalexhaustion you have to add to your lib file, 050-function.lua/034-exhaustion.lua in TFS 0.3/0.4 and global.lua in TFS 0.2/1.0.
 
I typed out the function waaay wrong lol.

In movements.xml i had to take citizen.lua out cuz of 1387 itemid.. how do i use tps with same item id?

Also i cannot get it to keep me out of the tp.. i used if(item.actionId == 8765) then globalexhaustion.set
 
Last edited:
Code:
local storage = 9853
local time = 10 -- time in seconds

function onStepIn(cid, item, position, fromPosition)
     if globalexhaustion.check(storage) then
         doTeleportThing(cid, fromPosition)
         doPlayerSendCancel(cid, "You need to wait "..globalexhaustion.get(storage).." seconds before you can enter here again.")
         return true
     end
     doTeleportThing(cid, {x = 95, y = 120, z = 7})
     globalexhaustion.set(storage, time)
     return true
end
Works fine for me, how did you added it in movements.xml and which server do you use?
It doesn't matter if you use uniqueid or actionid, as long as the uniqueid or actionid is not used already. Also make sure the teleport doesn't have a destination.
 
If you want it for all teleports you can also do it like this.
Code:
local storage = 9853
local time = 10 -- time in seconds

function onStepIn(cid, item, position, fromPosition)
     if globalexhaustion.check(storage) then
         addEvent(doTeleportThing, 100, cid, fromPosition)
         doPlayerSendCancel(cid, "You need to wait "..globalexhaustion.get(storage).." seconds before you can enter here again.")
         return true
     end
     globalexhaustion.set(storage, time)
     return true
end
 
I use it for an instance. Id like to useit with differant storages for other instance. Like instance1.lua on this tp, then instance2.lua on another, how do i do that? xD

Like, add differant actionIds and storages in same script via tables?
 
Last edited by a moderator:
You can add actionids to the teleports, then the storage based on actionid. So storage + item.actionid or just item.actionid as storage.
 
You can just add + item.actionid after the storage in the globalexhaustion functions.
Code:
globalexhaustion.check(storage + item.actionid)
globalexhaustion.get(storage + item.actionid)
globalexhaustion.set(storage + item.actionid, time)
Then make an if statement to see if the teleport has an actionid, incase you also have teleports without exhaustion.
Code:
if item.actionid == 0 then
     return true
end
 
Code:
local storage = 9854
local time = 300 --time in seconds


        function onStepIn(cid, item, position, fromPosition)
            if item.actionid == 9853 then
            if globalexhaustion.check(storage + item.actionid) then
                doTeleportThing(cid, fromPosition)
                doPlayerSendCancel(cid, "You need to wait "..globalexhaustion.get(storage + item.actionid).." seconds before entering this instance")
                return true
            end
            end
            doTeleportThing(cid, {x = 2079, y = 1992, x = 11})
            globalexhaustion.set(storage + item.actionid, time)
            return true
            end
Nothing happens here and no errors. I know im not very good at this, so i thankyou for ypur patience
 
If you only want it for 1 actionid, then add it with actionid 9853 in movements.xml.
It's not needed to do this: if item.actionid == 9853 then
This is never needed unless you use different actionids in the same script.

If you add the script with itemid 1387, make sure this isn't used for an other stepin script, like citizen.lua.
With that you can use the script for different actionids, only thing you have to do then is check if the teleport has an actionid, like I showed in the example.
 
Code:
local storage = 9853
local time = 300 -- time in seconds

function onStepIn(cid, item, position, fromPosition)
     if item.actionid == 0 then
         return true
     end

     if globalexhaustion.check(storage + item.actionid) then
         addEvent(doTeleportThing, 100, cid, fromPosition)
         doPlayerSendCancel(cid, "You need to wait "..globalexhaustion.get(storage + item.actionid).." seconds before entering this instance.")
         return true
     end
     globalexhaustion.set(storage + item.actionid, time)
     return true
end

You can add it in movements.xml with the actionids you used or with the itemid.
If you add it with the itemid in movements.xml, make sure it is not used for an other script in movements.xml, like for example citizen.lua.
So if you have this 2x or more, it won't work.
<movevent type="StepIn" itemid="1387" event="script" value="somescript.lua"/>
 
Yes, if you do the teleport back with addEvent, you can add positions in the teleports.
It will show the other side for a short time though, because it will teleport the person back 0.1 second after he got teleported.
If you don't want that, you can also add uniqueids to the teleports, then do the teleport positions based on uniqueid in a table.

@Tufte
It's the exhaustion function in 034-exhaustion.lua from TFS 0.3/0.4, but then with global storage.
I edited it so it works with global storage instead of player storage.
 
Back
Top