• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC +[Globalevent] Team Battle, easy to configure

Thanks, but it isn't 100% finished (check To-Do list) :p
I'm to lazy to fix everything right now! But when I finished everything I will release it for sure :)
 
Thanks guys :) I will improve when I can and release all the scripts for it!
I will try make everything in MOD !
 
thx for the basics, i have been looking for this..
 
[10/03/2010 22:54:54] [Error - GlobalEvent Interface]
[10/03/2010 22:54:54] data/globalevents/scripts/BattleCheck.lua:eek:nThink
[10/03/2010 22:54:54] Description:
[10/03/2010 22:54:54] data/globalevents/scripts/BattleCheck.lua:55: attempt to perform arithmetic on global 'battleTime' (a nil value)
[10/03/2010 22:54:54] stack traceback:
[10/03/2010 22:54:54] data/globalevents/scripts/BattleCheck.lua:55: in function <data/globalevents/scripts/BattleCheck.lua:41>
[10/03/2010 22:54:54] [Error - GlobalEvents::think] Couldn't execute event: TeamBattle

????

[10/03/2010 22:59:14] [Error - Npc interface]
[10/03/2010 22:59:14] data/npc/scripts/BattleNPC.lua:eek:nCreatureSay
[10/03/2010 22:59:14] Description:
[10/03/2010 22:59:14] (luaGetCreatureStorage) Creature not found

When I try to "leave" battle.


TFS 0.3.6
 
@up

then... no one above you tested it :x and tell things like nice blah blah

change

addEvent(stopBattle, battleTime * 60 * 1000)

to

addEvent(stopBattle, cfg.battleTime * 60 * 1000)

if you find another bug like that do same way 8D


NPC fix i didnt see another error
Lua:
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 cfg = 
    {
        signedUp1 = 100000,
        signedUp2 = 100001,
        maxPlayerEachTeam = 10,
        team1Storage = 100002,
        team2Storage = 100003,
        team1Name = "Punishers",
        team2Name = "Tha Artards"
    }


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 msgcontains(msg, 'battle') then
        npcHandler:say("Do you wish to join the battle? There is currently " .. getGlobalStorageValue(cfg.team1Storage) .. "/" .. cfg.maxPlayerEachTeam .. " players in {" .. cfg.team1Name .. "} team and " .. getGlobalStorageValue(cfg.team2Storage) .. "/" .. cfg.maxPlayerEachTeam .. " players in {" .. cfg.team2Name .. "} team.", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if getPlayerStorageValue(cid, cfg.signedUp1) ~= 1 and getPlayerStorageValue(cid, cfg.signedUp2) ~= 1 then
            npcHandler:say("Do you wish to join {" .. cfg.team1Name .. "} or {" .. cfg.team2Name .. "}?", 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, cfg.team1Name) and talkState[talkUser] == 2 then
        if getGlobalStorageValue(cfg.team1Storage) ~= cfg.maxPlayerEachTeam then --fixed
            setPlayerStorageValue(cid, cfg.signedUp1, 1)
            setGlobalStorageValue(cfg.team1Storage, (getGlobalStorageValue(cfg.team1Storage)+1))
            npcHandler:say("You have joined " .. cfg.team1Name .. "! When both teams have " .. cfg.maxPlayerEachTeam .. " players you will be teleported to the battle arena.", cid)
            doBroadcastMessage("[Team Battle]: " .. getPlayerName(cid) .. " have joined the battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. "!", TALKTYPE_BROADCAST)
            talkState[talkUser] = 0
        else
            npcHandler:say("{" .. cfg.team1Name .. "} is currently full, join {" .. cfg.team2Name .. "} or wait for someone to leave {" .. cfg.team1Name .. "}.", cid) --fixed
            talkState[talkUser] = 1
        end
    elseif msgcontains(msg, cfg.team2Name) and talkState[talkUser] == 2 then
        if getGlobalStorageValue(cfg.team2Storage) ~= cfg.maxPlayerEachTeam then --fixed
            setPlayerStorageValue(cid, cfg.signedUp2, 1) --fixed
            setGlobalStorageValue(cfg.team2Storage, (getGlobalStorageValue(cfg.team2Storage)+1))
            npcHandler:say("You have joined " .. cfg.team2Name .. "! When both teams have " .. cfg.maxPlayerEachTeam .. " players you will be teleported to the battle arena.", cid)
            doBroadcastMessage("[Team Battle]: " .. getPlayerName(cid) .. " have joined the battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. "!", TALKTYPE_BROADCAST)
            talkState[talkUser] = 0
        else
            npcHandler:say("{" .. cfg.team2Name .. "} is currently full, join {" .. cfg.team1Name .. "} or wait for someone to leave {" .. cfg.team2Name .. "}.", 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(cfg.signedUp1) == 1 then
            setPlayerStorageValue(cid, cfg.signedUp1, -1) -- fixed
            setGlobalStorageValue(cfg.team1Storage, (getGlobalStorageValue(cfg.team1Storage)-1))
            npcHandler:say("You have left the battle.", cid)
            doBroadcastMessage("[Team Battle]: " .. getPlayerName(cid) .. " have left the battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. "!", TALKTYPE_BROADCAST)
        else
            npcHandler:say("You are not even signed up!", cid)
        end
        talkState[talkUser] = 0 -- moved
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        if getPlayerStorageValue(cid, cfg.signedUp2) == 1 then --fixed
            setPlayerStorageValue(cid, cfg.signedUp2, -1) --fixed
            setGlobalStorageValue(cfg.team2Storage, (getGlobalStorageValue(cfg.team2Storage)-1))
            npcHandler:say("You have left the battle.", cid)
            doBroadcastMessage("[Team Battle]: " .. getPlayerName(cid) .. " have left the battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. "!", TALKTYPE_BROADCAST)
        else
            npcHandler:say("You are not even signed up!", cid)
        end    
        talkState[talkUser] = 0 --moved
    end                                                                                                    
    return true
end


       

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Lua:
function onCombat(cid, target)
local team1Storage = 100002
	if getPlayerStorageValue(cid, team1Storage) == 1 and getPlayerStorageValue(target, team1Storage) == 1 then
		doPlayerSendCancel(cid, "You cannot attack your own team.")
		return FALSE
	end
end

And, I have modified the globalevent Script To remove Walls on the begin of the Match and do Create the Walls on the end of the match. (To Fix the PZ Bug you have).
[UNTESTED]
Lua:
  local cfg =
    {           team1Wall_id = 9785,
                team2Wall_id = 9784,
                team1Wall_pos = { x = 31948, y = 32111, z = 7 },
                team2Wall_pos = { x = 31900, y = 32045, z = 7 }, 
                signedUp1 == 100000,
                signedUp2 == 100001,
                maxPlayerEachTeam = 1,
                team1Storage = 100002,
                team2Storage = 100003,
                team1Name = "The Good",
                team2Name = "The Evil",
                team1Pos = { x = 31951, y = 32119, z = 7 },
                team2Pos = { x = 31900, y = 32036, z = 7 },
                running = 100004,
                battleTime = 25 -- Minutes
    }

function stopBattle()
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerStorageValue(cid, cfg.signedUp1) == 1 or getPlayerStorageValue(cid, cfg.signedUp2) == 1 then
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
            doSendMagicEffect(cfg.team2Pos, CONST_ME_TELEPORT)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            setPlayerStorageValue(cid, cfg.signedUp1, -1)
            setPlayerStorageValue(cid, cfg.signedUp2, -1)
        end
    end
    setGlobalStorageValue(cfg.team1Storage, -1)
    setGlobalStorageValue(cfg.team2Storage, -1)
    setGlobalStorageValue(cfg.team1Storage, 0)
    setGlobalStorageValue(cfg.team2Storage, 0)
    setGlobalStorageValue(cfg.running, 0)
    doBroadcastMessage("The battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. " is over.", 12)
    doCreateItem(cfg.team2Wall_id, 1, cfg.team1Wall_pos)
    doCreateItem(cfg.team2Wall_id, 1, cfg.team2Wall_pos)
end


function onThink(interval, lastExecution)
local team1Wall = getTileItemById(cfg.team1Wall_pos, cfg.team1Wall_id).uid
local team2Wall = getTileItemById(cfg.team2Wall_pos, cfg.team2Wall_id).uid

        if getGlobalStorageValue(cfg.team1Storage) == -1 then
                setGlobalStorageValue(cfg.team1Storage, 0)
        end
        
        if getGlobalStorageValue(cfg.team2Storage) == -1 then
                setGlobalStorageValue(cfg.team2Storage, 0)
        end

    if getGlobalStorageValue(cfg.team1Storage) == cfg.maxPlayerEachTeam and getGlobalStorageValue(cfg.team2Storage) == cfg.maxPlayerEachTeam then
                if getGlobalStorageValue(cfg.running) ~= 1 then
                        doBroadcastMessage("The battle between " .. cfg.team1Name .. " and " .. cfg.team2Name .. " has started! They will battle " .. cfg.maxPlayerEachTeam .. " vs " .. cfg.maxPlayerEachTeam .. "!", 12)
                        setGlobalStorageValue(cfg.running, 1)
                        addEvent(stopBattle, cfg.battleTime * 60 * 1000)
                        doRemoveItem(team1Wall)
                        doRemoveItem(team2Wall)
                        for _, cid in ipairs(getPlayersOnline()) do
                                if getPlayerStorageValue(cid, cfg.signedUp1) == 1 then
                                        doTeleportThing(cid, cfg.team1Pos, FALSE)
                                        doSendMagicEffect(cfg.team1Pos, CONST_ME_TELEPORT)
                                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                elseif getPlayerStorageValue(cid, signedUp2) == 1 then
                                        doTeleportThing(cid, cfg.team2Pos, FALSE)
                                        doSendMagicEffect(cfg.team2Pos, CONST_ME_TELEPORT)
                                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                end
                        end
                end
        end
    return true
end


EDIT: I didnt read the script so i didnt realize the PZ abuse so the script doesnt help, But The script doesnt even work in General so .. -.-
 
Last edited:
@up

then... no one above you tested it :x and tell things like nice blah blah

change

addEvent(stopBattle, battleTime * 60 * 1000)

to

addEvent(stopBattle, cfg.battleTime * 60 * 1000)

if you find another bug like that do same way 8D


NPC fix i didnt see another error

Thanks, edited first post

EDIT: I didnt read the script so i didnt realize the PZ abuse so the script doesnt help, But The script doesnt even work in General so .. -.-

What you mean didn't work in General? :p
 
I tested it on 0.3.6, The npc seems to work fine but the globalevent script does nothing =p
 
@Sync
The global event script work. I already tested it :p
Are you sure you had "maxPlayerEachTeam" players in both teams then?
 
pm me
i can help you scripting the creature events
 
It's perfect! But can't you make that, for example just sorcerers and druids can join to first team. They will not be avable to join in second team. That's same with knight and pala. They can join just second team, can't first?
 
Yes, I can do that, but I'm too lazy right now and can't test the scripts.. So I won't be updating it for a while :p
 
Back
Top