1local LIMITE_STORAGE = 999999999
2local maxDeathRecords = 5
3local WarzoneLobbyTimer = {}
4local function getExpForLevel(level)
5 level = level - 1
6 return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
7end
8function onPrepareDeath(player, killer)
9 local tile = Tile(player:getPosition()):hasFlag(TILESTATE_PVPZONE)
10 if tile then
11 if killer then
12 if killer:isPlayer() then
13 -- FREELANCER
14 local targetPlacar = killer:getStorageValue(_SISTEMA.TIME_WAR_STORAGE)
15 Game.setStorageValue(_SISTEMA.FIGHT_PLACAR[targetPlacar].GLOBAL_PLACAR, (Game.getStorageValue(_SISTEMA.FIGHT_PLACAR[targetPlacar].GLOBAL_PLACAR) + 01))
16 player:setStorageValue(_SISTEMA.INVITE_WAR_MAIN, nil)
17
18 if Game.getStorageValue(_SISTEMA.FIGHT_PLACAR[targetPlacar].GLOBAL_PLACAR) >= 03 then
19 local WinnerTimeId = 00
20 REMOVE_PLAYER_ARENA = addEvent(function()
21 local from = _SISTEMA.ARENA[01]
22 local to = _SISTEMA.ARENA[02]
23 for A = from.x, to.x do
24 for B = from.y, to.y do
25 for C = from.z, to.z do
26 local tile = Tile(A, B, C)
27 local creature = tile:getTopCreature()
28 if creature and creature:isPlayer() then
29 creature:teleportTo(_SISTEMA.TEMPLE_POS)
30 creature:getPosition():sendMagicEffect(03)
31 if WinnerTimeId == 00 then
32 WinnerTimeId = creature:getStorageValue(_SISTEMA.TIME_WAR_STORAGE)
33 end
34 creature:setStorageValue(_SISTEMA.INVITE_WAR_MAIN, nil)
35 end
36 end
37 end
38 end
39
40 local players = Game.getPlayers()
41 for _, targetPlayer in ipairs(players) do
42 if targetPlayer:getStorageValue(_SISTEMA.TIME_WAR_STORAGE) > 00 then
43 if targetPlayer:getStorageValue(_SISTEMA.TIME_WAR_STORAGE) == WinnerTimeId then
44 onSetPlayerVictory(targetPlayer:getGuid(), _SISTEMA.VICTORY_POINTS)
45 -- RECOMPENSA
46 local RewardId = math.random(01, #_SISTEMA.REWARDS)
47 local VictoryPlayer = tonumber(onGetPlayerVictory(targetPlayer:getGuid()))
48 local RankNamePlayer = ""
49 local RankChancePlayer = 00
50 for X = 01, #_SISTEMA.RANKS do
51 if VictoryPlayer >= _SISTEMA.RANKS[X].VALUE then
52 RankNamePlayer = _SISTEMA.RANKS[X].NAME
53 RankChancePlayer = _SISTEMA.RANKS[X].CHANCE
54 break
55 end
56 end
57
58 if math.random(000, 10) <= RankChancePlayer then
59
60 if _SISTEMA.REWARDS[RewardId].TYPE == 01 then
61 targetPlayer:addItem(_SISTEMA.REWARDS[RewardId].IDD, _SISTEMA.REWARDS[RewardId].VALUE)
62 elseif _SISTEMA.REWARDS[RewardId].TYPE == 02 then
63 targetPlayer:setStorageValue(_SISTEMA.REWARDS[RewardId].IDD, _SISTEMA.REWARDS[RewardId].VALUE)
64 end
65
66
67 end
68 else
69 targetPlayer:setStorageValue(_SISTEMA.TIME_WAR_STORAGE, nil)
70 end
71 end
72 end
73 end, _SISTEMA.SEC_REMOVE_PLA_ARENA * 1000)
74 end
75
76 if Game.getStorageValue(_GLOBAL_RANDOM.WARZONE.STORAGE_START_WARZONE) == 01 then
77 if player:getStorageValue(_SYSTEM.WARZONE) > 00 and killer:getStorageValue(_SYSTEM.WARZONE) > 00 then
78
79 if player:getStorageValue(_GLOBAL_RANDOM.WARZONE.STORAGE_BLUE_PLAYER) == 01 then
80 local RED_TIME = Game.getStorageValue(_GLOBAL_RANDOM.WARZONE.PLACAR_RED_TEAM)
81 Game.setStorageValue(_GLOBAL_RANDOM.WARZONE.PLACAR_RED_TEAM, (RED_TIME + 01))
82
83 elseif player:getStorageValue(_GLOBAL_RANDOM.WARZONE.STORAGE_RED_PLAYER) == 01 then
84 local BLUE_TIME = Game.getStorageValue(_GLOBAL_RANDOM.WARZONE.PLACAR_BLUE_TEAM)
85 Game.setStorageValue(_GLOBAL_RANDOM.WARZONE.PLACAR_BLUE_TEAM, (BLUE_TIME + 01))
86 end
87
88 -- DESAFIO
89 if killer:getStorageValue(_DESAFIOS[00].DESAFIO_ID) > 00 then
90 onPlayerDesafios(killer, 79, 01)
91 end
92 end
93
94 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_01, nil)
95 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_02, nil)
96 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_03, nil)
97 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_04, nil)
98 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_05, nil)
99 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_06, nil)
100 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_07, nil)
101 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_08, nil)
102 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_09, nil)
103 player:setStorageValue(_SYSTEM.INVENTARIO[04].UID_10, nil)
104
105 player:setStorageValue(_GLOBAL_RANDOM.WARZONE.LOBBY_TIMER, 10)
106
107
108 doInventario(player, 00, 04, 00)
109 player:sendCancelMessage("@StarCliente")
110 end
111 if killer:getStorageValue(_PVP_ROOM[00].PVP_SALA_ID) == 06 and player:getStorageValue(_PVP_ROOM[00].PVP_SALA_ID) == 06 then
112 if killer:getIp() ~= player:getIp() then
113 if killer:getStorageValue(_SYSTEM.PVP_POINTS) < 00 then
114 killer:setStorageValue(_SYSTEM.PVP_POINTS, 01)
115 else
116 killer:setStorageValue(_SYSTEM.PVP_POINTS, (killer:getStorageValue(_SYSTEM.PVP_POINTS) + 01))
117 end
118
119 -- DESAFIO
120 if killer:getStorageValue(_DESAFIOS[00].DESAFIO_ID) > 00 then
121 onPlayerDesafios(killer, 73, 01)
122 end
123 killer:sendCancelMessage("@LootMSG 3219 05 00 01")
124 doBackpack(killer, 11)
125 end
126 end
127 end
128 end
129 if player:getStorageValue(_SYSTEM.FIRST_DEAD_TUTOR) == 02 then
130 player:setTown(Town(16))
131 player:teleportTo({x=3893, y=1771, z=07})
132 player:addHealth(player:getMaxHealth())
133 player:setStorageValue(_SYSTEM.FIRST_DEAD_TUTOR, nil)
134 player:setStorageValue(_SYSTEM.DANGEROUS[01][01].STORAGE, nil)
135
136
137 player:sendCancelMessage("@NoTeleport 00")
138 return false
139 end
140 if player:teleportTo(player:getTown():getTemplePosition()) then
141 player:addHealth(player:getMaxHealth())
142 end
143 else
144 player:getPosition():sendMagicEffect(206)
145 player:setSkull(SKULL_NONE)
146 player:setSkullTime(0)
147 if player:teleportTo(player:getTown():getTemplePosition()) then
148 player:addHealth(player:getMaxHealth())
149 end
150 player:setStorageValue(_SYSTEM.CURSED_TREE, nil)
151 if player:getStorageValue(_SYSTEM.WARZONE) > 00 then
152 return true
153 end
154 if _DEBUG_MODE then
155 print("[CREATURESCRIPT - PREPARE DEATH] " ..player:getName())
156 end
157
158 if player:getStorageValue(_QUESTLOG[166].UID_01) == 02 then
159 player:setStorageValue(_QUESTLOG[166].UID_01, 01)
160 player:setStorageValue(10993, 00)
161
162
163 doBackpack(player, 12)
164 player:sendCancelMessage("@LoadQuestWindows")
165 end
166 if player:getStorageValue(_QUESTLOG[169].UID_01) > 01 and player:getStorageValue(_QUESTLOG[169].UID_01) < 100 then
167 player:setStorageValue(_QUESTLOG[169].UID_01, 01)
168
169
170 doBackpack(player, 12)
171 player:sendCancelMessage("@LoadQuestWindows")
172 end
173 if player:getStorageValue(_QUESTLOG[188].UID_01) == 02 or player:getStorageValue(_QUESTLOG[188].UID_01) == 03 then
174 player:setStorageValue(_QUESTLOG[188].UID_01, 01)
175
176
177 doBackpack(player, 12)
178 player:sendCancelMessage("@LoadQuestWindows")
179 end
180 if player:getStorageValue(_QUESTLOG[197].UID_01) == 03 then
181 player:setStorageValue(_QUESTLOG[197].UID_01, 02)
182
183
184 doBackpack(player, 12)
185 player:sendCancelMessage("@LoadQuestWindows")
186 end
187 if player:getStorageValue(_QUESTLOG[198].UID_01) == 02 then
188 player:setStorageValue(_QUESTLOG[198].UID_01, 01)
189
190
191 doBackpack(player, 12)
192 player:sendCancelMessage("@LoadQuestWindows")
193 end
194
195 player:setStorageValue(_SYSTEM.DANGEROUS[01][01].STORAGE, nil)
196 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
197 player:setStorageValue(_SYSTEM.TASK[00].TIMER, nil)
198 player:sendCancelMessage("@DGTime 0 0 0")
199 player:sendCancelMessage("@ResetDG")
200 player:setTown(Town(01))
201 local PenOrigin = 30
202 if player:getStorageValue(_SYSTEM.INVENTARIO[01].UID_01) == 1022 then
203 PenOrigin = 00
204 end
205 if player:getStorageValue(_SYSTEM.PENALIDADES[02]) > 00 then
206 if PenOrigin > 00 then
207 PenOrigin = PenOrigin - player:getStorageValue(_SYSTEM.PENALIDADES[02])
208 end
209
210 player:sendCancelMessage("@deadScreen 0 1")
211 else
212 local ExpTable = getExpForLevel((player:getLevel() + 1)) - getExpForLevel(player:getLevel())
213 local PenPercent = PenOrigin * (ExpTable / 100)
214
215 if player:getStorageValue(_SYSTEM.PENALIDADES[01]) < 01 then
216 player:setStorageValue(_SYSTEM.PENALIDADES[01], PenPercent)
217 else
218 local Penalidade_Total = (player:getStorageValue(_SYSTEM.PENALIDADES[01]) + PenPercent)
219 if Penalidade_Total > LIMITE_STORAGE then
220 player:setStorageValue(_SYSTEM.PENALIDADES[01], LIMITE_STORAGE)
221 else
222 player:setStorageValue(_SYSTEM.PENALIDADES[01], Penalidade_Total)
223 end
224 end
225
226 player:sendCancelMessage("@deadScreen " ..player:getStorageValue(_SYSTEM.PENALIDADES[01]).. " 0")
227 end
228 if player:getStorageValue(_SYSTEM.INVENTARIO[01].UID_01) == 1022 then
229 else
230 player:setStorageValue(_SYSTEM.PENALIDADES[02], nil)
231 player:setStorageValue(_SYSTEM.DEATH_COUNT, 1)
232 end
233
234 local playerGuid = player:getGuid()
235 local byPlayer = 0
236 local killerName
237 local lastHitUnjustified = false
238 if killer then
239 if killer:isPlayer() then
240 if not player:getSkull() then
241 lastHitUnjustified = true
242 end
243 byPlayer = 1
244 else
245 local master = killer:getMaster()
246 if master and master ~= killer and master:isPlayer() then
247 killer = master
248 if not player:getSkull() then
249 lastHitUnjustified = true
250 end
251 byPlayer = 1
252 end
253 end
254 killerName = killer:getName()
255 else
256 killerName = "field item"
257 end
258 local byPlayerMostDamage = 0
259 local mostDamageKillerName
260 for cid, damage in pairs(player:getDamageMap()) do
261 local killer = Creature(cid)
262 if killer and killer:isPlayer() then
263 byPlayerMostDamage = 1
264 mostDamageName = killer:getName()
265 elseif killer and killer:isMonster() then
266 mostDamageName = killer:getName()
267 else
268 mostDamageName = "field item"
269 end
270 break
271 end
272
273 local FirstDead = db.storeQuery("SELECT * FROM `player_deaths` WHERE `player_id` = " .. playerGuid)
274 if FirstDead then
275 --DELETE FROM `player_deaths` WHERE `player_id` = 19
276 else
277 player:setStorageValue(_SYSTEM.FIRST_DEAD_TUTOR, 01)
278 end
279
280 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 .. ", " .. (lastHitUnjustified and 1 or 0) .. ", " .. (mostDamageUnjustified and 1 or 0) .. ")")
281 local resultId = db.storeQuery("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. playerGuid)
282
283 local deathRecords = 0
284 local tmpResultId = resultId
285 while tmpResultId ~= false do
286 tmpResultId = result.next(resultId)
287 deathRecords = deathRecords + 1
288 end
289
290 if resultId ~= false then
291 result.free(resultId)
292 end
293
294 local limit = deathRecords - maxDeathRecords
295 if limit > 0 then
296 db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
297 end
298 if byPlayer == 1 then
299 local targetGuild = player:getGuild()
300 targetGuild = targetGuild and targetGuild:getId() or 0
301 if targetGuild ~= 0 then
302 local killerGuild = killer:getGuild()
303 killerGuild = killerGuild and killerGuild:getId() or 0
304 if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer:getId()) then
305 local warId = false
306 resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. ") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. "))")
307 if resultId ~= false then
308 warId = result.getNumber(resultId, "id")
309 result.free(resultId)
310 end
311
312 if warId ~= false then
313 db.asyncQuery("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(killerName) .. ", " .. db.escapeString(player:getName()) .. ", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. warId .. ")")
314 end
315 end
316 end
317 end
318 return false
319 end
320
321 return false
322end
323