Itutorial
Excellent OT User
- Joined
- Dec 23, 2014
- Messages
- 2,307
- Solutions
- 68
- Reaction score
- 982
Place the flags set their AID to the one defined in the CTFlib file set all required information in the lib. (if you scroll down in the lib you can edit rewards) Have fun....Its not testing to 100% ability but I did test the majority of it and it works.
in data/ make a file called ctf.lua
data/talkactions/scripts make a file called ctf.lua
talkactions.xml
data/globalevents/scripts make a file called ctf.lua
in globalevents.xml
in data/ make a file called ctf.lua
Code:
config = {
["event"] = 50000,
["green_team"] = 50001,
["red_team"] = 50002,
["score_red_team"] = 50003,
["score_green_team"] = 50004,
["player_has_red_flag"] = 50005,
["player_has_green_flag"] = 50006,
["p_green_team"] = 50007,
["p_red_team"] = 50008,
["cycle"] = 50009,
["max_players_per_team"] = 10,
["required_players"] = 10,
["max_flags_captured"] = 10,
["end_automatic"] = true, --Should it end CTF by itself?
["end_automatically_minutes"] = 30,
["green_flag_pos"] = {x = 1301, y = 1739, z = 7},
["red_flag_pos"] = {x = 1294, y = 1739, z = 7},
["green_flag_itemid"] = 1437,
["red_flag_itemid"] = 1435,
["flag_aid"] = 3000,
["no_flag_itemid"] = 1642, --set this to item that pops up when flag is taken
["red_team_start_pos"] = {x = 1294, y = 1740, z = 7},
["green_team_start_pos"] = {x = 1301, y = 1740, z = 7},
["temple"] = {x = 1120, y = 1778, z = 7}
}
function openCTF()
Game.setStorageValue(config["event"], 1)
Game.broadcastMessage("CTF is now open. Type !joinCTF to enter.")
end
function playerJoinTeam(player)
if Game.getStorageValue(config["event"]) == 1 or Game.getStorageValue(config["event"]) == 2 then
if Game.getStorageValue(config["red_team"]) > config["max_players_per_team"] and Game.getStorageValue(config["green_team"]) > config["max_players_per_team"] then
return player:sendCancelMessage("The teams are full.")
end
if Game.getStorageValue(config["red_team"]) <= Game.getStorageValue(config["green_team"]) and Game.getStorageValue(config["red_team"]) <= config["max_players_per_team"] then
player:setStorageValue(config["p_red_team"], 1)
Game.setStorageValue(config["red_team"], Game.getStorageValue(config["red_team"]) + 1)
player:sendTextMessage(4, "You have joined the red team. CTF will start when enough players have joined. Type !leaveCTF to exit the queue")
elseif Game.getStorageValue(config["green_team"]) <= Game.getStorageValue(config["red_team"]) and Game.getStorageValue(config["green_team"]) <= config["max_players_per_team"] then
player:setStorageValue(config["[p_green_team"], 1)
Game.setStorageValue(config["green_team"], Game.getStorageValue(config["green_team"]) + 1)
player:sendTextMessage(4, "You have joined the green team. CTF will start when enough players have joined. Type !leaveCTF to exit the queue")
end
else
return player:sendCancelMessage("CTF is not open.")
end
end
function checkCTF()
if Game.getStorageValue(config["event"]) == 1 then
red_team = Game.getStorageValue(config["red_team"])
green_team = Game.getStorageValue(config["green_team"])
if red_team + green_team >= config["required_players"] then
Game.broadcastMessage("CTF will start in 5 minutes.")
Game.setStorageValue(config["event"], 2)
Game.setStorageValue(config["cycle"], 1)
addEvent(nextStep, 60 * 1000)
end
end
end
function nextStep()
if Game.getStorageValue(config["event"]) == 2 then
red_team = Game.getStorageValue(config["red_team"])
green_team = Game.getStorageValue(config["green_team"])
if red_team + green_team < config["required_players"] then
Game.broadcastMessage("Players have left the CTF event queue. There are not enough players for the event to start.")
Game.setStorageValue(config["event"], 1)
return false
end
if Game.getStorageValue(config["cycle"]) < 5 then
time_left = 5 - Game.getStorageValue(config["cycle"])
Game.broadcastMessage("CTF will start in "..time_left.." minutes.")
Game.setStorageValue(config["cycle"], Game.getStorageValue(config["cycle"]) + 1)
addEvent(nextStep, 60 * 1000)
else
Game.setStorageValue(config["event"], 3)
Game.setStorageValue(config["cycle"], 0)
addEvent(startCTF, 0)
end
end
end
function startCTF()
players = Game.getPlayers()
for i = 1, #players do
player = Player(players[i])
if player:getStorageValue(config["p_red_team"]) == 1 then
player:teleportTo(config["red_team_start_pos"])
player:sendTextMessage(4, "CTF has started.")
elseif player:getStorageValue(config["p_green_team"]) == 1 then
player:teleportTo(config["green_team_start_pos"])
player:sendTextMessage(4, "CTF has started.")
end
end
Game.setStorageValue(config["score_green_team"], 0)
Game.setStorageValue(config["score_red_team"], 0)
if config["end_automatic"] == true then
addEvent(endCTF, config["end_automatically_minutes"] * 60 * 1000)
end
end
function endCTF()
players = Game.getPlayers()
if Game.getStorageValue(config["score_green_team"]) > Game.getStorageValue(config["score_red_team"]) then
for i = 1, #players do
player = Player(players[i])
if player:getStorageValue(config["p_green_team"]) == 1 then
--Add rewards here
player:sendTextMessage(4, "Your team has won!")
end
end
elseif Game.getStorageValue(config["score_green_team"]) < Game.getStorageValue(config["score_red_team"]) then
for i = 1, #players do
player = Player(players[i])
if player:getStorageValue(config["p_red_team"]) == 1 then
--Add rewards here
player:sendTextMessage(4, "Your team has won!")
end
end
Game.broadcastMessage("Red team has won CTF event!")
elseif Game.getStorageValue(config["score_green_team"]) == Game.getStorageValue(config["score_red_team"]) then
for i = 1, #players do
player = Player(players[i])
if player:getStorageValue(config["p_red_team"]) == 1 or player:getStorageValue(config["p_green_team"]) == 1 then
--Add tie rewards here
player:sendTextMessage(4, "There has been a tie!")
end
end
Game.broadcastMessage("The teams have tied playing CTF!")
end
for i = 1, #players do
if player:getStorageValue(config["p_red_team"]) == 1 then
player:setStorageValue(config["p_red_team"], 0)
player:teleportTo(config["temple"])
elseif player:getStorageValue(config["p_green_team"]) == 1 then
player:setStorageValue(config["p_green_team"], 0)
player:teleportTo(config["temple"])
end
end
Game.setStorageValue(config["score_green_team"], 0)
Game.setStorageValue(config["score_red_team"], 0)
Game.setStorageValue(config["event"], 0)
Game.setStorageValue(config["cycle"], 0)
Game.setStorageValue(config["red_team"], 0)
Game.setStorageValue(config["green_team"], 0)
end
data/talkactions/scripts make a file called ctf.lua
Code:
dofile("data/ctf.lua")
function onSay(player, words)
if (words == "!startCTF") then
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end
Game.setStorageValue(config["green_team"], 0)
Game.setStorageValue(config["red_team"], 0)
Game.setStorageValue(config["p_green_team"], 0)
Game.setStorageValue(config["p_red_team"], 0)
Game.setStorageValue(config["score_red_team"], 0)
Game.setStorageValue(config["score_green_team"], 0)
Game.setStorageValue(config["cycle"], 0)
openCTF()
elseif (words == "!joinCTF") then
if player:getStorageValue(config["p_red_team"]) == 1 or player:getStorageValue(config["p_green_team"]) == 1 then
return player:sendCancelMessage("You have already joined the CTF event.")
end
playerJoinTeam(player)
elseif (words == "!leaveCTF") then
if player:getStorageValue(config["p_green_team"]) == 1 then
player:setStorageValue(config["p_green_team"], 0)
Game.setStorageValue(config["green_team"], Game.getStorageValue(config["green_team"]) - 1)
player:sendTextMessage(4, "You have left the event.")
elseif player:getStorageValue(config["p_red_team"]) == 1 then
player:setStorageValue(config["p_red_team"], 0)
Game.setStorageValue(config["red_team"], Game.getStorageValue(config["red_team"]) - 1)
player:sendTextMessage(4, "You have left the event.")
else
player:sendTextMessage(4, "You are not in CTF event.")
end
end
return false
end
talkactions.xml
Code:
<talkaction words="!startCTF" script="ctf.lua" />
<talkaction words="!joinCTF" script="ctf.lua" />
<talkaction words="!leaveCTF" script="ctf.lua" />
data/globalevents/scripts make a file called ctf.lua
Code:
dofile("data/ctf.lua")
function onThink(interval)
if Game.getStorageValue(config["event"]) == 1 then
checkCTF()
end
return true
end
in globalevents.xml
Code:
<globalevent name="CTF" interval="10000" script="ctf.lua" />
Last edited: