• 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!

Change player outfit on use (action) TFS 1.2

Doitforthegains

Well-Known Member
Joined
Aug 30, 2014
Messages
231
Reaction score
74
Hey guys! So I'm making vocation levers, that when used, the lever is is suppose to reward items, change players voc, send magic effect, and finally change outfit to corrisponding voc. As of right now the only thing not registering onUse is ChangeOutfit...Heres my script. As I mentioned in the title I'm using TFS 1.2
Code:
local cfgItems = {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}, {8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getActionId(13165) and getPlayerVocation(player) == 20 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have become an orc warrior!.")
         
        local bag = player:addItem(1988) -- Bag id
        for i = 1, #cfgItems do
            bag:addItem(cfgItems[i][1], cfgItems[i][2])
        end
        doPlayerSetVocation(player, 23)
        doSendMagicEffect(getThingPos(player), CONST_ME_MAGIC_HOLYAREA) 
        doCreatureChangeOutfit(cid, 7) --I want it to switch players outfit to ID 7 -orc warrior-
        else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already chosen your vocation.")
       end
end
I'm not receiving any errors in my console either..
Does anyone know why it's not registering?

Thanks in advance for your help!
 
Hey guys! So I'm making vocation levers, that when used, the lever is is suppose to reward items, change players voc, send magic effect, and finally change outfit to corrisponding voc. As of right now the only thing not registering onUse is ChangeOutfit...Heres my script. As I mentioned in the title I'm using TFS 1.2
Code:
local cfgItems = {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}, {8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getActionId(13165) and getPlayerVocation(player) == 20 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have become an orc warrior!.")
      
        local bag = player:addItem(1988) -- Bag id
        for i = 1, #cfgItems do
            bag:addItem(cfgItems[i][1], cfgItems[i][2])
        end
        doPlayerSetVocation(player, 23)
        doSendMagicEffect(getThingPos(player), CONST_ME_MAGIC_HOLYAREA)
        doCreatureChangeOutfit(cid, 7) --I want it to switch players outfit to ID 7 -orc warrior-
        else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already chosen your vocation.")
       end
end
I'm not receiving any errors in my console either..
Does anyone know why it's not registering?

Thanks in advance for your help!
Code:
player:setOutfit(7) -- switch players outfit to ID 7 -orc warrior-
 
Just tried setting player:setOutfit(7) and it gave me this error:
Code:
in function 'setOutfit'
data/actions/scripts/lever.lua:13: in function <data/actions/scripts/lever.lua:3>
:(
--EDIT-- Apparently if I set it to 'doCreatureChangeOutfit(player, 7)' I get a similar error
Code:
in function 'setOutfit'
data/lib/compat/compat.lua:176 in function 'doCreatureChangeOutfit'
data/actions/scripts/lever.lua:13: in function <data/actions/scripts/lever.lua:3>
 
Last edited:
Outfit is a table which consist of

LookType,LookFeet,LookBody,Look~~

you can find it in luascript.cpp

search for PushOutfit
Code:
void LuaInterface::pushOutfit(lua_State* L, const Outfit_t& outfit)
{
   lua_newtable(L);
   setField(L, "lookType", outfit.lookType);
   setField(L, "lookTypeEx", outfit.lookTypeEx);
   setField(L, "lookHead", outfit.lookHead);
   setField(L, "lookBody", outfit.lookBody);
   setField(L, "lookLegs", outfit.lookLegs);
   setField(L, "lookFeet", outfit.lookFeet);
   setField(L, "lookAddons", outfit.lookAddons);
}

So you cant just type
player:setOutfit(7)

you have to do it like this
Code:
local outfit = getCreatureOutfit(cid)
outfit.lookTypeEx = 7
player:setOutfit(outfit)

this is just an example.. it might not work with tfs 1.2
 
you have to do it like this
Code:
local outfit = getCreatureOutfit(cid)
outfit.lookTypeEx = 7
player:setOutfit(outfit)

this is just an example.. it might not work with tfs 1.2
If getCreatureOutfit(cid) returns a table and one of its properties is lookTypeEx you can update the value by calling just the one property and it won't erase or alter the entire table. This method of assignment will work for any table in any distribution.
 
I tried adding what you said @tetra20 but I received this error:
Code:
attempt to index local 'outfit' (a boolean value)
stack traceback:
[C]: in function '__newindex'
data/actions/scripts/orc_warrior_lever.lua:15: in function <data/actions/scripts/orc_warrior_lever.lua:3>
@Sharkot I'm super newbie in lua/coding so I think I understand what you're saying but wouldn't know how to execute it :(
 
I tried adding what you said @tetra20 but I received this error:
Code:
attempt to index local 'outfit' (a boolean value)
stack traceback:
[C]: in function '__newindex'
data/actions/scripts/orc_warrior_lever.lua:15: in function <data/actions/scripts/orc_warrior_lever.lua:3>
@Sharkot I'm super newbie in lua/coding so I think I understand what you're saying but wouldn't know how to execute it :(

Code:
local outfit = player:getOutfit()
outfit.lookType = 7
player:setOutfit(outfit)


Code:
local cfgItems = {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}, {8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if player:getVocation() ~= 20 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already chosen your vocation.")
            return true
        end

        local bag = player:addItem(1988)
        for i = 1, #cfgItems do
            bag:addItem(cfgItems[i][1], cfgItems[i][2])
        end
       
        player:setVocation(23)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have become an orc warrior!")
        player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        local outfit = player:getOutfit()
        outfit.lookType = 7
        player:setOutfit(outfit)
    return true
end
 
Back
Top