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

Action Question

Calon

Experienced Member
Joined
Feb 6, 2009
Messages
1,070
Reaction score
21
Is possible to make this Npc Script a tp (when a player get in the tp get a auto balance between 2 team (red - blue) and tp to x y z pos) and the things in script V


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
 
    --[[Start edit]]--  
 
        local mingroup = 4 --(updated) minimum group to reset the event
        local joined = 10000 ---must be like the storage in mod
        local maxPlayerEachTeam = 4 ---must be like max number in mod
        local team1Name = "Blue" ---must be like team number i mod
        local team2Name = "red"
        local minlevel = 120 --(added) min lvl for a player to join.
 
		--[[Storage like in the mod file]]--
          local  running1 = 12000 --just add a non ussed storage
          local running2 = 12001 --just add a non ussed storage
          local sto = 12223 --just add a non ussed storage
         --[[Storage end]]--
 
 
 --[[End of edit]]--
local function getBlue()
	return getGlobalStorageValue(9888)
end
 local function removeBlue()
    return setGlobalStorageValue(9888, getGlobalStorageValue(9888) - 1)
end
local function addBlue()
   return setGlobalStorageValue(9888, getGlobalStorageValue(9888) + 1)
end
local function resetBlue()
      return setGlobalStorageValue(9888,0)
end
 
local function getRed()
	return getGlobalStorageValue(9887)
end
 local function removeRed()
    return setGlobalStorageValue(9887, getGlobalStorageValue(9887) - 1)
end
local function addRed()
   return setGlobalStorageValue(9887, getGlobalStorageValue(9887) + 1)
end
local function resetRed()
      return setGlobalStorageValue(9887,0)
end
--[[Script start]]--
 
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if getPlayerGroupId(cid) >= mingroup then
     npcHandler:say("Oh! Hail, sire. Do you want to reset my event?", cid)
	 talkState[talkUser] = 1
      if msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
	      	     resetBlue()
                 resetRed()
		         setGlobalStorageValue(running1,-1)
                 setGlobalStorageValue(running2,-1)
                 setGlobalStorageValue(sto,-1)
		         npcHandler:say("Event was reseted, sire.", cid)
		         doBroadcastMessage("My Event was reseted on the orders of "..getCreatureName(cid)..". So all who want to join msg me now.")
		 for _,cid in ipairs(getPlayersOnline()) do
		    if getPlayerStorageValue(cid, joined) > 0 then
			   setPlayerStorageValue(cid, joined,-1) 
			     doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
                 doSendMagicEffect(getCreaturePosition(cid), 10)
			 end
		 end
	  elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
	    npcHandler:say("As You wish, sire.", cid)
	     talkState[talkUser] = 0
	 end
else
    if msgcontains(msg, 'battle') then
	     if getGlobalStorageValue(running2) == 1 then   
             npcHandler:say("Battle will start latter, and it will be broadcaste that you can speak to me.", cid)
         elseif getPlayerLevel(cid) < minlevel then
	         npcHandler:say("Go Away noob! Only level 120+ are allowed.",cid)
		 else
         npcHandler:say("Do you wish to join the battle? There is currently " .. getBlue() .. "/" .. maxPlayerEachTeam .. " players in {" .. team1Name .. "} team and " .. getRed() .. "/" .. maxPlayerEachTeam .. " players in {" .. team2Name .. "} team.", cid)
         talkState[talkUser] = 1
	     end
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if getPlayerStorageValue(cid, joined) ~= 1 and getPlayerStorageValue(cid, joined) ~= 2 then
            npcHandler:say("Do you wish to join {" .. team1Name .. "} team  or {" .. team2Name .. "} team?", cid)
            talkState[talkUser] = 2
        else
            npcHandler:say("You are already signed up!", cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
        npcHandler:say("Okay then.", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, team1Name) and talkState[talkUser] == 2 then
        if getBlue() ~= maxPlayerEachTeam then --fixed
            setPlayerStorageValue(cid, joined, 1)
           addBlue()
            npcHandler:say("You have joined " .. team1Name .. " team! When both teams have " .. maxPlayerEachTeam .. " players you will be teleported to the battle arena.Please dont log out.", cid)
 
            talkState[talkUser] = 0
        else
            npcHandler:say("{" .. team1Name .. "} team is currently full, join {" .. team2Name .. "} team or wait for someone to leave {" .. team1Name .. "} team.", cid) --fixed
            talkState[talkUser] = 1
        end
    elseif msgcontains(msg, team2Name) and talkState[talkUser] == 2 then
        if getRed() ~= maxPlayerEachTeam then --fixed
            setPlayerStorageValue(cid, joined, 2) --fixed
           addRed()
            npcHandler:say("You have joined " .. team2Name .. " team! When both teams have " .. maxPlayerEachTeam .. " players you will be teleported to the battle arena.", cid)
 
            talkState[talkUser] = 0
        else
            npcHandler:say("{" .. team2Name .. "} team is currently full, join {" .. team1Name .. "} team or wait for someone to leave {" .. team2Name .. "} team.", cid)
            talkState[talkUser] = 1
        end
 elseif msgcontains(msg, 'leave') then
        npcHandler:say("Do you wish to leave the battle?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        if getPlayerStorageValue(cid,joined) == 1 then
            setPlayerStorageValue(cid, joined, -1) -- fixed
           removeBlue()
            npcHandler:say("You have left the battle.", cid)
            doBroadcastMessage("Event: " .. getPlayerName(cid) .. " have left the battle between " .. team1Name .. " and " .. team2Name .. "!")
        elseif getPlayerStorageValue(cid,joined) == 2 then --fixed
		      setPlayerStorageValue(cid,joined,-1)
              removeRed()
              npcHandler:say("You have left the battle.", cid)
             doBroadcastMessage("Event: " .. getPlayerName(cid) .. " have left the battle between " .. team1Name .. " and " .. team2Name .. "!")
		else
            npcHandler:say("You are not even signed up!", cid)
        end
        talkState[talkUser] = 0 -- moved
    end 
end	
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top