• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Instantly change outfit

Booker

New Member
Joined
Apr 2, 2015
Messages
46
Reaction score
4
I have the following script of an NPC who changes my vocation:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

function creatureSayCallback(cid, type, msg)
   
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local stg = 57894
   
    if getPlayerStorageValue(cid, stg) < 1 then       
        if msgcontains(msg:lower(), 'sorcerer') then
            npcHandler:say('A SORCERER! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!', cid)
            talkState[talkUser] = 1       
        elseif msgcontains(msg:lower(), 'druid') then
            npcHandler:say('A DRUID! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!', cid)
            talkState[talkUser] = 2   
        elseif msgcontains(msg:lower(), 'paladin') then
            npcHandler:say('A PALADIN! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!', cid)
            talkState[talkUser] = 3   
        elseif msgcontains(msg:lower(), 'knight') then
            npcHandler:say('A KNIGHT! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!', cid)
            talkState[talkUser] = 4
        elseif msgcontains(msg:lower(), 'yes') then
            if talkState[talkUser] == 1 then
                doPlayerSetVocation(cid, 1)
                npcHandler:say('SO BE IT!', cid)
                setPlayerStorageValue(cid, stg, 1)
                talkState[talkUser] = 0
            elseif talkState[talkUser] == 2 then
                doPlayerSetVocation(cid, 2)
                npcHandler:say('SO BE IT!', cid)
                setPlayerStorageValue(cid, stg, 1)
                talkState[talkUser] = 0
            elseif talkState[talkUser] == 3 then
                doPlayerSetVocation(cid, 3)
                npcHandler:say('SO BE IT!', cid)
                setPlayerStorageValue(cid, stg, 1)
                talkState[talkUser] = 0
            elseif talkState[talkUser] == 4 then
                doPlayerSetVocation(cid, 4)
                setPlayerStorageValue(cid, stg, 1)
                npcHandler:say('SO BE IT!', cid)
                talkState[talkUser] = 0
            end
        elseif msgcontains(msg:lower(), 'no') then
            npcHandler:say(getCreatureName(cid) .. ', WHAT KIND OF PROFESSIONAL DO YOU WANNA BE? KNIGHT, PALADIN, SORCERER, OR DRUID?', cid)
            talkState[talkUser] = 0
        elseif msgcontains(msg:lower(), 'bye') then
            npcHandler:say('Good bye.', cid)
            talkState[talkUser] = 0
        end
    else
        npcHandler:say('YOU ALREADY HAVE VOCATION!', cid)
        talkState[talkUser] = 0
    end               
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

It works well, but i want the NPC to give my instantly and outfit and take another one from me. Note that it needs to change by the time the words "yes" are said (to accept the vocation).

Should i use a string like "DoChangeCreatureOutfit" or something like that? I want him to take the outfit 250 away and give me the outfit 460.

Thanks fellas
 
TFS versions?
Either
Code:
Player:setOutfit(outfitArray)
Or
Code:
doCreatureChangeOutfit(cid, outfitArray)
 
TFS versions?
I'm using TFS 0.3.6
Where exactly should i put your code?
I put it this way:
Code:
doPlayerSetVocation(cid, 1)
                npcHandler:say('SO BE IT!', cid)
                setPlayerStorageValue(cid, stg, 1)
                doCreatureChangeOutfit(cid, 460)
                talkState[talkUser] = 0
(460 is the outfit i want to change to)
but doesn't work. Sorry i'm really a newbie!
 
Last edited:
I'm using TFS 0.3.6
Where exactly should i put your code?
I put it this way:
Code:
doPlayerSetVocation(cid, 1)
                npcHandler:say('SO BE IT!', cid)
                setPlayerStorageValue(cid, stg, 1)
                doCreatureChangeOutfit(cid, 460)
                talkState[talkUser] = 0
(460 is the outfit i want to change to)
but doesn't work. Sorry i'm really a newbie!
Code:
local outfit = getPlayerOutfit(cid)
outfit.lookType = 460
doCreatureChangeOutfit(cid, outfit)

Not sure about getPlayerOutfit(cid), check your luascript.cpp file if its right or not.
 
Well i made it work just changing your "GetPlayerOutfit", into:
Code:
local outfit = getCreatureOutfit(cid)
                outfit.lookType = 460
                doCreatureChangeOutfit(cid, outfit)
Worked 100%, thanks for the help man!
 
Back
Top