• 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 tfs 0.4 (lua) check if a storage id exist on anyplayer

dunnish

New Member
Joined
Jun 18, 2009
Messages
268
Solutions
1
Reaction score
2
Hello!

how do i check if storage id exist on anyplayer

if we say like this.

if first player say !join then its will create a event.
but if player2 sayts !join then player2 will join the existing event.
 
Solution
Quick example
Lua:
if getGlobalStorageValue(45001) <= 0 then
    -- starting event
    setGlobalStorageValue(45001, 1)
elseif getGlobalStorageValue(45001) == 1 then
    -- joining existing event
end
setPlayerStorageValue(cid, 45001, 1) -- note that global and player storages are separate, so they can share the same key and not interfere with each other.
Combination of globalstorage for the event, and playerstorage to confirm they are in the event.
Lua:
getPlayerStorageValue(uid, key)
doPlayerSetStorageValue(uid, key, newValue)
setPlayerStorageValue(uid, key, newValue) -- //compats version

getGlobalStorageValue(valueid)
setGlobalStorageValue(key, newValue)
 
Combination of globalstorage for the event, and playerstorage to confirm they are in the event.
Lua:
getPlayerStorageValue(uid, key)
doPlayerSetStorageValue(uid, key, newValue)
setPlayerStorageValue(uid, key, newValue) -- //compats version

getGlobalStorageValue(valueid)
setGlobalStorageValue(key, newValue)
this one works buts only for 1 player not for the server.
do you know why?
Lua:
if getPlayerStorageValue(cid,jailedstoragevalue_time) <= 0 then

and this one dossnt work at all
Lua:
if getPlayerStorageValue(uid, jailedstoragevalue_time) <= 0 then
 
Quick example
Lua:
if getGlobalStorageValue(45001) <= 0 then
    -- starting event
    setGlobalStorageValue(45001, 1)
elseif getGlobalStorageValue(45001) == 1 then
    -- joining existing event
end
setPlayerStorageValue(cid, 45001, 1) -- note that global and player storages are separate, so they can share the same key and not interfere with each other.
 
Solution
Just use the example that Xikini gave :D
BUUT, I have a tip: you can use modulus operator to limit the amount of players in the same room.
Yea yea modulus operator, but don't be scared it's quite simple (I'll do it in pseudocode so please don't paste it into your script):

Code:
--this code should be placed where you handle the player join

maxPlayersInOneEvent = 10

amountOfPlayers = 0
globalStorage = 45001
setGlobalStorageValue(globalStorage, amountOfOtherPlayers)

if((getGlobalStorage(globalStorage)+ 1) % maxPlayersInOneEvent ~= 0) then
setGlobalStorageValue(globalStorage, amountOfPlayers)
amountOfPlayers = amountOfPlayers + 1
end
With the ideia of the code above (obvsly it's a sample and I haven't tested it) you can limit the quantity of players joining the same globalEvent.
With almost no change you can also make a new globalEvent when it reaches the max players amount and create dynamically rooms by-player-demand.
 
Back
Top