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

Guild war request! rep++

quinkan

New Member
Joined
Mar 15, 2009
Messages
125
Reaction score
0
Someone help me with this.. rep++:thumbup:


The best release of ultimate times!!!
GIVE ME REPUTATION PLEASE


Here are!!!:D

Credits: Nahruto

Additional Credits: GeKirAh {To tutorial and release!!!}


Lets go!!! =)

How to Install IT?!!

1.0
Go to TFS Folder and create an LUA File, With a name: "guild_war" {without " "}, TFS Version: 0.3 b3+, and write it with this file!:
Code:
function guildExists(guildId)
	if(type(guildId) ~= 'number') then
		return FALSE, error("luaGuildExists: number expected for 'guildId' (got " .. type(guildId) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `id` = " .. guildId)
	if(res:getID() ~= LUA_ERROR) then
		res:free()
		return TRUE
	end
	
	return FALSE
end

function isGuildInWar(guildId)
	if(guildExists(guildId) == TRUE) then
		return FALSE
	end
	
	return FALSE
end

function getGuildIdByName(name)
	if(type(name) ~= 'string') then
		return FALSE, error("luaGetGuildIdByName: string expected for 'name' (got " .. type(name) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(name))
	if(res:getID() ~= LUA_ERROR) then
		local id = res:getDataInt "id"
		res:free()
		
		return id
	end
	
	return FALSE
end

function getGuildLeaderRank(guildId)
	if(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " .. guildId .. " ORDER BY level DESC LIMIT 1;")
	local leaderId = res:getDataString "name"
	res:free()
	
	return leaderId
end

function getGuildWarId(guildId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaGetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `war_id` FROM `guilds` WHERE `id` = " .. guildId .. ", `war_status` = " .. status)
	if(res:getID() ~= LUA_ERROR) then
		local warId = res:getDataInt "war_id"
		res:free()
	
		return warId
	end
	
	return FALSE
end

function setGuildWarId(guildId, warId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaSetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE or guildExists(warId) == FALSE) then
		return FALSE
	end
	
	local res = db.executeQuery("UPDATE `guilds` SET `war_id` = " .. warId .. ", `war_status` = " .. status .. " WHERE `id` = " .. guildId)
	return TRUE
end

function isInGuildWar(cid, player)
	local guildId = getPlayerGuildId(cid)
	if(guildId ~= FALSE) then
		return FALSE
	end
	
	return FALSE
end


2.0 Go to folder Talkaction, and create an new lua file, name: "GuildWar" and write it:
Code:
dofile("./GuildWar.lua")

function onSay(cid, words, param)
	if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
		local myGuild = getPlayerGuildId(cid)
		if words == "/war-invite" then
			if GuildIsInPEace(myGuild) == true then
				if param ~= "" then
					if guildExist(param) ~= LUA_ERROR then
						local invitedGuild = getGuildId(param)
						if invitedGuild ~= LUA_ERROR then
							if invitedGuild ~= myGuild then
								if GuildIsInPEace(invitedGuild) == true then
									doInviteToWar(myGuild, invitedGuild)
									doBroadcastMessage(BroadCast[1][1] ..getPlayerGuildName(cid).. BroadCast[1][2] ..getGuildNameById(invitedGuild).. BroadCast[1][3], BroadCast_Type)
								else
									doPlayerSendCancel(cid, CancelMessagesWar[6])
								end
							else
								doPlayerSendCancel(cid, CancelMessagesWar[8])
							end
						else
							doPlayerSendCancel(cid, CancelMessagesWar[4])
						end
					else
						doPlayerSendCancel(cid, CancelMessagesWar[4])
					end
				else
					doPlayerSendCancel(cid, CancelMessagesWar[7])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[5])
			end
		elseif words == "/war-accept" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				local enemyGuild = getGuildWarInfo(myGuild).By
				doBroadcastMessage(BroadCast[2][1] ..getPlayerGuildName(cid).. BroadCast[2][2] ..getGuildNameById(enemyGuild).. BroadCast[2][3], BroadCast_Type)
				WarAccept(myGuild, enemyGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])
			end
		elseif words == "/war-reject" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				doBroadcastMessage(BroadCast[3][1] ..getPlayerGuildName(cid).. BroadCast[3][2] ..getGuildNameById(getGuildWarInfo(myGuild).By).. BroadCast[3][3], BroadCast_Type)
				cleanInfo(getGuildWarInfo(myGuild).By)
				cleanInfo(myGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-cancel-invite" then
			if getGuildWarInfo(myGuild).To ~= 0 then
				if getGuildWarInfo(myGuild).With == 0 then
					doBroadcastMessage(BroadCast[4][1] ..getPlayerGuildName(cid).. BroadCast[4][2] ..getGuildNameById(getGuildWarInfo(myGuild).To).. BroadCast[4][3], BroadCast_Type)
					cleanInfo(getGuildWarInfo(myGuild).To)
					cleanInfo(myGuild)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[3])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-challenge" then
			local map = Maps[param]
			if map then
				if getGuildWarInfo(myGuild).With ~= 0 and getGuildWarInfo(myGuild).ON == 0 then
					local enemyGuild = getGuildWarInfo(myGuild).With
					addEvent(StarWar, 15 * 1000, {myGuild = myGuild, enemyGuild = enemyGuild, map = param})
					doBroadcastMessage(BroadCast[5][1] ..getPlayerGuildName(cid).. BroadCast[5][2] ..getGuildNameById(enemyGuild).. BroadCast[5][3] .. param ..".", BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[10])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[9])
			end
		elseif words == "/war-cancel" then
			local enemy = getGuildWarInfo(myGuild).With
			if enemy ~= 0 then
				if (os.time() - getGuildWarInfo(myGuild).T) >= (60 * DelayToCancel) then
					StopWar(myGuild, enemy)
					doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(myGuild).. BroadCast[6][2] ..getGuildNameById(enemy).. BroadCast[6][3], BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[11])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[10])
			end
		end
	else
		doPlayerSendCancel(cid, CancelMessagesWar[2])
	end
	local file = io.open("data/logs/Wars.txt", "a") 
	file:write("".. os.date("%d %B %Y %X ", os.time()) .." -->  "..getCreatureName(cid)..": "..words.." "..param.."\n") 
	file:close() 
	return TRUE
end

3.0 Now go to globalevent folder, and create an new lua file again with the name "wars" and write it with this doccument:
Code:
dofile("./GuildWar.lua")

function onThink(interval, lastExecution)
	for _, id in ipairs(getGuildsWithWar()) do
		local Check = db.getResult("SELECT `name` FROM `guilds` WHERE id = ".. getGuildWarInfo(id).With .."")
		if Check:getID() == LUA_ERROR then
			cleanInfo(id)
		end
	end
	return TRUE
end


4.0 Go to Xampp folder, htdocs and create an new lua file and write it:
Code:
DelayToCancel = 24 * 60 * 60 --minutes

Maps = {
	["map 1"] = 
		{
			Guild1Pos = {x=998, y=1006, z=7},
			Guild2Pos = {x=1002, y=1006, z=7}
		},
	["map 2"] =
		{
			Guild1Pos = {x=994, y=1004, z=6},
			Guild2Pos = {x=1000, y=1003, z=6}			
		}
	}

TimeToTeleport = 1 --minutes, when star a challenge
StopBattle = TRUE --Stop battle after X time ? TRUE  /  FALSE
TimeToStop = 60 --Minutes Time to Stop if StopBattle = TRUE.

--Cancel messages~
CancelMessagesWar = {
	--Message when player try accept/reject/cancel a war but there is no a invitation.
	[1] = "Not pending invitations.",
	--Message when the player is not the guild leader.
	[2] = "Only Guild Leader can execute this command.",
	--Message when try Cancel the invitation but the war is already accepted.
	[3] = "The war is already accepted.",
	--MEssage when the invited guild name is not correct or does not exist.
	[4] = "Not correct guild name.",
	--Message when try invite any guild to a war but his guild already have a war or a pending invitation.
	[5] = "Your guild is already in war or have a pending invitation.",
	--Same of the cancel message 5 but the the enemy guild.
	[6] = "This guild is already in war or have a pending invitation.",
	--Message when use invite command but not write guild name.
	[7] = "Command needs param.",
	--Message when try invite his guild.
	[8] = "You can\´t invite you guild.",
	--Message when the map name is not correct.
	[9] = "Please write a correct name.",
	--Message when try go to any map but the guild is have no received/sent any war invitation
	[10] = "Your guild is not in any war.",
	--When try to cancel a war before the delay
	[11] = "You should wait ".. DelayToCancel .." minutes to cancel the war"
	}
	
--Broadcast messages when invite/accept/reject/cancel ~ Remember the Spaces.
BroadCast_Type = MESSAGE_EVENT_ADVANCE
BroadCast = {
	--Message when inviting
	[1] = 
		{
			"Guild ",
			--Here will be the guild name
			" have invited guild ",
			--Here will be the invited guild name
			" to have a war."
		},
	--Message when accept.
	[2] = 
		{
			"Guild ",
			--Here will be the guild name
			" have accepted the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when reject.
	[3] = 
		{
			"Guild ",
			--Here will be the guild name
			" have rejected the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when cancel.
	[4] = 
		{
			"Guild ",
			--Here will be the guild name
			" have canceled the invitation to the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message whenstar a battle..
	[5] = 
		{
			"Guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" will have a battle in the map :"
		},
	--message when a battle ends.
	[6] = 
		{
			"The battle betwen guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" its over."
		},
	}

--Functions ~.
function getGuildWarInfo(id)
	local Info = db.getResult("SELECT `invited_to`, `invited_by`, `in_war_with`,`war_time` FROM `guilds` WHERE `id` = " .. id .. "")
	if Info:getID() ~= LUA_ERROR then
		local invTo, invBy, warWith, Time = Info:getDataInt("invited_to"), Info:getDataInt("invited_by"), Info:getDataInt("in_war_with"), Info:getDataInt("war_time") 
		Info:free()
		return {To = invTo, By = invBy, With = warWith, T = Time}
	end
 	return LUA_ERROR
end

function getGuildNameById(id)
	local Info = db.getResult("SELECT `name` FROM `guilds` WHERE `id` = " .. id .. "")
		if Info:getID() ~= LUA_ERROR then
		local Name = Info:getDataString("name")
		Info:free()
		return Name
	end
 	return LUA_ERROR
end

function GuildIsInPEace(id)
	local Info = getGuildWarInfo(id)
	return (Info.To == 0 and Info.By == 0 and Info.With == 0)
end

function doInviteToWar(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = ".. enemyGuild .." WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_by` = ".. myGuild .." WHERE `id` = ".. enemyGuild .."")
end

function WarAccept(myGuild, enemyGuild)
	local StartTime = os.time()
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. myGuild ..", `kills` = 0, `show` = 1 WHERE `id` = ".. enemyGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. enemyGuild ..", `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function cleanInfo(myGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = 0, `in_war_with`  =  0, `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function registerDeath(myGuild, enemyGuild, cid, target)
	db.executeQuery("INSERT INTO `deaths_in_wars` (`guild_id`, `player_id`, `killer_guild`, `killer`, `date`) VALUES ("..enemyGuild..", "..getPlayerGUID(target)..", "..myGuild..", "..getPlayerGUID(cid)..", " .. os.time() ..");")	
	db.executeQuery("UPDATE `guilds` SET `kills` = `kills` + 1 WHERE `id` = ".. myGuild .."")
end

function StopWar(myGuild, enemyGuild)
	cleanInfo(myGuild)
	cleanInfo(enemyGuild)
	removeDeaths(myGuild)
	removeDeaths(enemyGuild)
end

function removeDeaths(id)
	db.executeQuery("DELETE FROM `deaths_in_wars` WHERE `guild_id` = " ..id .. ";")
end

function WeAreInWar(myGuild, enemyGuild)
	local myGuildInfo = getGuildWarInfo(myGuild)
	local enemyGuildInfo = getGuildWarInfo(enemyGuild)
	if myGuild == enemyGuildInfo.With and enemyGuild ==  myGuildInfo.With then
		if enemyGuildInfo.ON == 1 and myGuildInfo.ON == 1 then
			return TRUE
		end		
	end
	return FALSE
end

function getOnlineMembers(id)
	local PlayersOnline = getPlayersOnline()
	local MembersOnline = {}
	for i, pid in ipairs(PlayersOnline) do
		if id == getPlayerGuildId(PlayersOnline[i]) then
			table.insert(MembersOnline, PlayersOnline[i])
		end
	end
	return MembersOnline
end

function teleportGuild(id, pos)
	local Members = getOnlineMembers(id)
	if #Members > 0 then
		for i = 1, #Members do
			if getTilePzInfo(getCreaturePosition(Members[i])) == TRUE then
				doTeleportThing(Members[i], pos, FALSE)
				doSendMagicEffect(pos, CONST_ME_TELEPORT)
				doSendMagicEffect(getCreaturePosition(Members[i]), CONST_ME_POFF)
			end
		end
	end
end

function removeFrag(cid)
	local FragTime = getConfigInfo('timeToDecreaseFrags')
	local myFragTime = getPlayerRedSkullTicks(cid)
	local Remo = (myFragTime - FragTime)
	if Remo < 0 then
		Remo = 0
	end
	doPlayerSetRedSkullTicks(cid, Remo)
end

function getGuildsWithWar()
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `in_war_with` > 0")
	local GuildW = {}
	if res:getID() ~= LUA_ERROR then
		while true do
			table.insert(GuildW, res:getDataInt "id")
			if not res:next() then
				break
			end
		end
		res:free()
	end
	return GuildW
end

function guildExist(nom)
	local Get = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(nom) .. ";")
	if Get:getID() ~= LUA_ERROR then
		local ret = Get:getDataInt("id")
		Get:free()
		return ret
	end
 	return LUA_ERROR
end

function StarWar(x)
	teleportGuild(x.myGuild, Maps[x.map].Guild1Pos)
	teleportGuild(x.enemyGuild, Maps[x.map].Guild2Pos)
--[[	
	putWarOn(x.myGuild, x.enemyGuild)
	if StopBattle == TRUE then
		addEvent(StopWarNow, 60 * 1000, {myGuild = x.myGuild, enemyGuild = x.enemyGuild})
	end
]]
end	

--[[
function StopWarNow(c)
	StopWar(c.myGuild, c.enemyGuild)
	doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(c.myGuild).. BroadCast[6][2] ..getGuildNameById(c.enemyGuild).. BroadCast[6][3], BroadCast_Type)
end

function putWarOn(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. enemyGuild .."")
end
]]

5.0 Now ended all LUA FILES, Lets edit the XML Files, go to globalevent.xml and write it:
Code:
<globalevent name="wars" interval="1800" script="wars.lua"/> <!--1800 is 30 minutes-->

6.0 go to talkaction folder, open talkactions.xml and write it:
Code:
<talkaction words="/war-invite" script="GuildWar.lua" />	
	<talkaction words="/war-accept" script="GuildWar.lua" />	
	<talkaction words="/war-reject" script="GuildWar.lua" />
	<talkaction words="/war-cancel" script="GuildWar.lua" />	
	<talkaction words="/war-challenge" script="GuildWar.lua" />	
	<talkaction words="/war-cancel-invite" script="GuildWar.lua" />


Do you dont know how to open XML Files?
Click with right mause button and go with -> edit and open it with one text archive {I like WordPad}


NOW ALL READY!!! CONGRATULATIONS!!! NICE WAR SCRIPT WORKING!!!

Nice wars with your server!!!

Please Reputation 4me

Can anyone help me now with new PROMOTION Working? for it work need to configure all others thigs, spells~weapws {Wands, rods etc}, potions all!!! and need one new npc to sell it, Already maked an post with it can someone help me now? :S
Thanks a loot!!!


GOOD BYE ;DDDD

Hail OT-Land \o

EDITING:
Comands About War script:

/war-invite: To give an invitation for war!!!
/war-reject: To Reject invatation for war!!!
/war-cancel: To end war!!!
/war-challenge: To challenge war!!!
/war-cancel-invite: To cancel Invitaiton!!!
/war-accept: To accept guild war!!! :D

OTHER SCRIPT:
With this advanced script you can be have infinites vs infinites guilds in war!
Only guild war without TUTORIAL!
Code:
DelayToLeave = 12 * 60 * 60

BroadCast_Type = MESSAGE_EVENT_ADVANCE

Need_rank = GUILDLEVEL_LEADER

--Functions ~.
function WarInfo(guild)
	local Info = db.getResult("SELECT * FROM `guilds` WHERE `id` = " .. guild .. ";")
	if Info:getID() ~= LUA_ERROR then
		local inWar, inTeam, invitedTo, JoinDate = Info:getDataInt("war"), Info:getDataInt("team"), Info:getDataInt("invited_to_war"), Info:getDataInt("join_date")
		Info:free()
		return {War = inWar, Team = inTeam, Inv = invitedTo, Joined = JoinDate}
	end
 	return LUA_ERROR
end

function getGuildNameById(guild)
	local Info = db.getResult("SELECT * FROM `guilds` WHERE `id` = " .. guild .. ";")
		if Info:getID() ~= LUA_ERROR then
		local Name = Info:getDataString("name")
		Info:free()
		return Name
	end
 	return LUA_ERROR
end

function getGuildIdByName(name)
	local Get = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(name) .. ";")
	if Get:getID() ~= LUA_ERROR then
		local ret = Get:getDataInt("id")
		Get:free()
		return ret
	end
 	return LUA_ERROR
end

function IsInPeace(guild)
	local Info = WarInfo(guild)
	return (Info.War == 0 and Info.Team == 0 and Info.Inv == 0)
end

function cleanInfo(guild)
	db.executeQuery("UPDATE `guilds` SET `war` = 0, `team` = 0, `invited_to_war` = 0, join_date = 0 WHERE `id` = ".. guild ..";")
end

function createWar()
	db.executeQuery("INSERT INTO `wars` (`date`, `status`, `team_one_kills`, `team_two_kills`, `end_date`) VALUES (" .. os.time() .. ", 1, 0, 0, 0);")
	local This = db.getResult("SELECT * FROM `wars` ORDER BY `id` DESC LIMIT 1;")
	return This:getDataInt("id")
end

function inviteToWar(Guild, War, Team)
	db.executeQuery("UPDATE `guilds` SET `team` = " .. Team ..", `invited_to_war` = " .. War .. " WHERE `id` = ".. Guild ..";")
end

function updateWarInfo(Guild, warId, team)
	db.executeQuery("UPDATE `guilds` SET `war` = " .. warId .. ", `team` = " .. team .. ", `invited_to_war` = 0, join_date = " .. os.time() .. " WHERE `id` = ".. Guild ..";")
end

function leaveWar(Guild)
	if checkGuildsInThisWar(WarInfo(Guild).War) == 1 then
		db.executeQuery("UPDATE `wars` SET `status` = 0, `end_date` = " .. os.time() .. " WHERE `id` = ".. WarInfo(Guild).War ..";")
	end
	cleanInfo(Guild)
end

function removeFrag(cid)
	local FragTime = getConfigInfo('timeToDecreaseFrags')
	local myFragTime = getPlayerRedSkullTicks(cid)
	local Remo = (myFragTime - FragTime)
	if Remo < 0 then
		Remo = 0
	end
	doPlayerSetRedSkullTicks(cid, Remo)
end

function checkGuildsInThisWar(war)
	local res = db.getResult("SELECT * FROM `guilds` WHERE `war` = " .. war .. ";")
	local Guilds = {}
	if res:getID() ~= LUA_ERROR then
		while true do
			table.insert(Guilds, res:getDataInt "id")
			if not res:next() then
				break
			end
		end
		res:free()
	end
	return #Guilds
end

Code:
<?PHP
$MaxShow_of_frags = 20;

if($action == '')
{
$wars = $SQL->query("SELECT * FROM wars WHERE status = 1 ORDER BY date DESC;");

foreach ($wars as $k=>$v) 
{
	$guilds_one = "";
	$guilds_two = "";
	
	$team_one = $SQL->query("SELECT * FROM guilds WHERE war = ". $v[id] ."  AND team = 1;");
	$team_one_tot = 0;
	foreach ($team_one as $guild)
	{
		$team_one_tot++;
		$guilds_one .= "<a href='index.php?subtopic=guilds&action=show&guild=" . $guild[name] . "'>$guild[name]</a><br>"; 
	}
	$team_two = $SQL->query("SELECT * FROM guilds WHERE war = ". $v[id] ."  AND team = 2;");
	$team_two_tot = 0;
	foreach ($team_two as $guild)
	{
		$team_two_tot++;
		$guilds_two .= "<a href='index.php?subtopic=guilds&action=show&guild=" . $guild[name] . "'>$guild[name]</a><br>"; 
	}
		$stats .="
			<TR BGCOLOR=\"".$config['site'][($k % 2 == 1 ? 'light' : 'dark').'border']."\">
				<TD>
					<center>
						".(!$guilds_one ? "-/-" :"$guilds_one")."
					</center>
				</TD>
				<TD>
					<center>
						".(!$guilds_two ? "-/-" :"$guilds_two")."
					</center>
				</TD>
				<TD>
					<center>
						".($v[status] == 1 ? "<font color='green'><b>Active</b></font><br>Since " . date("d/m/y   H:i:s", $v[date]) . "" : "<font color='red'><b>Ended</b></font><br>At " . date("d/m/y   H:i:s", $v[end_date]) . "")."
					</center>
				</TD>
				<TD>
					<center>
						<b>
							" . $v[team_one_kills] . " / " . $v[team_two_kills] . "
						</b>
					</center>
				</TD>
				<TD>
					<center>
						<a href='index.php?subtopic=new_wars&action=show&war=" . $v[id] . "'>View</a>
					</center>
				</TD>
			</TR>
	";
}
$main_content .= '
	<center>
		<h1>
			Wars
		</h1>
	</center>
';
if(!$stats) {
	$main_content .= '
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
			<TR BGCOLOR="'.$config['site']['vdarkborder'].'">
				<TD CLASS=white>
					Status
				</TD>
			</TR>
			<TR BGCOLOR='.$config['site']['darkborder'].'>
				<TD>
					There are no wars in '.$config['server']['serverName'].' yet.
				</TD>
			</TR>
		</TABLE>
	';
} else {
	$main_content .= "
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
			<TR BGCOLOR=\"{$config['site']['vdarkborder']}\">
				<TD CLASS=white width=25%>
					<center>
						<B>
							Team One
						</B>
					</center>
				</TD>
				<TD CLASS=white width=25%>
					<center>
						<B>
							Team Two
						</B>
					</center>
				</TD>
				<TD CLASS=white width=25%>
					<center>
						<B>
							Status
						</B>
					</center>
				</TD>
				<TD CLASS=white width=15%>
					<center>
						<B>
							Scores
						</B>
					</center>
				</TD>
				<TD CLASS=white width=10%>
					<center>
						<B>
							View
						</B>
					</center>
				</TD>
			</TR>
			$stats
		</TABLE>
	";	
	}
}
if($action == 'show')
{
	$war_id = $_REQUEST['war'];
	
	$war = $SQL->query("SELECT * FROM wars WHERE id = ". $war_id ." LIMIT 1;");

	foreach ($war as $v)
	{
		$team_one = $SQL->query("SELECT * FROM guilds WHERE war = ". $v[id] ."  AND team = 1;");
		
		$team_one_tot = 0;
		
		foreach ($team_one as $guild)
		{
			$team_one_tot++;
			//Show guilds in team one.
			$guilds_one .= "<a href='index.php?subtopic=guilds&action=show&guild=" . $guild[name] . "'>$guild[name]</a> "; 
		}
		$team_two = $SQL->query("SELECT * FROM guilds WHERE war = ". $v[id] ."  AND team = 2;");
		
		$team_two_tot = 0;
		
		foreach ($team_two as $guild)
		{
			$team_two_tot++;
			//Show guilds in team two.
			$guilds_two .= "<a href='index.php?subtopic=guilds&action=show&guild=" . $guild[name] . "'>$guild[name]</a> "; 
		}
		
		//Get top fragger in team one.
		$Top_fragger_one = $SQL->query("
			SELECT 
				killer, COUNT(killer) maximo
			FROM 
				war_deaths
			WHERE 
				war_id = ". $war_id ."
			AND
				team = 1
			GROUP BY 
				killer
			ORDER BY 
				maximo 
			DESC LIMIT 1;
		");
		
		foreach ($Top_fragger_one as $x) 
		{
			$plyr = $ots->createObject('Player');
			$plyr->load($x[killer]);
			$Top_Fragger_one = $plyr->getName();
			$top_one_rank = $plyr->getRankId();
			$num_Top_one = $x[maximo];
		}
		
		if($top_one_rank)
		{
			//Get the guild of the top fragger one ~
			$ranks_one = $SQL->query("
			SELECT 
				g.name AS name
			FROM 
				guilds AS g
			INNER JOIN 
				guild_ranks AS gr
			ON
				gr.guild_id = g.id
			WHERE
				gr.id = " . $top_one_rank . "
			LIMIT 1
			");
			
			foreach ($ranks_one as $r_one) 
			{
				$g_name_top_one = $r_one[name];
			}
		}
		
		//Get top fragger in team two.
		$Top_fragger_two = $SQL->query("
			SELECT 
				killer, COUNT(killer) maximo
			FROM 
				war_deaths
			WHERE 
				war_id = ". $war_id ."
			AND
				team = 2
			GROUP BY 
				killer
			ORDER BY 
				maximo 
			DESC LIMIT 1;
		");
	
		foreach ($Top_fragger_two as $x) 
		{
			$plyr = $ots->createObject('Player');
			$plyr->load($x[killer]);
			$Top_Fragger_two = $plyr->getName();
			$top_two_rank = $plyr->getRankId();
			$num_Top_two = $x[maximo];
		}
		
		if($top_two_rank)
		{
			//Get the guild of the top fragger two~
			$ranks_two = $SQL->query("
			SELECT 
				g.name AS name
			FROM 
				guilds AS g
			INNER JOIN 
				guild_ranks AS gr
			ON
				gr.guild_id = g.id
			WHERE
				gr.id = " . $top_two_rank . "
			LIMIT 1
			");
			
			foreach ($ranks_two as $r_two) 
			{
				$g_name_top_two = $r_two[name];
			}
		}
		
		//Get most dead in team one.
		$most_d_one = $SQL->query("
			SELECT 
				target, COUNT(target) maximo
			FROM 
				war_deaths
			WHERE 
				war_id = ". $war_id ."
			AND
				team = 2
			GROUP BY 
				target
			ORDER BY 
				maximo 
			DESC LIMIT 1;
		");
	
		foreach ($most_d_one as $x) 
		{
			$plyr = $ots->createObject('Player');
			$plyr->load($x[target]);
			$Most_d_one = $plyr->getName();
			$most_one_rank = $plyr->getRankId();
			$num_most_one = $x[maximo];
		}
		
		if($most_one_rank)
		{
			//Get the guild of the most dead one ~
			$ranks_one = $SQL->query("
			SELECT 
				g.name AS name
			FROM 
				guilds AS g
			INNER JOIN 
				guild_ranks AS gr
			ON
				gr.guild_id = g.id
			WHERE
				gr.id = " . $most_one_rank . "
			LIMIT 1
			");
			
			foreach ($ranks_one as $r_one) 
			{
				$most_one_g = $r_one[name];
			}
		}
		
		//Get most dead in team two.
		$most_d_two = $SQL->query("
			SELECT 
				target, COUNT(target) maximo
			FROM 
				war_deaths
			WHERE 
				war_id = ". $war_id ."
			AND
				team = 1
			GROUP BY 
				target
			ORDER BY 
				maximo 
			DESC LIMIT 1;
		");
	
		foreach ($most_d_two as $x) 
		{
			$plyr = $ots->createObject('Player');
			$plyr->load($x[target]);
			$Most_d_two = $plyr->getName();
			$most_two_rank = $plyr->getRankId();
			$num_most_two = $x[maximo];
		}
		
		if($most_two_rank)
		{
			//Get the guild of the most dead one ~
			$ranks_two = $SQL->query("
			SELECT 
				g.name AS name
			FROM 
				guilds AS g
			INNER JOIN 
				guild_ranks AS gr
			ON
				gr.guild_id = g.id
			WHERE
				gr.id = " . $most_two_rank . "
			LIMIT 1
			");
			
			foreach ($ranks_two as $r_two) 
			{
				$most_two_g = $r_two[name];
			}
		}
		
		
		//Get number of deaths of every member.(team one)
		$team_one_guilds = $SQL->query("SELECT * FROM guilds WHERE war = ". $war_id ." AND team = 1;");
		foreach ($team_one_guilds as $t_one)
		{
			$ranks = $SQL->query("SELECT * FROM guild_ranks WHERE guild_id = ". $t_one[id] .";");
			foreach ($ranks as $y)
			{
				$Players = $SQL->query("SELECT * FROM players WHERE rank_id = ". $y[id] ." ORDER BY name DESC;");
				foreach ($Players as $k=>$x)
				{
					$totDeaths = 0;
					$deaths = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND target = ". $x[id] .";");
					foreach ($deaths as $s) {$totDeaths++;}				
					
					$totKills = 0;
					$Kills = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND killer = ". $x[id] .";");
					foreach ($Kills as $s) {$totKills++;}		
					
					$membersDeaths .="
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $x[name] . "'>$x[name]</a> - <a href='index.php?subtopic=guilds&action=show&guild=" . $t_one[name] . "'>$t_one[name]</a> $totDeaths / $totKills
							</b>
						</center>			
					";
				}
			}
		}
		//Get number of deaths of every member.(team two)
		$team_two_guilds = $SQL->query("SELECT * FROM guilds WHERE war = ". $war_id ." AND team = 2;");
		foreach ($team_two_guilds as $t_two)
		{
			$ranks = $SQL->query("SELECT * FROM guild_ranks WHERE guild_id = ". $t_two[id] .";");
			foreach ($ranks as $y)
			{
				$Players = $SQL->query("SELECT * FROM players WHERE rank_id = ". $y[id] ." ORDER BY name DESC;");
				foreach ($Players as $k=>$x)
				{
					$totDeaths = 0;
					$deaths = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND target = ". $x[id] .";");
					foreach ($deaths as $s) {$totDeaths++;}

					$totKills = 0;
					$Kills = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND killer = ". $x[id] .";");
					foreach ($Kills as $s) {$totKills++;}	
					
					$membersDeaths_two .="
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $x[name] . "'>$x[name]</a> - <a href='index.php?subtopic=guilds&action=show&guild=" . $t_two[name] . "'>$t_two[name]</a> $totDeaths / $totKills
							</b>
						</center>		
			
				";
				}
			}
		}
		//Latest frags (team one)
		$deaths_team_one = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND team = 1 ORDER BY date DESC LIMIT ". $MaxShow_of_frags .";");
		
		foreach ($deaths_team_one as $k=>$t) 
		{
			$target = $ots->createObject('Player');
			$target->load($t[target]);
			$targetName = $target->getName();
			$targetLevel = $target->getLevel();

			$killer = $ots->createObject('Player');
			$killer->load($t[killer]);
			$killerName = $killer->getName();
			$killerLevel = $killer->getLevel();
			
			$target_g = $ots->createObject('Guild');
			$target_g->load($t[t_guild]);
			$target_g_Name = $target_g->getName();
			
			$killer_g = $ots->createObject('Guild');
			$killer_g->load($t[k_guild]);
			$killer_g_Name = $killer_g->getName();
			
			$last_kills_one .="
				<TR BGCOLOR=\"".$config['site'][($k % 2 == 1 ? 'light' : 'dark').'border']."\">
					<TD>
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $targetName . "'>$targetName</a> [$targetLevel] - <a href='index.php?subtopic=guilds&action=show&guild=" . $target_g_Name . "'>$target_g_Name</a>
							</b>
						</center>
					</TD>
					<TD>
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $killerName . "'>$killerName</a> [$killerLevel] - <a href='index.php?subtopic=guilds&action=show&guild=" . $killer_g_Name . "'>$killer_g_Name</a>
							</b>
						</center>
					</TD>
					<TD>
						<center>
							<b>
								" . date("d/m/y   H:i:s", $t[date]) . "
							</b>
						</center>
					</TD>
				</TR>
			";
		}
		//Latest frags (team two)
		$deaths_team_one = $SQL->query("SELECT * FROM war_deaths WHERE war_id = ". $war_id ." AND team = 2 ORDER BY date DESC LIMIT ". $MaxShow_of_frags .";");
		
		foreach ($deaths_team_one as $k=>$t) 
		{
			$target = $ots->createObject('Player');
			$target->load($t[target]);
			$targetName = $target->getName();
			$targetLevel = $target->getLevel();

			$killer = $ots->createObject('Player');
			$killer->load($t[killer]);
			$killerName = $killer->getName();
			$killerLevel = $killer->getLevel();
			
			$target_g = $ots->createObject('Guild');
			$target_g->load($t[t_guild]);
			$target_g_Name = $target_g->getName();
			
			$killer_g = $ots->createObject('Guild');
			$killer_g->load($t[k_guild]);
			$killer_g_Name = $killer_g->getName();
			
			$last_kills_two .="
				<TR BGCOLOR=\"".$config['site'][($k % 2 == 1 ? 'light' : 'dark').'border']."\">
					<TD>
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $targetName . "'>$targetName</a> [$targetLevel] - <a href='index.php?subtopic=guilds&action=show&guild=" . $target_g_Name . "'>$target_g_Name</a>
							</b>
						</center>
					</TD>
					<TD>
						<center>
							<b>
								<a href='index.php?subtopic=characters&name=" . $killerName . "'>$killerName</a> [$killerLevel] - <a href='index.php?subtopic=guilds&action=show&guild=" . $killer_g_Name . "'>$killer_g_Name</a>
							</b>
						</center>
					</TD>
					<TD>
						<center>
							<b>
								" . date("d/m/y   H:i:s", $t[date]) . "
							</b>
						</center>
					</TD>
				</TR>
			";
		}
		
		//Get invited guilds
		$invited = $SQL->query("SELECT * FROM guilds WHERE invited_to_war = ". $war_id .";");
		
		foreach ($invited as $k=>$t)
		{
			$invi .="
				<TR BGCOLOR=\"".$config['site'][($k % 2 == 1 ? 'light' : 'dark').'border']."\">
					<TD>
						<center>
							<b>
								<a href='index.php?subtopic=guilds&action=show&guild=" . $t[name] . "'>$t[name]</a>
							</b>
						</center>
					</TD>
					<TD>
						<center><b>Team $t[team]</b></center>
					</TD>
				</TR>
			";			
		}
		
		
		//Get the title and basic info.
		$title = "$guilds_one($team_one_tot) v/s ".($guilds_two ? "$guilds_two($team_two_tot)" : "~~~~")."";
		
		$info = "
		".($v[status] == 1 ? "<font color='green'><b>Active</b></font><br>Since " . date("d/m/y   H:i:s", $v[date]) . "" : "<font color='red'><b>Ended</b></font><br>At " . date("d/m/y   H:i:s", $v[end_date]) . "")."
		<br>
		<br>
		Frags by team one = " . $v[team_one_kills] . "
		<br>
		<br>
		Frags by team two = " . $v[team_two_kills] . "
		<br>
		<br>
		Top fragger of team one = ".(!$Top_Fragger_one ? "-/-" : "<a href='index.php?subtopic=characters&name=" . $Top_Fragger_one ."'>$Top_Fragger_one</a> of <a href='index.php?subtopic=guilds&action=show&guild=" . $g_name_top_one . "'>$g_name_top_one</a> ($num_Top_one)")."
		<br>
		<br>
		Top fragger of team two = ".(!$Top_Fragger_two ? "-/-" : "<a href='index.php?subtopic=characters&name=" . $Top_Fragger_two . "'>$Top_Fragger_two</a> of <a href='index.php?subtopic=guilds&action=show&guild=" . $g_name_top_two . "'>$g_name_top_two</a> ($num_Top_two)")."
		<br>
		<br>
		The most one killed of team one = ".(!$Most_d_one ? "-/-" : "<a href='index.php?subtopic=characters&name=" . $Most_d_one . "'>$Most_d_one</a> of <a href='index.php?subtopic=guilds&action=show&guild=" . $most_one_g . "'>$most_one_g</a> ($num_most_one)")."
		<br>
		<br>
		The most one killed of team two = ".(!$Most_d_two ? "-/-" : "<a href='index.php?subtopic=characters&name=" . $Most_d_two . "'>$Most_d_two</a> of <a href='index.php?subtopic=guilds&action=show&guild=" . $most_two_g . "'>$most_two_g</a> ($num_most_two)")."
		";
	}
	
	//Start the show off work.
	$main_content .= "<center><h2>$title</h2></center><br><br>";
	
	$main_content .= "<center><b>$info</b></center><br><br>";
	
	$main_content .= "
		<center><h3>Members Deaths</h3></center>
		
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 WIDTH=100%>
			<TR BGCOLOR=\"{$config['site']['vdarkborder']}\">
				<TD CLASS=white width=50%>
					<center><b>Team one deaths/kills</b></center>
				</TD>
				<TD CLASS=white width=50%>
					<center><b>Team two deaths/kills</b></center>
				</TD>
			</TR>
			<TR BGCOLOR=\"".$config['site']['darkborder']."\">
				<TD>
					".($membersDeaths ? "$membersDeaths" : "~~")."
				</TD>
				<TD>
					".($membersDeaths_two ? "$membersDeaths_two" : "<center>-/-</center>")."
				</TD>
			</TR>
		</TABLE>
		<br>
		<br>
		";

	$main_content .= "
		<center><h3>Latest frags by Team one</h3></center>
		
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=100%>
			<TR BGCOLOR=\"{$config['site']['vdarkborder']}\">
				<TD CLASS=white width=35%>
					<center>
						<B>
							Player
						</B>
					</center>
				</TD>
				<TD CLASS=white width=35%>
					<center>
						<B>
							Killed by
						</B>
					</center>
				</TD>
				<TD CLASS=white width=30%>
					<center>
						<B>
							Date
						</B>
					</center>
				</TD>
			</TR>
			".(!$last_kills_one ? "<TR BGCOLOR=\"{$config['site']['darkborder']}\"><TD><center>-/-</center></TD><TD><center>-/-</center></TD><TD><center>-/-</center></TD></TR>" : "$last_kills_one")." 
		</TABLE>
		<br>
		<br>
		";
		
		$main_content .= "
		<center><h3>Latest frags by Team two</h3></center>
		
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=100%>
			<TR BGCOLOR=\"{$config['site']['vdarkborder']}\">
				<TD CLASS=white width=35%>
					<center>
						<B>
							Player
						</B>
					</center>
				</TD>
				<TD CLASS=white width=35%>
					<center>
						<B>
							Killed by
						</B>
					</center>
				</TD>
				<TD CLASS=white width=30%>
					<center>
						<B>
							Date
						</B>
					</center>
				</TD>
			</TR>
			".(!$last_kills_two ? "<TR BGCOLOR=\"{$config['site']['darkborder']}\"><TD><center>-/-</center></TD><TD><center>-/-</center></TD><TD><center>-/-</center></TD></TR>" : "$last_kills_two")." 
		</TABLE>
		<br>
		<br>
		";
		
		$main_content .= "
		<center><h3>Invited guilds</h3></center>
		
		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=100%>
			<TR BGCOLOR=\"{$config['site']['vdarkborder']}\">
				<TD CLASS=white width=35%>
					<center>
						<B>
							Guild
						</B>
					</center>
				</TD>
				<TD CLASS=white width=35%>
					<center>
						<B>
							Inivted to team
						</B>
					</center>
				</TD>
			</TR>
			".(!$invi ? "<TR BGCOLOR=\"{$config['site']['darkborder']}\"><TD><center>-/-</center></TD><TD><center>-/-</center></TD></TR>" : "$invi")." 
		</TABLE>
		";
		
	$main_content .= "<br><br><br><br><center><a href='index.php?subtopic=new_wars'><h1>Back</h1></a></center>";
}
?>
Code:
dofile("./Wars.lua")

function onSay(cid, words, param)
	local myGuild = getPlayerGuildId(cid)
	if myGuild ~= 0 then
		local myInfo = WarInfo(myGuild)
		if getPlayerGuildLevel(cid) >= Need_rank then
			if words == "/create-war" then
				if IsInPeace(myGuild) == true then
					local newWar = createWar()
					updateWarInfo(myGuild, newWar, 1)
					doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has started a new war.", BroadCast_Type)
				else
					doPlayerSendCancel(cid, "Your guild is already in a war or have a pending invitation.")
				end
			elseif words == "/leave-war" then
				if myInfo.War ~= 0 then
					if (os.time() - myInfo.Joined) >= (DelayToLeave) then
						leaveWar(myGuild)
						doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has left the war.", BroadCast_Type)
					else
						doPlayerSendCancel(cid, "You would wait " .. ((DelayToLeave/60)/60) .. " Hours to leave the war.")
					end
				else
					doPlayerSendCancel(cid, "Your guild is not in any war.")
				end
			elseif words == "/reject-war" then
				if myInfo.Inv ~= 0 then
					cleanInfo(myGuild)
					doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has reject the initatio to join the war.", BroadCast_Type)
				else
					doPlayerSendCancel(cid, "Your guild does not have any pending invitation.")
				end
			elseif words == "/join-war" then
				if myInfo.Inv ~= 0 then
					updateWarInfo(myGuild, myInfo.Inv, myInfo.Team)
					doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has accepted the initation to join the team " .. myInfo.Team .. " of the war.", BroadCast_Type)
				else
					doPlayerSendCancel(cid, "Your guild does not have any pending invitation.")
				end
			elseif words == "/invite-enemy" then
				if myInfo.War ~= 0 then
					if param ~= "" then
						local enemyGuild = getGuildIdByName(param)
						if enemyGuild ~= LUA_ERROR then
							if IsInPeace(enemyGuild) == true then
								inviteToWar(enemyGuild, myInfo.War, (myInfo.Team == 1 and 2 or 1))
								doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has invited " .. getGuildNameById(enemyGuild) .. " to join their war as enemy.", BroadCast_Type)
							else
								doPlayerSendCancel(cid, "This guild is already in a war or have a pending invitation.")
							end
						else
							doPlayerSendCancel(cid, "Write a correct guild name.")
						end
					else
						doPlayerSendCancel(cid, "Write the name of the guild.")
					end
				else
					doPlayerSendCancel(cid, "Your guild is not in any war.")
				end
			elseif words == "/invite-ally" then
				if myInfo.War ~= 0 then
					if param ~= "" then
						local enemyGuild = getGuildIdByName(param)
						if enemyGuild ~= LUA_ERROR then
							if IsInPeace(enemyGuild) == true then
								inviteToWar(enemyGuild, myInfo.War, myInfo.Team)
								doBroadcastMessage(getCreatureName(cid).." leader of "..getGuildNameById(myGuild).." has invited " .. getGuildNameById(enemyGuild) .. " to join their war as ally.", BroadCast_Type)
							else
								doPlayerSendCancel(cid, "This guild is already in a war or have a pending invitation.")
							end
						else
							doPlayerSendCancel(cid, "Write a correct guild name.")
						end
					else
						doPlayerSendCancel(cid, "Write the name of the guild.")
					end
				else
					doPlayerSendCancel(cid, "Your guild is not in any war.")
				end
			end
		else
			doPlayerSendCancel(cid, "You can\'t execute this command.")
		end
	else
		doPlayerSendCancel(cid, "You can\'t execute this command.")
	end
	return TRUE
end

Its all there!!! REP++ FOR ME!!! PLEASE!!!
~ REP ++ PLEASE!!! ~
 
I was the first to invent this idea ... out of a game called Metin2.
I should earn at least a little credit for this idea to share with you the Tibia.

The Nahruto only created the scripts, but the idea was mine.
 
In the tfs folder (where is located config.lua) create a filde called GuildWard.lua and add this:

Code:
function guildExists(guildId)
	if(type(guildId) ~= 'number') then
		return FALSE, error("luaGuildExists: number expected for 'guildId' (got " .. type(guildId) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `id` = " .. guildId)
	if(res:getID() ~= LUA_ERROR) then
		res:free()
		return TRUE
	end
	
	return FALSE
end

function isGuildInWar(guildId)
	if(guildExists(guildId) == TRUE) then
		return FALSE
	end
	
	return FALSE
end

function getGuildIdByName(name)
	if(type(name) ~= 'string') then
		return FALSE, error("luaGetGuildIdByName: string expected for 'name' (got " .. type(name) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(name))
	if(res:getID() ~= LUA_ERROR) then
		local id = res:getDataInt "id"
		res:free()
		
		return id
	end
	
	return FALSE
end

function getGuildLeaderRank(guildId)
	if(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " .. guildId .. " ORDER BY level DESC LIMIT 1;")
	local leaderId = res:getDataString "name"
	res:free()
	
	return leaderId
end

function getGuildWarId(guildId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaGetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `war_id` FROM `guilds` WHERE `id` = " .. guildId .. ", `war_status` = " .. status)
	if(res:getID() ~= LUA_ERROR) then
		local warId = res:getDataInt "war_id"
		res:free()
	
		return warId
	end
	
	return FALSE
end

function setGuildWarId(guildId, warId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaSetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE or guildExists(warId) == FALSE) then
		return FALSE
	end
	
	local res = db.executeQuery("UPDATE `guilds` SET `war_id` = " .. warId .. ", `war_status` = " .. status .. " WHERE `id` = " .. guildId)
	return TRUE
end

function isInGuildWar(cid, player)
	local guildId = getPlayerGuildId(cid)
	if(guildId ~= FALSE) then
		return FALSE
	end
	
	return FALSE
end

Now go to talkactions/scripts and create a file called GuildWar.lua and add:

Code:
dofile("./GuildWar.lua")

function onSay(cid, words, param)
	if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
		local myGuild = getPlayerGuildId(cid)
		if words == "/war-invite" then
			if GuildIsInPEace(myGuild) == true then
				if param ~= "" then
					if guildExist(param) ~= LUA_ERROR then
						local invitedGuild = getGuildId(param)
						if invitedGuild ~= LUA_ERROR then
							if invitedGuild ~= myGuild then
								if GuildIsInPEace(invitedGuild) == true then
									doInviteToWar(myGuild, invitedGuild)
									doBroadcastMessage(BroadCast[1][1] ..getPlayerGuildName(cid).. BroadCast[1][2] ..getGuildNameById(invitedGuild).. BroadCast[1][3], BroadCast_Type)
								else
									doPlayerSendCancel(cid, CancelMessagesWar[6])
								end
							else
								doPlayerSendCancel(cid, CancelMessagesWar[8])
							end
						else
							doPlayerSendCancel(cid, CancelMessagesWar[4])
						end
					else
						doPlayerSendCancel(cid, CancelMessagesWar[4])
					end
				else
					doPlayerSendCancel(cid, CancelMessagesWar[7])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[5])
			end
		elseif words == "/war-accept" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				local enemyGuild = getGuildWarInfo(myGuild).By
				doBroadcastMessage(BroadCast[2][1] ..getPlayerGuildName(cid).. BroadCast[2][2] ..getGuildNameById(enemyGuild).. BroadCast[2][3], BroadCast_Type)
				WarAccept(myGuild, enemyGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])
			end
		elseif words == "/war-reject" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				doBroadcastMessage(BroadCast[3][1] ..getPlayerGuildName(cid).. BroadCast[3][2] ..getGuildNameById(getGuildWarInfo(myGuild).By).. BroadCast[3][3], BroadCast_Type)
				cleanInfo(getGuildWarInfo(myGuild).By)
				cleanInfo(myGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-cancel-invite" then
			if getGuildWarInfo(myGuild).To ~= 0 then
				if getGuildWarInfo(myGuild).With == 0 then
					doBroadcastMessage(BroadCast[4][1] ..getPlayerGuildName(cid).. BroadCast[4][2] ..getGuildNameById(getGuildWarInfo(myGuild).To).. BroadCast[4][3], BroadCast_Type)
					cleanInfo(getGuildWarInfo(myGuild).To)
					cleanInfo(myGuild)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[3])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-challenge" then
			local map = Maps[param]
			if map then
				if getGuildWarInfo(myGuild).With ~= 0 and getGuildWarInfo(myGuild).ON == 0 then
					local enemyGuild = getGuildWarInfo(myGuild).With
					addEvent(StarWar, 15 * 1000, {myGuild = myGuild, enemyGuild = enemyGuild, map = param})
					doBroadcastMessage(BroadCast[5][1] ..getPlayerGuildName(cid).. BroadCast[5][2] ..getGuildNameById(enemyGuild).. BroadCast[5][3] .. param ..".", BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[10])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[9])
			end
		elseif words == "/war-cancel" then
			local enemy = getGuildWarInfo(myGuild).With
			if enemy ~= 0 then
				if (os.time() - getGuildWarInfo(myGuild).T) >= (60 * DelayToCancel) then
					StopWar(myGuild, enemy)
					doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(myGuild).. BroadCast[6][2] ..getGuildNameById(enemy).. BroadCast[6][3], BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[11])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[10])
			end
		end
	else
		doPlayerSendCancel(cid, CancelMessagesWar[2])
	end
	local file = io.open("data/logs/Wars.txt", "a") 
	file:write("".. os.date("%d %B %Y %X ", os.time()) .." -->  "..getCreatureName(cid)..": "..words.." "..param.."\n") 
	file:close() 
	return TRUE
end

Later, go to talkactions.xml and add this:

Code:
<talkaction words="/war-invite" script="GuildWar.lua" />	
	<talkaction words="/war-accept" script="GuildWar.lua" />	
	<talkaction words="/war-reject" script="GuildWar.lua" />
	<talkaction words="/war-cancel" script="GuildWar.lua" />	
	<talkaction words="/war-challenge" script="GuildWar.lua" />	
	<talkaction words="/war-cancel-invite" script="GuildWar.lua" />

Go to globalevents/scripts and create a file with the name wars.lua and add this:

Code:
dofile("./GuildWar.lua")

function onThink(interval, lastExecution)
	for _, id in ipairs(getGuildsWithWar()) do
		local Check = db.getResult("SELECT `name` FROM `guilds` WHERE id = ".. getGuildWarInfo(id).With .."")
		if Check:getID() == LUA_ERROR then
			cleanInfo(id)
		end
	end
	return TRUE
end

Later, add this in globalevents.xml:
Code:
<globalevent name="wars" interval="1800" script="wars.lua"/> <!--1800 is 30 minutes-->

Now in go to the folder xampplite/htdocs and create a file.lua (with the name you want) and add this:

Code:
DelayToCancel = 24 * 60 * 60 --minutes

Maps = {
	["map 1"] = 
		{
			Guild1Pos = {x=998, y=1006, z=7},
			Guild2Pos = {x=1002, y=1006, z=7}
		},
	["map 2"] =
		{
			Guild1Pos = {x=994, y=1004, z=6},
			Guild2Pos = {x=1000, y=1003, z=6}			
		}
	}

TimeToTeleport = 1 --minutes, when star a challenge
StopBattle = TRUE --Stop battle after X time ? TRUE  /  FALSE
TimeToStop = 60 --Minutes Time to Stop if StopBattle = TRUE.

--Cancel messages~
CancelMessagesWar = {
	--Message when player try accept/reject/cancel a war but there is no a invitation.
	[1] = "Not pending invitations.",
	--Message when the player is not the guild leader.
	[2] = "Only Guild Leader can execute this command.",
	--Message when try Cancel the invitation but the war is already accepted.
	[3] = "The war is already accepted.",
	--MEssage when the invited guild name is not correct or does not exist.
	[4] = "Not correct guild name.",
	--Message when try invite any guild to a war but his guild already have a war or a pending invitation.
	[5] = "Your guild is already in war or have a pending invitation.",
	--Same of the cancel message 5 but the the enemy guild.
	[6] = "This guild is already in war or have a pending invitation.",
	--Message when use invite command but not write guild name.
	[7] = "Command needs param.",
	--Message when try invite his guild.
	[8] = "You can\´t invite you guild.",
	--Message when the map name is not correct.
	[9] = "Please write a correct name.",
	--Message when try go to any map but the guild is have no received/sent any war invitation
	[10] = "Your guild is not in any war.",
	--When try to cancel a war before the delay
	[11] = "You should wait ".. DelayToCancel .." minutes to cancel the war"
	}
	
--Broadcast messages when invite/accept/reject/cancel ~ Remember the Spaces.
BroadCast_Type = MESSAGE_EVENT_ADVANCE
BroadCast = {
	--Message when inviting
	[1] = 
		{
			"Guild ",
			--Here will be the guild name
			" have invited guild ",
			--Here will be the invited guild name
			" to have a war."
		},
	--Message when accept.
	[2] = 
		{
			"Guild ",
			--Here will be the guild name
			" have accepted the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when reject.
	[3] = 
		{
			"Guild ",
			--Here will be the guild name
			" have rejected the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when cancel.
	[4] = 
		{
			"Guild ",
			--Here will be the guild name
			" have canceled the invitation to the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message whenstar a battle..
	[5] = 
		{
			"Guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" will have a battle in the map :"
		},
	--message when a battle ends.
	[6] = 
		{
			"The battle betwen guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" its over."
		},
	}

--Functions ~.
function getGuildWarInfo(id)
	local Info = db.getResult("SELECT `invited_to`, `invited_by`, `in_war_with`,`war_time` FROM `guilds` WHERE `id` = " .. id .. "")
	if Info:getID() ~= LUA_ERROR then
		local invTo, invBy, warWith, Time = Info:getDataInt("invited_to"), Info:getDataInt("invited_by"), Info:getDataInt("in_war_with"), Info:getDataInt("war_time") 
		Info:free()
		return {To = invTo, By = invBy, With = warWith, T = Time}
	end
 	return LUA_ERROR
end

function getGuildNameById(id)
	local Info = db.getResult("SELECT `name` FROM `guilds` WHERE `id` = " .. id .. "")
		if Info:getID() ~= LUA_ERROR then
		local Name = Info:getDataString("name")
		Info:free()
		return Name
	end
 	return LUA_ERROR
end

function GuildIsInPEace(id)
	local Info = getGuildWarInfo(id)
	return (Info.To == 0 and Info.By == 0 and Info.With == 0)
end

function doInviteToWar(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = ".. enemyGuild .." WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_by` = ".. myGuild .." WHERE `id` = ".. enemyGuild .."")
end

function WarAccept(myGuild, enemyGuild)
	local StartTime = os.time()
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. myGuild ..", `kills` = 0, `show` = 1 WHERE `id` = ".. enemyGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. enemyGuild ..", `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function cleanInfo(myGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = 0, `in_war_with`  =  0, `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function registerDeath(myGuild, enemyGuild, cid, target)
	db.executeQuery("INSERT INTO `deaths_in_wars` (`guild_id`, `player_id`, `killer_guild`, `killer`, `date`) VALUES ("..enemyGuild..", "..getPlayerGUID(target)..", "..myGuild..", "..getPlayerGUID(cid)..", " .. os.time() ..");")	
	db.executeQuery("UPDATE `guilds` SET `kills` = `kills` + 1 WHERE `id` = ".. myGuild .."")
end

function StopWar(myGuild, enemyGuild)
	cleanInfo(myGuild)
	cleanInfo(enemyGuild)
	removeDeaths(myGuild)
	removeDeaths(enemyGuild)
end

function removeDeaths(id)
	db.executeQuery("DELETE FROM `deaths_in_wars` WHERE `guild_id` = " ..id .. ";")
end

function WeAreInWar(myGuild, enemyGuild)
	local myGuildInfo = getGuildWarInfo(myGuild)
	local enemyGuildInfo = getGuildWarInfo(enemyGuild)
	if myGuild == enemyGuildInfo.With and enemyGuild ==  myGuildInfo.With then
		if enemyGuildInfo.ON == 1 and myGuildInfo.ON == 1 then
			return TRUE
		end		
	end
	return FALSE
end

function getOnlineMembers(id)
	local PlayersOnline = getPlayersOnline()
	local MembersOnline = {}
	for i, pid in ipairs(PlayersOnline) do
		if id == getPlayerGuildId(PlayersOnline[i]) then
			table.insert(MembersOnline, PlayersOnline[i])
		end
	end
	return MembersOnline
end

function teleportGuild(id, pos)
	local Members = getOnlineMembers(id)
	if #Members > 0 then
		for i = 1, #Members do
			if getTilePzInfo(getCreaturePosition(Members[i])) == TRUE then
				doTeleportThing(Members[i], pos, FALSE)
				doSendMagicEffect(pos, CONST_ME_TELEPORT)
				doSendMagicEffect(getCreaturePosition(Members[i]), CONST_ME_POFF)
			end
		end
	end
end

function removeFrag(cid)
	local FragTime = getConfigInfo('timeToDecreaseFrags')
	local myFragTime = getPlayerRedSkullTicks(cid)
	local Remo = (myFragTime - FragTime)
	if Remo < 0 then
		Remo = 0
	end
	doPlayerSetRedSkullTicks(cid, Remo)
end

function getGuildsWithWar()
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `in_war_with` > 0")
	local GuildW = {}
	if res:getID() ~= LUA_ERROR then
		while true do
			table.insert(GuildW, res:getDataInt "id")
			if not res:next() then
				break
			end
		end
		res:free()
	end
	return GuildW
end

function guildExist(nom)
	local Get = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(nom) .. ";")
	if Get:getID() ~= LUA_ERROR then
		local ret = Get:getDataInt("id")
		Get:free()
		return ret
	end
 	return LUA_ERROR
end

function StarWar(x)
	teleportGuild(x.myGuild, Maps[x.map].Guild1Pos)
	teleportGuild(x.enemyGuild, Maps[x.map].Guild2Pos)
--[[	
	putWarOn(x.myGuild, x.enemyGuild)
	if StopBattle == TRUE then
		addEvent(StopWarNow, 60 * 1000, {myGuild = x.myGuild, enemyGuild = x.enemyGuild})
	end
]]
end	

--[[
function StopWarNow(c)
	StopWar(c.myGuild, c.enemyGuild)
	doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(c.myGuild).. BroadCast[6][2] ..getGuildNameById(c.enemyGuild).. BroadCast[6][3], BroadCast_Type)
end

function putWarOn(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. enemyGuild .."")
end
]]

And it's already

Don't use the "other scripts"
 
In the tfs folder (where is located config.lua) create a filde called GuildWard.lua and add this:

Code:
function guildExists(guildId)
	if(type(guildId) ~= 'number') then
		return FALSE, error("luaGuildExists: number expected for 'guildId' (got " .. type(guildId) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `id` = " .. guildId)
	if(res:getID() ~= LUA_ERROR) then
		res:free()
		return TRUE
	end
	
	return FALSE
end

function isGuildInWar(guildId)
	if(guildExists(guildId) == TRUE) then
		return FALSE
	end
	
	return FALSE
end

function getGuildIdByName(name)
	if(type(name) ~= 'string') then
		return FALSE, error("luaGetGuildIdByName: string expected for 'name' (got " .. type(name) .. ")", 2)
	end
	
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(name))
	if(res:getID() ~= LUA_ERROR) then
		local id = res:getDataInt "id"
		res:free()
		
		return id
	end
	
	return FALSE
end

function getGuildLeaderRank(guildId)
	if(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " .. guildId .. " ORDER BY level DESC LIMIT 1;")
	local leaderId = res:getDataString "name"
	res:free()
	
	return leaderId
end

function getGuildWarId(guildId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaGetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE) then
		return FALSE
	end
	
	local res = db.getResult("SELECT `war_id` FROM `guilds` WHERE `id` = " .. guildId .. ", `war_status` = " .. status)
	if(res:getID() ~= LUA_ERROR) then
		local warId = res:getDataInt "war_id"
		res:free()
	
		return warId
	end
	
	return FALSE
end

function setGuildWarId(guildId, warId, status)
	if(type(status) ~= 'number') then
		return FALSE, error("luaSetGuildWarId: number expected for 'status' (got " .. type(status) .. ")", 2)
	elseif(guildExists(guildId) == FALSE or guildExists(warId) == FALSE) then
		return FALSE
	end
	
	local res = db.executeQuery("UPDATE `guilds` SET `war_id` = " .. warId .. ", `war_status` = " .. status .. " WHERE `id` = " .. guildId)
	return TRUE
end

function isInGuildWar(cid, player)
	local guildId = getPlayerGuildId(cid)
	if(guildId ~= FALSE) then
		return FALSE
	end
	
	return FALSE
end

Now go to talkactions/scripts and create a file called GuildWar.lua and add:

Code:
dofile("./GuildWar.lua")

function onSay(cid, words, param)
	if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
		local myGuild = getPlayerGuildId(cid)
		if words == "/war-invite" then
			if GuildIsInPEace(myGuild) == true then
				if param ~= "" then
					if guildExist(param) ~= LUA_ERROR then
						local invitedGuild = getGuildId(param)
						if invitedGuild ~= LUA_ERROR then
							if invitedGuild ~= myGuild then
								if GuildIsInPEace(invitedGuild) == true then
									doInviteToWar(myGuild, invitedGuild)
									doBroadcastMessage(BroadCast[1][1] ..getPlayerGuildName(cid).. BroadCast[1][2] ..getGuildNameById(invitedGuild).. BroadCast[1][3], BroadCast_Type)
								else
									doPlayerSendCancel(cid, CancelMessagesWar[6])
								end
							else
								doPlayerSendCancel(cid, CancelMessagesWar[8])
							end
						else
							doPlayerSendCancel(cid, CancelMessagesWar[4])
						end
					else
						doPlayerSendCancel(cid, CancelMessagesWar[4])
					end
				else
					doPlayerSendCancel(cid, CancelMessagesWar[7])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[5])
			end
		elseif words == "/war-accept" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				local enemyGuild = getGuildWarInfo(myGuild).By
				doBroadcastMessage(BroadCast[2][1] ..getPlayerGuildName(cid).. BroadCast[2][2] ..getGuildNameById(enemyGuild).. BroadCast[2][3], BroadCast_Type)
				WarAccept(myGuild, enemyGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])
			end
		elseif words == "/war-reject" then
			if getGuildWarInfo(myGuild).By ~= 0 then
				doBroadcastMessage(BroadCast[3][1] ..getPlayerGuildName(cid).. BroadCast[3][2] ..getGuildNameById(getGuildWarInfo(myGuild).By).. BroadCast[3][3], BroadCast_Type)
				cleanInfo(getGuildWarInfo(myGuild).By)
				cleanInfo(myGuild)
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-cancel-invite" then
			if getGuildWarInfo(myGuild).To ~= 0 then
				if getGuildWarInfo(myGuild).With == 0 then
					doBroadcastMessage(BroadCast[4][1] ..getPlayerGuildName(cid).. BroadCast[4][2] ..getGuildNameById(getGuildWarInfo(myGuild).To).. BroadCast[4][3], BroadCast_Type)
					cleanInfo(getGuildWarInfo(myGuild).To)
					cleanInfo(myGuild)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[3])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[1])	
			end
		elseif words == "/war-challenge" then
			local map = Maps[param]
			if map then
				if getGuildWarInfo(myGuild).With ~= 0 and getGuildWarInfo(myGuild).ON == 0 then
					local enemyGuild = getGuildWarInfo(myGuild).With
					addEvent(StarWar, 15 * 1000, {myGuild = myGuild, enemyGuild = enemyGuild, map = param})
					doBroadcastMessage(BroadCast[5][1] ..getPlayerGuildName(cid).. BroadCast[5][2] ..getGuildNameById(enemyGuild).. BroadCast[5][3] .. param ..".", BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[10])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[9])
			end
		elseif words == "/war-cancel" then
			local enemy = getGuildWarInfo(myGuild).With
			if enemy ~= 0 then
				if (os.time() - getGuildWarInfo(myGuild).T) >= (60 * DelayToCancel) then
					StopWar(myGuild, enemy)
					doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(myGuild).. BroadCast[6][2] ..getGuildNameById(enemy).. BroadCast[6][3], BroadCast_Type)
				else
					doPlayerSendCancel(cid, CancelMessagesWar[11])
				end
			else
				doPlayerSendCancel(cid, CancelMessagesWar[10])
			end
		end
	else
		doPlayerSendCancel(cid, CancelMessagesWar[2])
	end
	local file = io.open("data/logs/Wars.txt", "a") 
	file:write("".. os.date("%d %B %Y %X ", os.time()) .." -->  "..getCreatureName(cid)..": "..words.." "..param.."\n") 
	file:close() 
	return TRUE
end

Later, go to talkactions.xml and add this:

Code:
<talkaction words="/war-invite" script="GuildWar.lua" />	
	<talkaction words="/war-accept" script="GuildWar.lua" />	
	<talkaction words="/war-reject" script="GuildWar.lua" />
	<talkaction words="/war-cancel" script="GuildWar.lua" />	
	<talkaction words="/war-challenge" script="GuildWar.lua" />	
	<talkaction words="/war-cancel-invite" script="GuildWar.lua" />

Go to globalevents/scripts and create a file with the name wars.lua and add this:

Code:
dofile("./GuildWar.lua")

function onThink(interval, lastExecution)
	for _, id in ipairs(getGuildsWithWar()) do
		local Check = db.getResult("SELECT `name` FROM `guilds` WHERE id = ".. getGuildWarInfo(id).With .."")
		if Check:getID() == LUA_ERROR then
			cleanInfo(id)
		end
	end
	return TRUE
end

Later, add this in globalevents.xml:
Code:
<globalevent name="wars" interval="1800" script="wars.lua"/> <!--1800 is 30 minutes-->

Now in go to the folder xampplite/htdocs and create a file.lua (with the name you want) and add this:

Code:
DelayToCancel = 24 * 60 * 60 --minutes

Maps = {
	["map 1"] = 
		{
			Guild1Pos = {x=998, y=1006, z=7},
			Guild2Pos = {x=1002, y=1006, z=7}
		},
	["map 2"] =
		{
			Guild1Pos = {x=994, y=1004, z=6},
			Guild2Pos = {x=1000, y=1003, z=6}			
		}
	}

TimeToTeleport = 1 --minutes, when star a challenge
StopBattle = TRUE --Stop battle after X time ? TRUE  /  FALSE
TimeToStop = 60 --Minutes Time to Stop if StopBattle = TRUE.

--Cancel messages~
CancelMessagesWar = {
	--Message when player try accept/reject/cancel a war but there is no a invitation.
	[1] = "Not pending invitations.",
	--Message when the player is not the guild leader.
	[2] = "Only Guild Leader can execute this command.",
	--Message when try Cancel the invitation but the war is already accepted.
	[3] = "The war is already accepted.",
	--MEssage when the invited guild name is not correct or does not exist.
	[4] = "Not correct guild name.",
	--Message when try invite any guild to a war but his guild already have a war or a pending invitation.
	[5] = "Your guild is already in war or have a pending invitation.",
	--Same of the cancel message 5 but the the enemy guild.
	[6] = "This guild is already in war or have a pending invitation.",
	--Message when use invite command but not write guild name.
	[7] = "Command needs param.",
	--Message when try invite his guild.
	[8] = "You can\´t invite you guild.",
	--Message when the map name is not correct.
	[9] = "Please write a correct name.",
	--Message when try go to any map but the guild is have no received/sent any war invitation
	[10] = "Your guild is not in any war.",
	--When try to cancel a war before the delay
	[11] = "You should wait ".. DelayToCancel .." minutes to cancel the war"
	}
	
--Broadcast messages when invite/accept/reject/cancel ~ Remember the Spaces.
BroadCast_Type = MESSAGE_EVENT_ADVANCE
BroadCast = {
	--Message when inviting
	[1] = 
		{
			"Guild ",
			--Here will be the guild name
			" have invited guild ",
			--Here will be the invited guild name
			" to have a war."
		},
	--Message when accept.
	[2] = 
		{
			"Guild ",
			--Here will be the guild name
			" have accepted the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when reject.
	[3] = 
		{
			"Guild ",
			--Here will be the guild name
			" have rejected the invitation of the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message when cancel.
	[4] = 
		{
			"Guild ",
			--Here will be the guild name
			" have canceled the invitation to the guild " ,
			--Here will be the name of the guild who have invited em.
			" to have a war."
		},
	--Message whenstar a battle..
	[5] = 
		{
			"Guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" will have a battle in the map :"
		},
	--message when a battle ends.
	[6] = 
		{
			"The battle betwen guild ",
			--Here will be the guild name
			" and guild " ,
			--Here will be the name of the guild who have invited em.
			" its over."
		},
	}

--Functions ~.
function getGuildWarInfo(id)
	local Info = db.getResult("SELECT `invited_to`, `invited_by`, `in_war_with`,`war_time` FROM `guilds` WHERE `id` = " .. id .. "")
	if Info:getID() ~= LUA_ERROR then
		local invTo, invBy, warWith, Time = Info:getDataInt("invited_to"), Info:getDataInt("invited_by"), Info:getDataInt("in_war_with"), Info:getDataInt("war_time") 
		Info:free()
		return {To = invTo, By = invBy, With = warWith, T = Time}
	end
 	return LUA_ERROR
end

function getGuildNameById(id)
	local Info = db.getResult("SELECT `name` FROM `guilds` WHERE `id` = " .. id .. "")
		if Info:getID() ~= LUA_ERROR then
		local Name = Info:getDataString("name")
		Info:free()
		return Name
	end
 	return LUA_ERROR
end

function GuildIsInPEace(id)
	local Info = getGuildWarInfo(id)
	return (Info.To == 0 and Info.By == 0 and Info.With == 0)
end

function doInviteToWar(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = ".. enemyGuild .." WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_by` = ".. myGuild .." WHERE `id` = ".. enemyGuild .."")
end

function WarAccept(myGuild, enemyGuild)
	local StartTime = os.time()
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. myGuild ..", `kills` = 0, `show` = 1 WHERE `id` = ".. enemyGuild .."")
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = ".. StartTime ..", `in_war_with`  =  ".. enemyGuild ..", `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function cleanInfo(myGuild)
	db.executeQuery("UPDATE `guilds` SET `invited_to` = 0, `invited_by` = 0, `war_time` = 0, `in_war_with`  =  0, `kills` = 0, `show` = 0 WHERE `id` = ".. myGuild .."")
end

function registerDeath(myGuild, enemyGuild, cid, target)
	db.executeQuery("INSERT INTO `deaths_in_wars` (`guild_id`, `player_id`, `killer_guild`, `killer`, `date`) VALUES ("..enemyGuild..", "..getPlayerGUID(target)..", "..myGuild..", "..getPlayerGUID(cid)..", " .. os.time() ..");")	
	db.executeQuery("UPDATE `guilds` SET `kills` = `kills` + 1 WHERE `id` = ".. myGuild .."")
end

function StopWar(myGuild, enemyGuild)
	cleanInfo(myGuild)
	cleanInfo(enemyGuild)
	removeDeaths(myGuild)
	removeDeaths(enemyGuild)
end

function removeDeaths(id)
	db.executeQuery("DELETE FROM `deaths_in_wars` WHERE `guild_id` = " ..id .. ";")
end

function WeAreInWar(myGuild, enemyGuild)
	local myGuildInfo = getGuildWarInfo(myGuild)
	local enemyGuildInfo = getGuildWarInfo(enemyGuild)
	if myGuild == enemyGuildInfo.With and enemyGuild ==  myGuildInfo.With then
		if enemyGuildInfo.ON == 1 and myGuildInfo.ON == 1 then
			return TRUE
		end		
	end
	return FALSE
end

function getOnlineMembers(id)
	local PlayersOnline = getPlayersOnline()
	local MembersOnline = {}
	for i, pid in ipairs(PlayersOnline) do
		if id == getPlayerGuildId(PlayersOnline[i]) then
			table.insert(MembersOnline, PlayersOnline[i])
		end
	end
	return MembersOnline
end

function teleportGuild(id, pos)
	local Members = getOnlineMembers(id)
	if #Members > 0 then
		for i = 1, #Members do
			if getTilePzInfo(getCreaturePosition(Members[i])) == TRUE then
				doTeleportThing(Members[i], pos, FALSE)
				doSendMagicEffect(pos, CONST_ME_TELEPORT)
				doSendMagicEffect(getCreaturePosition(Members[i]), CONST_ME_POFF)
			end
		end
	end
end

function removeFrag(cid)
	local FragTime = getConfigInfo('timeToDecreaseFrags')
	local myFragTime = getPlayerRedSkullTicks(cid)
	local Remo = (myFragTime - FragTime)
	if Remo < 0 then
		Remo = 0
	end
	doPlayerSetRedSkullTicks(cid, Remo)
end

function getGuildsWithWar()
	local res = db.getResult("SELECT `id` FROM `guilds` WHERE `in_war_with` > 0")
	local GuildW = {}
	if res:getID() ~= LUA_ERROR then
		while true do
			table.insert(GuildW, res:getDataInt "id")
			if not res:next() then
				break
			end
		end
		res:free()
	end
	return GuildW
end

function guildExist(nom)
	local Get = db.getResult("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(nom) .. ";")
	if Get:getID() ~= LUA_ERROR then
		local ret = Get:getDataInt("id")
		Get:free()
		return ret
	end
 	return LUA_ERROR
end

function StarWar(x)
	teleportGuild(x.myGuild, Maps[x.map].Guild1Pos)
	teleportGuild(x.enemyGuild, Maps[x.map].Guild2Pos)
--[[	
	putWarOn(x.myGuild, x.enemyGuild)
	if StopBattle == TRUE then
		addEvent(StopWarNow, 60 * 1000, {myGuild = x.myGuild, enemyGuild = x.enemyGuild})
	end
]]
end	

--[[
function StopWarNow(c)
	StopWar(c.myGuild, c.enemyGuild)
	doBroadcastMessage(BroadCast[6][1] ..getGuildNameById(c.myGuild).. BroadCast[6][2] ..getGuildNameById(c.enemyGuild).. BroadCast[6][3], BroadCast_Type)
end

function putWarOn(myGuild, enemyGuild)
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. myGuild .."")
	db.executeQuery("UPDATE `guilds` SET `war_time`  = 1 WHERE `id` = ".. enemyGuild .."")
end
]]

And it's already

Don't use the "other scripts"
[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)


[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)


[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)


[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)


[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)


[06/04/2009 03:12:56] Lua Script Error: [TalkAction Interface]
[06/04/2009 03:12:56] data/talkactions/scripts/GuildWar.lua

[06/04/2009 03:12:56] cannot open ./GuildWar.lua: No such file or directory
[06/04/2009 03:12:56] [Warning - Event::loadScript] Can not load script (data/talkactions/scripts/GuildWar.lua)
error..
 
is your mistake.. "no such file or directory".

checks that the name of the file that one finds in the first folder (where the config.lua is) has the correct name (GuildWar.lua)
 
[06/04/2009 03:28:22] data/talkactions/scripts/GuildWar.lua:89: attempt to index global 'CancelMessagesWar' (a nil value)
[06/04/2009 03:28:22] stack traceback:
[06/04/2009 03:28:22] data/talkactions/scripts/GuildWar.lua:89: in function <data/talkactions/scripts/GuildWar.lua:3>
how can i solve it?
 
Back
Top