• 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 script "onSay"/talkaction - TFS 1.2

dropz

Member
Joined
May 4, 2022
Messages
46
Reaction score
24
hello!

how can i deal with this script to it get just the initial parameter of the local config that i declared in the begin of script?

what im trying is use just a one script that grabs the infos from local config and use it to manipulate witch type of outfit i want set.

here's my script:

Lua:
local config = {
   outfits = {
   ["slayer"] = {looktype_m = 137, looktype_f = 149},
   ["archer"] = {looktype_m = 138, looktype_f = 150},
   ["wizzard"] = {looktype_m = 139, looktype_f = 151}
},
   storage = {652000, 652001, 652002}
}

function onSay(player, words, param)

   if player:getStorageValue(config.storage) < 1 then
      player:sendTextMessage(MESSAGE_INFO_DESCR, "You dont have a permission to use this command.")
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
   end

    local lookType = tostring(param)

    if lookType == config.outfits then
        if (player:getSex() == PLAYERSEX_FEMALE) then
         local playerOutfit = player:getOutfit(config.outfits.looktype_f)
         playerOutfit.lookType = config.outfits.looktype_f
         player:setOutfit(playerOutfit)
         player:addOutfit(playerOutfit)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You've weared a " .. config.outfits .." outfit.")
        else
         local playerOutfit = player:getOutfit(config.outfits.looktype_m)
         playerOutfit.lookType = config.outfits.looktype_m
         player:setOutfit(playerOutfit)
         player:addOutfit(playerOutfit)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You've weared a " .. config.outfits .." outfit.")
      end
    else
        player:sendCancelMessage("This outfit does not exist.")
    end
    return false
end

the idea is the script verify if your storageValue is valid, if yes after use a command setting the specific outfit it will deal with the parameters of "local config" to change for the chosen one.

the point is im just trying to avoid use more than one script for this command of outfits, but im not getting success in how to deal with the variables and set them.

thanks in advance.
Post automatically merged:

solved, thanks anyway.
 
Last edited:
Try this:
Lua:
outfit = {
    [1] = { name = "slayer", looktype_m = 137, looktype_f = 149, stor = 652000 },
    [2] = { name = "archer", looktype_m = 138, looktype_f = 150, stor = 652001 },
    [3] = { name = "wizzard", looktype_m = 139, looktype_f = 151, stor = 652002 },
}

function onSay(player, words, param)
    for i = 1, #outfit do
        if player:getStorageValue(outfit[i].stor) <= 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You dont have a permission to use this command.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end

        local param = tostring(param)
        if param == outfit[i].name then
            if (player:getSex() == PLAYERSEX_FEMALE) then
                local o_f = player:getOutfit()
                o_f.lookType = outfit[i].looktype_f
            else
                local o_f = player:getOutfit()
                o_f.lookType = outfit[i].looktype_m
            end

            player:setOutfit(o_f)
            player:addOutfit(o_f)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You've weared a " .. outfit[i].name .. " outfit.")
        else
            player:sendCancelMessage("This outfit does not exist.")
        end
    end

    return false
end
 
Try
Lua:
local selected = config.outfit[param]
if selected then
    -- exists
end
Post automatically merged:

Another example: forgottenserver/bed_modification_kits.lua at 59a109bba117803e5e84c740398946a1e7c9a961 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/59a109bba117803e5e84c740398946a1e7c9a961/data/actions/scripts/other/bed_modification_kits.lua#L20)
Post automatically merged:

Similar system, but with item
 
Oops, I got confused, I created a repeating structure, but there is no need.
Try it this way:
Lua:
config = {
    outfit = {
        ["slayer"] = { looktype_m = 137, looktype_f = 149, stor = 652000 },
        ["archer"] = { looktype_m = 138, looktype_f = 150, stor = 652001 },
        ["wizzard"] = { looktype_m = 139, looktype_f = 151, stor = 652002 },
    }
}

function onSay(player, words, param)
    selected = config.outfit[param]
    if selected then
        if player:getStorageValue(selected.stor) <= 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You dont have a permission to use this command.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)

            return false
        end

        o_f = player:getOutfit()
        if (player:getSex() == PLAYERSEX_FEMALE) then
            o_f.lookType = selected.looktype_f
        else
            o_f.lookType = selected.looktype_m
        end

        player:setOutfit(o_f)
        player:addOutfit(o_f)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You've weared a " .. selected .. " outfit.")
    else
        player:sendCancelMessage("This outfit does not exist.")
    end

    return false
end
 
Back
Top