War system (frag limit)

This commit is contained in:
Daniel Björkholm 2014-05-28 22:43:50 +02:00
parent feb0feffee
commit 7fe609abdb
3 changed files with 110 additions and 2 deletions

View File

@ -0,0 +1,96 @@
local deathListEnabled = true
local maxDeathRecords = 5
function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
local player = Player(cid)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
if not deathListEnabled then
return
end
local byPlayer = 0
local killerCreature = Creature(killer)
if killerCreature == nil then
killerName = "field item"
else
if killerCreature:isPlayer() then
byPlayer = 1
else
local master = killerCreature:getMaster()
if master and master ~= killerCreature and master:isPlayer() then
killerCreature = master
byPlayer = 1
end
end
killerName = killerCreature:getName()
end
local byPlayerMostDamage = 0
if mostDamage == 0 then
mostDamageName = "field item"
else
local mostDamageKiller = Creature(mostDamage)
if mostDamageKiller:isPlayer() then
byPlayerMostDamage = 1
else
local master = mostDamageKiller:getMaster()
if master and master ~= mostDamageKiller and master:isPlayer() then
mostDamageKiller = master
byPlayerMostDamage = 1
end
end
mostDamageName = mostDamageKiller:getName()
end
local playerGuid = player:getGuid()
db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES (" .. playerGuid .. ", " .. os.time() .. ", " .. player:getLevel() .. ", " .. db.escapeString(killerName) .. ", " .. byPlayer .. ", " .. db.escapeString(mostDamageName) .. ", " .. byPlayerMostDamage .. ", " .. unjustified .. ", " .. mostDamage_unjustified .. ")")
local resultId = db.storeQuery("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. playerGuid)
local deathRecords = 0
local tmpResultId = resultId
while tmpResultId ~= false do
tmpResultId = result.next(resultId)
deathRecords = deathRecords + 1
end
if resultId ~= false then
result.free(resultId)
end
while deathRecords > maxDeathRecords do
db.query("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT 1")
deathRecords = deathRecords - 1
end
if byPlayer == 1 then
local playerGuild = player:getGuild()
if playerGuild then
local killerGuild = killerCreature:getGuild()
if playerGuild ~= killerGuild and isInWar(cid, killerCreature) then
local warId = false
resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild:getId() .. " AND `guild2` = " .. playerGuild:getId() .. ") OR (`guild1` = " .. playerGuild:getId() .. " AND `guild2` = " .. killerGuild:getId() .. "))")
if resultId ~= false then
warId = result.getDataInt(resultId, "id")
result.free(resultId)
end
if warId ~= false then
db.query("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(killerName) .. ", " .. db.escapeString(player:getName()) .. ", " .. killerGuild:getId() .. ", " .. playerGuild:getId() .. ", " .. os.time() .. ", " .. warId .. ")")
local wars = db.storeQuery("SELECT `guild_wars`.`id`, (SELECT `limit` FROM `znote_guild_wars` WHERE `znote_guild_wars`.`id` = `guild_wars`.`id`) AS `limit`, (SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild1`) guild1_kills, (SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild2`) guild2_kills FROM `guild_wars` WHERE (`guild1` = " .. killerGuild:getId() .. " OR `guild2` = " .. killerGuild:getId() .. ") AND `id` = " .. warId .. " AND `status` = 1")
if wars ~= false then
guildKills1 = result.getDataInt(wars, "guild1_kills")
guildKills2 = result.getDataInt(wars, "guild2_kills")
fragLimit = result.getDataInt(wars, "limit")
result.free(wars)
end
if guildKills1 >= fragLimit or guildKills2 >= fragLimit then
broadcastMessage(string.format("%s has just won the war against %s.", killerGuild:getName(), playerGuild:getName()), MESSAGE_EVENT_ADVANCE)
db.query("UPDATE `guild_wars` SET `status` = 4, `ended` = " .. os.time() .. " WHERE `status` = 1 AND `id` = " .. warId)
end
end
end
end
end
end

View File

@ -214,6 +214,13 @@ CREATE TABLE IF NOT EXISTS `znote_deleted_characters` (
`done` tinyint(1) NOT NULL, `done` tinyint(1) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_guild_wars` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`limit` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
FOREIGN KEY (`id`) REFERENCES `guild_wars` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
</textarea> </textarea>
</li> </li>
<li> <li>

View File

@ -490,6 +490,10 @@ if ($highest_access >= 2) {
$wars = mysql_select_multi("SELECT `id`, `guild1`, `guild2`, `status` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild1` = '$targetGuild') AND (`guild2` = '$gid' OR `guild2` = '$targetGuild') AND `status` IN (0, 1);"); $wars = mysql_select_multi("SELECT `id`, `guild1`, `guild2`, `status` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild1` = '$targetGuild') AND (`guild2` = '$gid' OR `guild2` = '$targetGuild') AND `status` IN (0, 1);");
if ($status == false && $wars == false) { if ($status == false && $wars == false) {
guild_war_invitation($gid, $targetGuild); guild_war_invitation($gid, $targetGuild);
$limit = $_POST['limit'];
if (empty($limit))
$limit = 100;
mysql_insert("INSERT INTO `znote_guild_wars` (`limit`) VALUES ('$limit');");
header('Location: guilds.php?name='. $_GET['name']); header('Location: guilds.php?name='. $_GET['name']);
exit(); exit();
} else echo '<font color="red" size="4">This guild has already been invited to war(or you\'re trying to invite your own).</FONT>'; } else echo '<font color="red" size="4">This guild has already been invited to war(or you\'re trying to invite your own).</FONT>';
@ -683,6 +687,7 @@ if ($highest_access >= 2) {
<ul> <ul>
<li>Invite guild to war:<br> <li>Invite guild to war:<br>
<input type="text" name="warinvite" placeholder="Guild name"> <input type="text" name="warinvite" placeholder="Guild name">
<input type="number" min="10" max="999" name="limit">
<input type="submit" value="Invite Guild"> <input type="submit" value="Invite Guild">
</li> </li>
</ul> </ul>
@ -694,12 +699,12 @@ if ($highest_access >= 2) {
<table id="guildsTable" class="table table-striped table-hover"><tr class="yellow"><th>Aggressor</th><th>Information</th><th>Enemy</th></tr> <table id="guildsTable" class="table table-striped table-hover"><tr class="yellow"><th>Aggressor</th><th>Information</th><th>Enemy</th></tr>
<?php <?php
$i = 0; $i = 0;
$wars = mysql_select_multi("SELECT `guild1`, `guild2`, `name1`, `name2`, `started` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild2` = '$gid') AND `status` = 0 ORDER BY `started` DESC"); $wars = mysql_select_multi("SELECT `guild1`, `guild2`, `name1`, `name2`, `started`, (SELECT `limit` FROM `znote_guild_wars` WHERE `znote_guild_wars`.`id` = `guild_wars`.`id`) AS `limit` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild2` = '$gid') AND `status` = 0 ORDER BY `started` DESC");
if (!empty($wars) || $wars !== false) { if (!empty($wars) || $wars !== false) {
foreach($wars as $war) { foreach($wars as $war) {
$i++; $i++;
echo '<tr><td><a href="guilds.php?name='.$war['name1'].'">'.$war['name1'].'</a></td><td>'; echo '<tr><td><a href="guilds.php?name='.$war['name1'].'">'.$war['name1'].'</a></td><td>';
echo '<center><b>Pending invitation</b><br />Invited on ' . getClock($war['started'], true) . '.<br />'; echo '<center><b>Pending invitation</b><br />Invited on ' . getClock($war['started'], true) . '.<br />The frag limit is set to ' . $war['limit'] . ' frags.<br />';
if ($war['guild1'] == $gid) { if ($war['guild1'] == $gid) {
echo '<br /><form action="" method="post"><input type="hidden" name="cancel_war_invite" value="'.$war['guild2'].'" /><input type="submit" value="Cancel Invitation"></form>'; echo '<br /><form action="" method="post"><input type="hidden" name="cancel_war_invite" value="'.$war['guild2'].'" /><input type="submit" value="Cancel Invitation"></form>';
} else if ($war['guild2'] == $gid) { } else if ($war['guild2'] == $gid) {