• 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 1.2 Storage Value to all players from a guild, help plz

origamidoizin

Member
Joined
Jan 2, 2024
Messages
19
Reaction score
6
hi guys i have a code that add storage to players but i have a event in my server everyday and need add and remove storage to more than 50 players every day and its makin me crazy, there is a way that i can add a storage to all guild members? im nub and tried many ways like using war talkaction code, implementing other codes i saw but nothing works, if smn good heart can help? i guess it is easy to do but need some tips to do that, ty anyway




MY CODE:
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    local split = param:split(",")
    if split[2] == nil or split[3] == nil then
        player:sendCancelMessage("Insufficient parameters.")
        return false
    end
    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("Player with name does not exist or is not online.")
        return false
    end
    if split[4] ~= nil then
        player:sendCancelMessage("Too many parameters.")
        return false
    end
    target:setStorageValue(split[2], split[3])
    return false
end
 
hi guys i have a code that add storage to players but i have a event in my server everyday and need add and remove storage to more than 50 players every day and its makin me crazy, there is a way that i can add a storage to all guild members? im nub and tried many ways like using war talkaction code, implementing other codes i saw but nothing works, if smn good heart can help? i guess it is easy to do but need some tips to do that, ty anyway




MY CODE:
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    local split = param:split(",")
    if split[2] == nil or split[3] == nil then
        player:sendCancelMessage("Insufficient parameters.")
        return false
    end
    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("Player with name does not exist or is not online.")
        return false
    end
    if split[4] ~= nil then
        player:sendCancelMessage("Too many parameters.")
        return false
    end
    target:setStorageValue(split[2], split[3])
    return false
end

Lua:
local talkaction = TalkAction("!addguildstorage")
function talkaction.onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    -- Get the key and value of the parameters
    local split = param:split(",")
    local storageKey = tonumber(split[1])
    local storageValue = tonumber(split[2])

    -- Verify that the key and storage value are valid numbers
    if storageKey == nil or storageValue == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Please provide a valid key and storage value.")
        return false
    end

    -- get all players online
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        local guild = player:getGuild() -- get player guild
        if guild then
            -- set player storage
            player:setStorageValue(storageKey, storageValue)
        end
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "The storage value has been added to all online players who are in a guild.")
    return false
end
talkaction:register()
 
Last edited:
Lua:
local talkaction = TalkAction("!addguildstorage")
function talkaction.onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    -- Get the key and value of the parameters
    local split = param:split(",")
    local storageKey = tonumber(split[1])
    local storageValue = tonumber(split[2])

    -- Verify that the key and storage value are valid numbers
    if storageKey == nil or storageValue == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Please provide a valid key and storage value.")
        return false
    end

    -- get all players online
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        local guild = player:getGuild() -- get player guild
        if guild then
            -- set player storage
            player:setStorageValue(storageKey, storageValue)
        end
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "The storage value has been added to all online players who are in a guild.")
    return false
end
talkaction:register()
ty bro but did not work, this gives some errors guess the syntax for tfs 1.2 isnt this but ty anyway

Lua Script Error: [Test Interface]
data/talkactions/scripts/storage.lua
data/talkactions/scripts/storage.lua:34: attempt to index global 'talkaction' (a nil value)
stack traceback:
[C]: in function '__index'
data/talkactions/scripts/storage.lua:34: in main chunk
[C]: in function 'reload'
data/talkactions/scripts/reload.lua:75: in function <data/talkactions/scripts/reload.lua:60>
 
ty bro but did not work, this gives some errors guess the syntax for tfs 1.2 isnt this but ty anyway

Lua Script Error: [Test Interface]
data/talkactions/scripts/storage.lua
data/talkactions/scripts/storage.lua:34: attempt to index global 'talkaction' (a nil value)
stack traceback:
[C]: in function '__index'
data/talkactions/scripts/storage.lua:34: in main chunk
[C]: in function 'reload'
data/talkactions/scripts/reload.lua:75: in function <data/talkactions/scripts/reload.lua:60>
This is a revscript, don't add it in the talkactions folder, just go to data/scripts/talkactions and drop it, no need to register it in the xml file, just drop it in this folder and start the server or use /reload scripts

If your server doesnt have revscript system, use:
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    -- Get the key and value of the parameters
    local split = param:split(",")
    local storageKey = tonumber(split[1])
    local storageValue = tonumber(split[2])

    -- Verify that the key and storage value are valid numbers
    if storageKey == nil or storageValue == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Please provide a valid key and storage value.")
        return false
    end

    -- get all players online
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        local guild = player:getGuild() -- get player guild
        if guild then
            -- set player storage
            player:setStorageValue(storageKey, storageValue)
        end
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "The storage value has been added to all online players who are in a guild.")
    return false
end
 
Last edited:
This is a revscript, don't add it in the talkactions folder, just go to data/scripts/talkactions and drop it, no need to register it in the xml file, just drop it in this folder and start the server or use /reload scripts

If your server doesnt have revscript system, use:
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    -- Get the key and value of the parameters
    local split = param:split(",")
    local storageKey = tonumber(split[1])
    local storageValue = tonumber(split[2])

    -- Verify that the key and storage value are valid numbers
    if storageKey == nil or storageValue == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Please provide a valid key and storage value.")
        return false
    end

    -- get all players online
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        local guild = player:getGuild() -- get player guild
        if guild then
            -- set player storage
            player:setStorageValue(storageKey, storageValue)
        end
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "The storage value has been added to all online players who are in a guild.")
    return false
end
[QUOTE="mano368, post: 2741475, member: 142237"]
This is a revscript, don't add it in the talkactions folder, just go to data/scripts/talkactions and drop it, no need to register it in the xml file, just drop it in this folder and start the server or use /reload scripts

If your server doesnt have revscript system, use:
[Code=lua]
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    -- Get the key and value of the parameters
    local split = param:split(",")
    local storageKey = tonumber(split[1])
    local storageValue = tonumber(split[2])

    -- Verify that the key and storage value are valid numbers
    if storageKey == nil or storageValue == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Please provide a valid key and storage value.")
        return false
    end

    -- get all players online
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        local guild = player:getGuild() -- get player guild
        if guild then
            -- set player storage
            player:setStorageValue(storageKey, storageValue)
        end
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "The storage value has been added to all online players who are in a guild.")
    return false
end
mine dont use revscripts, i tried this second u sent but now it isnt seting the storage to the guild, idk if need a check into db to achieve that, because i used the talkaction trying the name of guild and it didnot work, with the number it set the value but idk why the value is not set to the members lol
[/QUOTE]
 
mine dont use revscripts, i tried this second u sent but now it isnt seting the storage to the guild, idk if need a check into db to achieve that, because i used the talkaction trying the name of guild and it didnot work, with the number it set the value but idk why the value is not set to the members lol
I thought it would be for everyone who had a guild, so you don't use it with a guild name, just !addguildstorage STORAGE, VALUE or whatever name you put there, but you just put storage and then value

And this script is only valid for those who are online at the time you use the command

Then I'll send one the way you want it, with a guild name in charge and to all members
 
I thought it would be for everyone who had a guild, so you don't use it with a guild name, just !addguildstorage STORAGE, VALUE or whatever name you put there, but you just put storage and then value

And this script is only valid for those who are online at the time you use the command

Then I'll send one the way you want it, with a guild name in charge and to all members
No its a daily event like castle 24h, but the winners gain access to another city that the teleport has a storage value, this value is only obtainable by the event, and i have to add manualy the storage to all guild players that win the event(1guild only), like im doin now i have to add storage to players today and tomorrow need to remove the storage and then add again one player by one to the winner guild of next day, so its boring af, i wish something could work, i tried to implement the same code of castle but on this events isnt workin, but on the castle event wornk nornmally, thats crazy lol
 
No its a daily event like castle 24h, but the winners gain access to another city that the teleport has a storage value, this value is only obtainable by the event, and i have to add manualy the storage to all guild players that win the event(1guild only), like im doin now i have to add storage to players today and tomorrow need to remove the storage and then add again one player by one to the winner guild of next day, so its boring af, i wish something could work, i tried to implement the same code of castle but on this events isnt workin, but on the castle event wornk nornmally, thats crazy lol
Can you share the castle system link with us?
 
Can you share the castle system link with us?
Yes

But as i said i dont like this event so im not using it, but i tested and it worked
the problem is that i tried the same syntax on the castle on my event and isnt workin and idk why
 
I created a script less than 10 minutes ago. It's very simple and easy. It works for players whether they are offline or online, granting access to all storages for castle access. This is done through databases. I don't know which database you're using. I recommend checking your database and putting the correct name. Just change the name 'castle' to 'castle_24'. Please check before making any alterations, okay? Also, check if the storage is the same as your castle 24 or if it needs to be modified.



How to use the command? For example, /addstorage guildName,1 to set it for all members of the guild.
Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if not resultId then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local split = param:split(",")
    local guildName = split[1]
    local value = tonumber(split[2])

    if guildName == nil or value == nil or value <= 0 then
        player:sendCancelMessage("Incorrect format. Use: /addstorage guildName,1")
        return false
    end

    local guildId = getGuildId(guildName)

    if not guildId then
        player:sendCancelMessage("Guild not found.")
        return false
    end

    -- Check if the castle already belongs to the guild
    local currentOwner = Game.getStorageValue(696969)
    if currentOwner == guildId then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[Castle 24H] The castle already belongs to the guild.")
        return false
    end

    -- Set the storage value for the guild
    Game.setStorageValue(696969, guildId)

    -- Add a record to the database
    db.query(('INSERT INTO castle (name, guild_id) VALUES ("%s", %d)'):format(guildName, guildId))

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You set Storage Value: " .. value .. " for the guild " .. guildName .. ".")

    return false
end
Post automatically merged:

Ah, I also created a script to remove it for all members.

How to use the command? Simply use /removestorage guildName, -1 to remove all members.

Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if not resultId then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local split = param:split(",")
    local guildName = split[1]
    local value = tonumber(split[2])

    if guildName == nil or value ~= -1 then
        player:sendCancelMessage("Incorrect format. Use: /removestorage guildName,-1")
        return false
    end

    local guildId = getGuildId(guildName)

    if not guildId then
        player:sendCancelMessage("Guild not found.")
        return false
    end

    -- Remove storage for all members of the guild
    db.query("DELETE FROM castle WHERE guild_id = " .. guildId)

    -- Set the storage value for the guild
    Game.setStorageValue(696969, 0)  -- Here, the value is set to 0 to remove the guild

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You removed the Storage for all members of the guild " .. guildName .. ".")

    return false
end
 
Last edited:
I created a script less than 10 minutes ago. It's very simple and easy. It works for players whether they are offline or online, granting access to all storages for castle access. This is done through databases. I don't know which database you're using. I recommend checking your database and putting the correct name. Just change the name 'castle' to 'castle_24'. Please check before making any alterations, okay? Also, check if the storage is the same as your castle 24 or if it needs to be modified.



How to use the command? For example, /addstorage guildName,1 to set it for all members of the guild.
Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if not resultId then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local split = param:split(",")
    local guildName = split[1]
    local value = tonumber(split[2])

    if guildName == nil or value == nil or value <= 0 then
        player:sendCancelMessage("Incorrect format. Use: /addstorage guildName,1")
        return false
    end

    local guildId = getGuildId(guildName)

    if not guildId then
        player:sendCancelMessage("Guild not found.")
        return false
    end

    -- Check if the castle already belongs to the guild
    local currentOwner = Game.getStorageValue(696969)
    if currentOwner == guildId then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[Castle 24H] The castle already belongs to the guild.")
        return false
    end

    -- Set the storage value for the guild
    Game.setStorageValue(696969, guildId)

    -- Add a record to the database
    db.query(('INSERT INTO castle (name, guild_id) VALUES ("%s", %d)'):format(guildName, guildId))

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You set Storage Value: " .. value .. " for the guild " .. guildName .. ".")

    return false
end
Post automatically merged:

Ah, I also created a script to remove it for all members.

How to use the command? Simply use /removestorage guildName, -1 to remove all members.

Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if not resultId then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local split = param:split(",")
    local guildName = split[1]
    local value = tonumber(split[2])

    if guildName == nil or value ~= -1 then
        player:sendCancelMessage("Incorrect format. Use: /removestorage guildName,-1")
        return false
    end

    local guildId = getGuildId(guildName)

    if not guildId then
        player:sendCancelMessage("Guild not found.")
        return false
    end

    -- Remove storage for all members of the guild
    db.query("DELETE FROM castle WHERE guild_id = " .. guildId)

    -- Set the storage value for the guild
    Game.setStorageValue(696969, 0)  -- Here, the value is set to 0 to remove the guild

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You removed the Storage for all members of the guild " .. guildName .. ".")

    return false
end
ty bro ill test it
 
Back
Top