• 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 7.6 How to make a NPC who changes outfits for Players?

GOD Rox

New Member
Joined
Aug 31, 2010
Messages
8
Reaction score
2
Hello I have a problem with a Script. GM/Admins can change outfits by the command /outfit.

Example: /outfit Name, 2 (Orc Warlord)

Now I wanted to add a NPC who changes outfits with this command. The problem is that when the npc says this command, the server crashs.
With Admin or GM it works. The NPC has also the same access.

This is the script:

Lua:
 focus = 0
 talk_start = 0
 target = 0
 following = false
 attacking = false
 
 function onThingMove(creature, thing, oldpos, oldstackpos)
 
 end
 
 
 function onCreatureAppear(creature)
 
 end
 
 
 function onCreatureDisappear(cid, pos)
     if focus == cid then
         selfSay('Good bye then.')
         focus = 0
         talk_start = 0
     end
 end
 
 
 function onCreatureTurn(creature)
 
 end

function msgcontains(txt, str)
     return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
 end
 
 
 function onCreatureSay(cid, type, msg)
     msg = string.lower(msg)
 
      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Hiho ' .. creatureGetName(cid) .. '! Welcome to the gm shop, here you can buy more hp, mana, or change your outfit.')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

    elseif focus == cid then
        talk_start = os.clock()

      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Hiho ' .. creatureGetName(cid) .. '! Welcome to the gm shop, here you can buy more hp, mana, or change your outfit.')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

    elseif focus == cid then
        talk_start = os.clock()

    if msgcontains(msg, 'health') or msgcontains(msg, 'hp') then
        if pay(cid,10000000) then
            selfSay('/health ' .. creatureGetName(cid) .. '')
        end
    elseif msgcontains(msg, 'mana') then
        if pay(cid,10000000) then
            selfSay('/mana ' .. creatureGetName(cid) .. '')
        end

        elseif msgcontains(msg, '2') then
            monsterName = 'orc warlord'
        if pay(cid,40000000) then
            selfSay('/outfit ' .. creatureGetName(cid) .. ', ' .. monsterName .. '')
        end

        elseif msgcontains(msg, '3') then
            monsterName = 'war wolf'
        if pay(cid,40000000) then
            selfSay('/outfit ' .. creatureGetName(cid) .. ', ' .. monsterName .. '')
            end


      elseif string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 3 then
          selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
          focus = 0
          talk_start = 0
      end     
 end
 end
 end
 
 function onCreatureChangeOutfit(creature)
 
 
 end
 
 
 function onThink()
     if (os.clock() - talk_start) > 30 then
         if focus > 0 then
             selfSay('Next Please...')
         end
             focus = 0
     end
 end
 
I don't understand why you'd want the npc to change appearance though.
Wouldn't the player be the one getting it's appearance changed?

Beyond that, you have it backwards. xD
You're taking the number and inputting the name.. where you should be taking the monster name and converting it into a number, for use with the talkaction.

annnd, instead of forcing the npc to say the command, just force the player to say the command.
Lua:
-- doCreatureExecuteTalkAction(cid, text[, ignoreAccess = false[, channelId = CHANNEL_DEFAULT]])
doCreatureExecuteTalkAction(cid, "/outfit " .. getCreatureName(cid) .. ", " .. monsterNumber, true) -- ignore access requirement (true)

But, this is kind of a crude way of going about it, since you can just do it manually.
Lua:
-- doSetMonsterOutfit(cid, name[, time = -1])

local monsterName = "rat"
if getMonsterInfo(monsterName) then
    doSetMonsterOutfit(cid, monsterName, -1) -- -1 means forever, until the player relogs or changes outfit
else
    -- monster does not exist
end
 
This is an old 7.6 server. I dont have talkactions. Also I cannot use this functions: doSetMonsterOutfit, getMonsterInfo or doCreatureExecuteTalkAction.
 
This is an old 7.6 server. I dont have talkactions. Also I cannot use this functions: doSetMonsterOutfit, getMonsterInfo or doCreatureExecuteTalkAction.
Okay then.
Post the script that is attached to /outfit

More then likely your server has the function doCreatureChangeOutfit, but no point in continuing to guess what functions your server has, when I can just view a script that already has the function available xD
 
Change
Code:
selfSay('/outfit ' .. creatureGetName(cid) .. ', ' .. monsterName .. '')

to

Code:
selfSay("/outfit " .. creatureGetName(cid) .. ", " .. monsterName .. ''")

It may do nothing but I know ' has some limitations compared to "
 
Back
Top