TFS 0.4 RealWarSystem.txt

(20 KB) Pobierz
wkleic do sql w phpmyadmin 
-------------------------------------------------------
CREATE TABLE IF NOT EXISTS `guild_wars` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `guild_id` INT NOT NULL,
  `enemy_id` INT NOT NULL,
  `begin` BIGINT NOT NULL DEFAULT '0',
  `end` BIGINT NOT NULL DEFAULT '0',
  `frags` INT UNSIGNED NOT NULL DEFAULT '0',
  `payment` BIGINT UNSIGNED NOT NULL DEFAULT '0',
  `guild_kills` INT UNSIGNED NOT NULL DEFAULT '0',
  `enemy_kills` INT UNSIGNED NOT NULL DEFAULT '0',
  `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `status` (`status`),
  KEY `guild_id` (`guild_id`),
  KEY `enemy_id` (`enemy_id`)
) ENGINE=InnoDB;
---------------------------------------------------------------
ALTER TABLE `guild_wars`
  ADD CONSTRAINT `guild_wars_ibfk_1` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_wars_ibfk_2` FOREIGN KEY (`enemy_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;
---------------------------------------------------------------
ALTER TABLE `guilds` ADD `balance` BIGINT UNSIGNED NOT NULL AFTER `motd`;
------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `guild_kills` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `guild_id` INT NOT NULL,
  `war_id` INT NOT NULL,
  `death_id` INT NOT NULL
) ENGINE = InnoDB;
-------------------------------------------------------------------------------
ALTER TABLE `guild_kills`
  ADD CONSTRAINT `guild_kills_ibfk_1` FOREIGN KEY (`war_id`) REFERENCES `guild_wars` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_kills_ibfk_2` FOREIGN KEY (`death_id`) REFERENCES `player_deaths` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_kills_ibfk_3` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;
------------------------------------------------------------------------------------
ALTER TABLE `killers` ADD `war` INT NOT NULL DEFAULT 0;
 --------------------------------------------------------------------------------------





to wklejamy do data/talkactions/talkactions.xml
------------------------------------------------------------------------------------------------------------------

<talkaction words="/war" channel="0" event="script" value="war.lua" desc="(Guild channel command) War management."/>
<talkaction words="/balance" channel="0" event="script" value="balance.lua" desc="(Guild channel command) Balance management."/>
--------------------------------------------------------------------------------------------------------------------






data/globalevents/scripts/init.lua lub start.lua
----------------------------------------------------------------------------------------------------------------
db.executeQuery("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (os.time() - 2 * 86400) .. ";")
db.executeQuery("UPDATE `guild_wars` SET `status` = 5, `end` = " .. os.time() .. " WHERE `status` = 1 AND `end` > 0 AND `end` < " .. os.time() .. ";")
----------------------------------------------------------------------------------------------------------------
 





data/lib/101-war.lua (stworz ten plik jezeli go nie masz)
 -------------------------------------------------------------------
WAR_GUILD = 0
WAR_ENEMY = 1
 --------------------------------------------------------------------







data/talkactions/scripts/balance.lua ( stworz ten plik jezeli go nie masz )

------------------------------------------------------------------------------
 
local function isValidMoney(value)
	if(value == nil) then
		return false
	end
 
	return (value > 0 and value <= 99999999999999)
end
 
function onSay(cid, words, param, channel)
	local guild = getPlayerGuildId(cid)
	if(guild == 0) then
		return false
	end
 
	local t = string.explode(param, ' ', 1)
	if(getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER and isInArray({ 'pick' }, t[1])) then
		if(t[1] == 'pick') then
			local money = { tonumber(t[2]) }
			if(not isValidMoney(money[1])) then
				doPlayerSendChannelMessage(cid, '', 'Invalid amount of money specified.', TALKTYPE_CHANNEL_W, 0)
				return true
			end
 
			local result = db.getResult('SELECT `balance` FROM `guilds` WHERE `id` = ' .. guild)
			if(result:getID() == -1) then
				return false
			end
 
			money[2] = result:getDataLong('balance')
			result:free()
 
			if(money[1] > money[2]) then
				doPlayerSendChannelMessage(cid, '', 'The balance is too low for such amount.', TALKTYPE_CHANNEL_W, 0)
				return true
			end
 
			if(not db.executeQuery('UPDATE `guilds` SET `balance` = `balance` - ' .. money[1] .. ' WHERE `id` = ' .. guild .. ' LIMIT 1;')) then
				return false
			end
 
			doPlayerAddMoney(cid, money[1])
			doPlayerSendChannelMessage(cid, '', 'You have just picked ' .. money[1] .. ' money from your guild balance.', TALKTYPE_CHANNEL_W, 0)
		else
			doPlayerSendChannelMessage(cid, '', 'Invalid sub-command.', TALKTYPE_CHANNEL_W, 0)
		end
	elseif(t[1] == 'donate') then
		local money = tonumber(t[2])
		if(not isValidMoney(money)) then
			doPlayerSendChannelMessage(cid, '', 'Invalid amount of money specified.', TALKTYPE_CHANNEL_W, 0)
			return true
		end
 
		if(getPlayerMoney(cid) < money) then
			doPlayerSendChannelMessage(cid, '', 'You don\'t have enough money.', TALKTYPE_CHANNEL_W, 0)
			return true
		end
 
		if(not doPlayerRemoveMoney(cid, money)) then
			return false
		end
 
		db.executeQuery('UPDATE `guilds` SET `balance` = `balance` + ' .. money .. ' WHERE `id` = ' .. guild .. ' LIMIT 1;')
		doPlayerSendChannelMessage(cid, '', 'You have transfered ' .. money .. ' money to your guild balance.', TALKTYPE_CHANNEL_W, 0)
	else
		local result = db.getResult('SELECT `name`, `balance` FROM `guilds` WHERE `id` = ' .. guild)
		if(result:getID() == -1) then
			return false
		end
 
		doPlayerSendChannelMessage(cid, '', 'Current balance of guild ' .. result:getDataString('name') .. ' is: ' .. result:getDataLong('balance') .. ' bronze coins.', TALKTYPE_CHANNEL_W, 0)
		result:free()
	end
 
	return true
end
----------------------------------------------------------------------------------------------------






data/talkactions/scripts/war.lua ( stworz jezeli go nie masz ) 
 --------------------------------------------------------------------------
function onSay(cid, words, param, channel)
	local guild = getPlayerGuildId(cid)
	if(not guild or getPlayerGuildLevel(cid) < GUILDLEVEL_LEADER) then
		doPlayerSendChannelMessage(cid, "", "You cannot execute this talkaction.", TALKTYPE_CHANNEL_W, 0)
		return true
	end
 
	local t = string.explode(param, ",")
	if(not t[2]) then
		doPlayerSendChannelMessage(cid, "", "Not enough param(s).", TALKTYPE_CHANNEL_W, 0)
		return true
	end
 
	local enemy = getGuildId(t[2])
	if(not enemy) then
		doPlayerSendChannelMessage(cid, "", "Guild \"" .. t[2] .. "\" does not exists.", TALKTYPE_CHANNEL_W, 0)
		return true
	end
 
	if(enemy == guild) then
		doPlayerSendChannelMessage(cid, "", "You cannot perform war action on your own guild.", TALKTYPE_CHANNEL_W, 0)
		return true
	end
 
	local enemyName, tmp = "", db.getResult("SELECT `name` FROM `guilds` WHERE `id` = " .. enemy)
	if(tmp:getID() ~= -1) then
		enemyName = tmp:getDataString("name")
		tmp:free()
	end
 
	if(isInArray({"accept", "reject", "cancel"}, t[1])) then
		local query = "`guild_id` = " .. enemy .. " AND `enemy_id` = " .. guild
		if(t[1] == "cancel") then
			query = "`guild_id` = " .. guild .. " AND `enemy_id` = " .. enemy
		end
 
		tmp = db.getResult("SELECT `id`, `begin`, `end`, `payment` FROM `guild_wars` WHERE " .. query .. " AND `status` = 0")
		if(tmp:getID() == -1) then
			doPlayerSendChannelMessage(cid, "", "Currently there's no pending invitation for a war with " .. enemyName .. ".", TALKTYPE_CHANNEL_W, 0)
			return true
		end
 
		if(t[1] == "accept") then
			local _tmp = db.getResult("SELECT `balance` FROM `guilds` WHERE `id` = " .. guild)
			local state = _tmp:getID() < 0 or _tmp:getDataInt("balance") < tmp:getDataInt("payment")
 
			_tmp:free()
			if(state) then
				doPlayerSendChannelMessage(cid, "", "Your guild balance is too low to accept this invitation.", TALKTYPE_CHANNEL_W, 0)
				return true
			end
 
			db.executeQuery("UPDATE `guilds` SET `balance` = `balance` - " .. tmp:getDataInt("payment") .. " WHERE `id` = " .. guild)
		end
 
		query = "UPDATE `guild_wars` SET "
		local msg = "accepted " .. enemyName .. " invitation to war."
		if(t[1] == "reject") then
			query = query .. "`end` = " .. os.time() .. ", `status` = 2"
			msg = "rejected " .. enemyName .. " invitation to war."
		elseif(t[1] == "cancel") then
			query = query .. "`end` = " .. os.time() .. ", `status` = 3"
			msg = "canceled invitation to a war with " .. enemyName .. "."
		else
			query = query .. "`begin` = " .. os.time() .. ", `end` = " .. (tmp:getDataInt("end") > 0 and (os.time() + ((tmp:getDataInt("begin") - tmp:getDataInt("end")) / 86400)) or 0) .. ", `status` = 1"
		end
 
		query = query .. " WHERE `id` = " .. tmp:getDataInt("id")
		if(t[1] == "accept") then
			doGuildAddEnemy(guild, enemy, tmp:getDataInt("id"), WAR_GUILD)
			doGuildAddEnemy(enemy, guild, tmp:getDataInt("id"), WAR_ENEMY)
		end
 
		tmp:free()
		db.executeQuery(query)
		doBroadcastMessage(getPlayerGuildName(cid) .. " has " .. msg, MESSAGE_EVENT_ADVANCE)
		return true
	end
 
	if(t[1] == "invite") then
		local str = ""
                tmp = db.getResult("SELECT `guild_id`, `status` FROM `guild_wars` WHERE `guild_id` IN (" .. guild .. "," .. enemy .. ") AND `enemy_id` IN (" .. enemy .. "," .. guild .. ") AND `status` IN (0, 1)")
                ...
Zgłoś jeśli naruszono regulamin