• 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 Change town transfer NPC, add more towns

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,492
Solutions
27
Reaction score
857
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again guys! I want to ask for a request, I have the following NPC that changes the player's town as soon you say "transfer" to it.
The thing is, that I have added one more city, so now I would like to make it able to transfer to two different towns now.

This way, if player says "thais", he got transfered to thais coordinates and residenced to town 3.
And if player says "mihen", he will get transfered to mihen coordinates and residenced to town 2.
And finally if player says "transfer" give the options to choose between "thais" or "mihen".

Lua:
local marks = {
    [1]={{x=1019,y=975,z=7},"Father Zuke",MAPMARK_TEMPLE},
    [2]={{x=1025,y=981,z=7},"Jassu",MAPMARK_STAR},
    [3]={{x=0979,y=0962,z=5},"Rin",MAPMARK_STAR},
    [4]={{x=989,y=964,z=5},"O'aka",MAPMARK_STAR},
    [5]={{x=989,y=971,z=5},"Keyakku",MAPMARK_STAR},
    [6]={{x=989,y=979,z=5},"Jassu",MAPMARK_STAR},
    [7]={{x=976,y=978,z=5},"Clasko",MAPMARK_STAR},
    [8]={{x=976,y=970,z=5},"Lucil",MAPMARK_STAR},
    [9]={{x=977,y=962,z=4},"Tromell",MAPMARK_STAR},
    [10]={{x=988,y=963,z=4},"Seymour",MAPMARK_STAR},
    [11]={{x=975,y=978,z=4},"Henricus",MAPMARK_QUESTION},
    [12]={{x=1022,y=977,z=8},"Amanda",MAPMARK_STAR},
    [13]={{x=986,y=1003,z=7},"Tim, The Guard",MAPMARK_QUESTION},
    [14]={{x=1048,y=999,z=7},"Walter, The Guard",MAPMARK_QUESTION},
    [15]={{x=1061,y=950,z=5},"Kulag, The Guard",MAPMARK_QUESTION},
    [16]={{x=1025,y=928,z=7},"Grof, The Guard",MAPMARK_QUESTION},
    [17]={{x=961,y=950,z=6},"Miles, The Guard",MAPMARK_QUESTION},
    [18]={{x=982,y=995,z=5},"Zaon",MAPMARK_STAR},
    [19]={{x=991,y=982,z=7},"Padreia",MAPMARK_QUESTION},
    [20]={{x=1168,y=1015,z=7},"Maroda",MAPMARK_QUESTION},
}

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

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if table.contains({"fuck", "idiot", "asshole", "ass", "fag", "stupid", "tyrant", "shit", "lunatic"}, msg) then
        npcHandler:say("Take this!", cid)
        local player = Player(cid)
        player:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONAREA)
        player:addCondition(condition)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
    end


    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
     local player = Player(cid)
     if msg == "marks" then
      for i = 1, #marks do
      player:addMapMark(marks[i][1],marks[i][3],marks[i][2],marks[i][4],marks[i][5],marks[i][6],marks[i][7],marks[i][8],marks[i][9],marks[i][10],marks[i][11],marks[i][12],marks[i][13],marks[i][14],marks[i][15],marks[i][16],marks[i][17],marks[i][18],marks[i][19],marks[i][20])
      end
      selfSay('Your world map has been marked with non-playable characters location.', cid)
      player:getPosition():sendMagicEffect(CONST_ME_STEPSVERTICAL)
      talkState[talkUser] = 0
      elseif msg == "home" then
      player:setTown(Town(1))
      selfSay('From now on you have become a citizen of Kilika.', cid)
      player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST)
      talkState[talkUser] = 0
      elseif msg == "mark" then
      for i = 1, #marks do
      -------------
      player:addMapMark(marks[i][1],marks[i][3],marks[i][2],marks[i][4],marks[i][5],marks[i][6],marks[i][7],marks[i][8],marks[i][9],marks[i][10],marks[i][11],marks[i][12],marks[i][13],marks[i][14],marks[i][15],marks[i][16],marks[i][17],marks[i][18],marks[i][19],marks[i][20])
      end
      selfSay('Your world map has been marked with non-playable characters location.', cid)
      player:getPosition():sendMagicEffect(CONST_ME_STEPSVERTICAL)
      talkState[talkUser] = 0
            --- transfer
      elseif msg == "transfer" then
      selfSay("Do you really want to leave this city? This {transfer} will change your {hometown} residence.", cid)
      talkState[talkUser] = 1
      elseif msg == "yes" and talkState[talkUser] == 1 then
      if not player:isPremium() then
      selfSay("Farewell!", cid)
      player:setTown(Town(2))
      player:teleportTo(player:getTown():getTemplePosition())
      --selfSay("You need to have premium account to use this feature.", cid)
      else
      selfSay("Farewell!", cid)
      player:setTown(Town(2))
      player:teleportTo(player:getTown():getTemplePosition())
      end
      talkState[talkUser] = 0
      elseif msg == "hometown" then
      player:setTown(Town(1))
      selfSay('From now on you have become a citizen of Kilika.', cid)
      player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST)
      talkState[talkUser] = 0
     else
    selfSay('I can only {mark} your world map, change your {hometown} or give you a {promotion}.', cid)
    talkState[talkUser] = 0
   end
   return true
end

local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})



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

Thanks in advance
Regards!
 
Back
Top