• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction [TFS 1.1-1.2] Guild Outfit Change (!go)

narko

vertrauenswürdig ~
Joined
Oct 19, 2008
Messages
1,317
Solutions
2
Reaction score
131
Location
Unknown
As I'm working on a new project, I had to adapt this script from 0.3/0.4 to make it work in TFS 1.1/1.2 and I'm glad to release it here in OtLand. I hope it's useful for someone.

Tested in TFS 1.2 and it worked perfectly.

Bugs:
- None (please report any problem)

Picture:
9hkzE7c4m.png


Full credit goes to Slawkens I only adapted it to work on newer revs.

Make a file called guild_outfit.lua in your talkactions folder.
Code:
function string.diff(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }

    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end

local config = {
            exhaustion = 299551, -- exhaust storage
            duration = 5 -- counted in seconds for example 5*60 for 5 minutes.
        }

function onSay(player, words, param, channel, creature)

            local playerGuild = player:getGuild()
            local creature = player

            if (os.time() - player:getStorageValue(config.exhaustion)) < config.duration then
             player:sendTextMessage(MESSAGE_INFO_DESCR,"You have to wait
' .. string.diff(player:getStorageValue(config.exhaustion)-os.time()) .. ' before
using this command again.")
                return false
            end

            if(not playerGuild or playerGuild:getId() == 0) then
                player:sendTextMessage(MESSAGE_INFO_DESCR,"Sorry, you're not in a guild.")
                return false
            end

            if player:getGuildLevel() < 2 then -- 3 = Leader, 2 = Vice-Leader, 1 = Regular Member
                player:sendTextMessage(MESSAGE_INFO_DESCR,"You have to be Leader or Vice-Leader of your guild to change outfits!")
                return false
            end

            local outfit, count = creature:getOutfit(), 0
            local message = "*Guild* Your outfit has been changed by leader. (" ..player:getName() .. ")"
            for _, members in ipairs(Game.getPlayers()) do
                if(members:getGuild() == playerGuild and player ~= members) then
                    local newOutfit = outfit
                    if(not members:hasOutfit(outfit.lookType, outfit.lookAddons)) then
                        local tmpOutfit = members:getOutfit()
                        newOutfit.lookAddons = 0--tmpOutfit.lookAddons
                        if(not members:hasOutfit(outfit.lookType, 0)) then
                            newOutfit.lookType = tmpOutfit.lookType
                        end
                    end

                    members:getPosition():sendMagicEffect(66)
                    members:setOutfit(newOutfit)
                    members:sendTextMessage(MESSAGE_INFO_DESCR, message)
                    count = count + 1
                end
            end

            player:sendTextMessage(MESSAGE_INFO_DESCR,"Guild members outfit has been changed. (Total: " .. count .. ")")
            player:setStorageValue(config.exhaustion, os.time() + config.duration)
            return false
        end
 
Last edited:
You should have used Guild.getMembersOnline instead of iterating through Game.getPlayers, and there's a bug on L16 (playerGuild:getId() == 0). There are some other things you can change as well, but w/e. :p

It's meant as constructive criticism, no offence intended. Great release nonetheless!
 
You should have used Guild.getMembersOnline instead of iterating through Game.getPlayers, and there's a bug on L16 (playerGuild:getId() == 0). There are some other things you can change as well, but w/e. :p

It's meant as constructive criticism, no offence intended. Great release nonetheless!

It's ok, constructive criticism is always welcome. I'm gonna try to add these changes you asked me. Thank you.
 
change with this is good to work with all :)
Code:
if (player:getStorageValue(config.exhaustion) > os.time())then
doPlayerSendCancel(player,"You must wait another " .. player:getStorageValue(config.exhaustion) - os.time() .. ' second' .. ((player:getStorageValue(config.exhaustion) - os.time()) == 1 and "" or "s") .. " to use this command again.")
return false
end
 
Line 35 should look like this:
PHP:
             player:sendTextMessage(MESSAGE_INFO_DESCR,"You have to wait" .. string.diff(player:getStorageValue(config.exhaustion)-os.time()) .. " before using this command again.")
 
This is changing the mount too and inside depot... how can we change this?
thanks for this
 
This is changing the mount too and inside depot... how can we change this?
thanks for this
If we check the sources we should be able to modify the value of outfit.
Code:
Outfit_t LuaScriptInterface::getOutfit(lua_State* L, int32_t arg)
{
    Outfit_t outfit;
    outfit.lookMount = getField<uint16_t>(L, arg, "lookMount");
    outfit.lookAddons = getField<uint8_t>(L, arg, "lookAddons");

    outfit.lookFeet = getField<uint8_t>(L, arg, "lookFeet");
    outfit.lookLegs = getField<uint8_t>(L, arg, "lookLegs");
    outfit.lookBody = getField<uint8_t>(L, arg, "lookBody");
    outfit.lookHead = getField<uint8_t>(L, arg, "lookHead");

    outfit.lookTypeEx = getField<uint16_t>(L, arg, "lookTypeEx");
    outfit.lookType = getField<uint16_t>(L, arg, "lookType");

    lua_pop(L, 8);
    return outfit;
}

Find this line
Code:
    local outfit, count = creature:getOutfit(), 0
And change it to this
Code:
    local outfit, count = creature:getOutfit(), 0
    outfit = {lookType = outfit.lookType, lookHead = outfit.lookHead, lookBody = outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet = outfit.lookFeet, lookTypeEx = outfit.lookTypeEx, lookAddons = outfit.lookAddons}

Now using the table you can take away things you don't want, I didn't include lookMount because obviously it is something you wanted to avoid.

If you need further assistance you can always reference the swimming script in movements
https://github.com/otland/forgotten...00a46a/data/movements/scripts/swimming.lua#L1
 
Last edited:
thanks but no have other method only in lua ?
That is the method in lua, we aren't modifying the sources, we are just referencing the metamethod to see what it returns, in this case it is a table of properties and values, which we can selectively include.
 
Back
Top