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

Exchange NPC - Rep++ if you helped ofc (rep power 7)

christiandb

Member
Joined
Feb 5, 2008
Messages
2,469
Reaction score
5
Location
010
Heya,

I got this so far:
PHP:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local 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)
end

      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Great to meet you again, ' .. creatureGetName(cid) .. '! I can exchange mystic turban for 1 blue piece of cloth, red robe for 1 red piece of cloth, green tunics for 1 green piece of cloth. And i can exchange a crown armor for piece of royal steel, devil helmet for piece of hell steel, dragon shield for piece of draconian steel, giant sword for huge chunk of crude iron, soul orb for 10 infernal bolts. Also warrior helmet for 1 flask warrior sweat and 10 giant spider silk for spool of yarn.')
          focus = cid
          talk_start = os.clock()
end

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

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

        if msgcontains(msg, 'warrior helmet') then
            selfSay('Do you want trade 4 warrior helmets for warrior sweat?')
            talk_state = 1    
end
        elseif talk_state == 1 then
            if msgcontains(msg, 'yes') then
            doPlayerRemoveItem(cid, 2475, 4)
            doPlayeraddItem(cid, 5885, )
            selfSay('Here you go, warror sweat.')
                
                end
             end
            
    talk_state = 0
            
        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
    end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
    doNpcSetCreatureFocus(focus)
    if (os.clock() - talk_start) > 30 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.)
             focus = 0
         end
     end
end

It's probably really bugged and I heard it's using the old NPC-system. I'd appreciate it if someone can fix this (rep++ as well ofc).

Thanks in advance,

Chris~
 
PHP:
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)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local message = string.lower(msg)

    
    -- FIRST TRADE BELOW
    if msgcontains(message, 'warrior sweat') then
        selfSay("Do you want trade 4 warrior helmets for warrior sweat?", cid)
        talkState[talkUser] = 1
    -- SECOND TRADE BELOW
    elseif msgcontains(message, 'whatever else') then
        selfSay("Do you want trade 2 of something for something else?", cid)
        talkState[talkUser] = 2
    end
    
    
    if msgcontains(message, 'yes') then
        -- FIRST TRADE BELOW
        if talkState[talkUser] == 1 then
            if doPlayerRemoveItem(cid, 2475, 4) == TRUE then
                doPlayerAddItem(cid, 5885)
                selfSay("Here you go, warrior sweat.", cid)
            end
        -- SECOND TRADE BELOW
        elseif talkState[talkUser] == 2 then
            if doPlayerRemoveItem(cid, 2475, 2) == TRUE then
                doPlayerAddItem(cid, 5885)
                selfSay("Here you go, something else.", cid)
            end
        end
    elseif msgcontains(message, 'no') and talkState[talkUser] > 0 then
        selfSay("Maybe another time...", cid)
        talkState[talkUser] = 0
    end
    return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:

Similar threads

  • Question Question
Replies
0
Views
182
Back
Top