1local EnableLoad = true
2local WaveCount = 00
3local condition = Condition(CONDITION_OUTFIT)
4local function onRewardPVP(cid, reward)
5 local player = Player(cid)
6 if player then
7 reward = reward * 02
8 if Game.getStorageValue(_GLOBAL_RANDOM.DAILY_EVENTS.STORAGE) == 05 then
9 reward = reward + reward
10 end
11 if player:getStorageValue(_SYSTEM.PVP_POINTS) < 00 then
12 player:setStorageValue(_SYSTEM.PVP_POINTS, reward)
13 else
14 player:setStorageValue(_SYSTEM.PVP_POINTS, (player:getStorageValue(_SYSTEM.PVP_POINTS) + reward))
15 end
16
17 player:sendCancelMessage("@LootMSG 3219 05 00 " ..reward)
18 doBackpack(player, 11)
19 end
20end
21local function onLoadPVPRoom(cid, step)
22 local player = Player(cid)
23 if player then
24 local A = Game.getStorageValue(_PVP_ROOM[01].CONTAGEM_PLAYER) or 0
25 local B = Game.getStorageValue(_PVP_ROOM[02].CONTAGEM_PLAYER) or 0
26 local C = Game.getStorageValue(_PVP_ROOM[03].CONTAGEM_PLAYER) or 0
27 local D = Game.getStorageValue(_PVP_ROOM[04].CONTAGEM_PLAYER) or 0
28 local E = Game.getStorageValue(_PVP_ROOM[05].CONTAGEM_PLAYER) or 0
29 local F = Game.getStorageValue(_PVP_ROOM[06].CONTAGEM_PLAYER) or 0
30
31 if step == 00 then
32 player:sendCancelMessage("@LoadPVP 01 " ..A.. " " ..B.. " " ..C.. " " ..D.. " " ..E.. " " ..F)
33 return false
34 end
35 if step == 01 then
36 if EnableLoad then
37 local players = Game.getPlayers()
38 for _, targetPlayer in ipairs(players) do
39 targetPlayer:sendCancelMessage("@LoadPVP 01 " ..A.. " " ..B.. " " ..C.. " " ..D.. " " ..E.. " " ..F)
40 end
41 else
42 onLoadPVPRoom(player, 00)
43 end
44 return false
45 end
46 end
47 return false
48end
49local function onBattleroyalZone(timer)
50 local id = 04
51 local DmgZone = 500
52 local ZoneEffect = 11
53 if Game.getStorageValue(_PVP_ROOM[00].BATTLE_PLAYER) == 01 then
54 Game.setStorageValue(_PVP_ROOM[00].BATTLE_PLAYER, nil)
55 local from = _PVP_ROOM[id].ARENA_POS[00].POS_X
56 local to = _PVP_ROOM[id].ARENA_POS[00].POS_Y
57 for A = from.x, to.x do
58 for B = from.y, to.y do
59 for C = from.z, to.z do
60 local tile = Tile(A, B, C)
61 if tile then
62 local creature = tile:getTopCreature()
63 if creature and creature:isPlayer() then
64 Game.setStorageValue(_PVP_ROOM[id].CONTAGEM_PLAYER, nil)
65 Game.setStorageValue(_PVP_ROOM[00].BATTLE_PLAYER, nil)
66 creature:setTown(Town(01))
67 creature:sendCancelMessage("@NoTeleport 00")
68 creature:sendCancelMessage("@CronOff")
69 creature:setStorageValue(_PVP_ROOM[00].PVP_SALA_ID, nil)
70 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, nil)
71 creature:teleportTo({x=3999, y=991, z=7})
72 creature:getPosition():sendMagicEffect(11)
73 onLoadPVPRoom(creature, 00)
74
75 onRewardPVP(creature, _PVP_ROOM[id].CRONOMETRO)
76
77 return true
78 end
79 end
80 end
81 end
82 end
83
84 return true
85 end
86 if WaveCount > 00 then
87 local from = _PVP_ROOM[id].WAVE[WaveCount].POS_X
88 local to = _PVP_ROOM[id].WAVE[WaveCount].POS_Y
89 for A = from.x, to.x do
90 for B = from.y, to.y do
91 for C = from.z, to.z do
92 local PosEffect = Position(A, B, C)
93 PosEffect:sendMagicEffect(ZoneEffect)
94 local tile = Tile(A, B, C)
95 if tile then
96 local creature = tile:getTopCreature()
97 if creature and creature:isPlayer() then
98 doTargetCombat(0, creature, COMBAT_PHYSICALDAMAGE, -DmgZone, -DmgZone, CONST_ME_NONE)
99 end
100 end
101 end
102 end
103 end
104 end
105 if WaveCount < 05 then
106 if timer > 00 then
107 timer = timer - 01
108 if timer == 60 then
109 local from = _PVP_ROOM[id].ARENA_POS[00].POS_X
110 local to = _PVP_ROOM[id].ARENA_POS[00].POS_Y
111 for A = from.x, to.x do
112 for B = from.y, to.y do
113 for C = from.z, to.z do
114 local tile = Tile(A, B, C)
115 if tile then
116 local creature = tile:getTopCreature()
117 if creature and creature:isPlayer() then
118
119 end
120 end
121 end
122 end
123 end
124 end
125 else
126 WaveCount = WaveCount + 01
127 addEvent(onBattleroyalZone, 1000, 300)
128 return true
129 end
130 addEvent(onBattleroyalZone, 1000, timer)
131 end
132end
133local function onPVPTimer(id)
134 Game.setStorageValue(_PVP_ROOM[id].CONTAGEM_PLAYER, nil)
135 local players = Game.getPlayers()
136 for _, creature in ipairs(players) do
137 if creature:getStorageValue(_PVP_ROOM[00].PVP_SALA_ID) == id then
138 creature:setTown(Town(01))
139 creature:removeCondition(CONDITION_OUTFIT)
140 creature:sendCancelMessage("@NoTeleport 00")
141 creature:sendCancelMessage("@CronOff")
142 creature:teleportTo({x=3999, y=991, z=7})
143 creature:getPosition():sendMagicEffect(11)
144 onLoadPVPRoom(creature, 00)
145
146 if id == 03 then
147 if creature:getStorageValue(_PVP_ROOM[00].TIME_ID) == 01 then
148 onRewardPVP(creature, _PVP_ROOM[id].CRONOMETRO)
149 end
150 else
151 if _PVP_ROOM[id].PLACAR[01] > _PVP_ROOM[id].PLACAR[02] then
152 if creature:getStorageValue(_PVP_ROOM[00].TIME_ID) == 02 then
153 onRewardPVP(creature, _PVP_ROOM[id].CRONOMETRO)
154 end
155 elseif _PVP_ROOM[id].PLACAR[02] > _PVP_ROOM[id].PLACAR[01] then
156 if creature:getStorageValue(_PVP_ROOM[00].TIME_ID) == 01 then
157 onRewardPVP(creature, _PVP_ROOM[id].CRONOMETRO)
158 end
159 end
160 end
161
162 -- DESAFIO
163 if creature:getStorageValue(_DESAFIOS[00].DESAFIO_ID) > 00 then
164 if id == 01 then
165 onPlayerDesafios(creature, 69, 01)
166 elseif id == 02 then
167 onPlayerDesafios(creature, 70, 01)
168 elseif id == 03 then
169 onPlayerDesafios(creature, 71, 01)
170 elseif id == 04 then
171 onPlayerDesafios(creature, 72, 01)
172 end
173 end
174 creature:setStorageValue(_PVP_ROOM[00].PVP_SALA_ID, nil)
175 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, nil)
176 end
177 end
178
179 if id == 04 then
180 Game.setStorageValue(_PVP_ROOM[00].BATTLE_PLAYER, nil)
181 end
182 stopEvent(_PVP_ROOM[id].ADDEVENT_TIMER)
183 _PVP_ROOM[id].ADDEVENT_TIMER = nil
184end
185local function onExhaustPVP(timer)
186 if timer > 00 then
187 timer = timer - 01
188 addEvent(onExhaustPVP, 1000, timer)
189 else
190 EnableLoad = true
191 end
192end
193local function onEnterPVP(id)
194 local lobPlayers = {}
195 local players = Game.getPlayers()
196 for X = 01, _PVP_ROOM[id].MAX_PLAYER do
197 for _, creature in ipairs(players) do
198 if creature:getLevel() == _PVP_ROOM[id].LOB_PLAYERS[X] then
199 creature:setTown(Town(_PVP_ROOM[id].TOWN_ID))
200 creature:sendCancelMessage("@NoTeleport 01")
201 creature:sendCancelMessage("@PVPCronometro ".. _PVP_ROOM[id].CRONOMETRO.. " 0")
202 creature:teleportTo(_PVP_ROOM[id].ARENA_POS[X])
203 creature:getPosition():sendMagicEffect(11)
204
205 if id == 01 then -- VERSUS
206 if X == 01 or X == 04 then
207 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 01)
208 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
209 condition:setTicks(-1)
210 creature:addCondition(condition)
211 end
212 if X == 02 or X == 03 then
213 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 02)
214 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
215 condition:setTicks(-1)
216 creature:addCondition(condition)
217 end
218 elseif id == 02 then -- ARENA
219 if X == 01 or X == 03 or X == 05 or X == 07 or X == 09 then
220 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 01)
221 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
222 condition:setTicks(-1)
223 creature:addCondition(condition)
224 end
225 if X == 02 or X == 04 or X == 06 or X == 08 or X == 10 then
226 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 02)
227 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
228 condition:setTicks(-1)
229 creature:addCondition(condition)
230 end
231 elseif id == 03 then -- CASTLE WAR
232 if X == 01 or X == 03 or X == 05 or X == 07 or X == 09 or X == 11 or X == 13 or X == 15 or X == 17 or X == 19 then
233 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 01)
234 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
235 condition:setTicks(-1)
236 creature:addCondition(condition)
237 end
238 if X == 02 or X == 04 or X == 06 or X == 08 or X == 10 or X == 12 or X == 14 or X == 16 or X == 18 or X == 20 then
239 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 02)
240 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
241 condition:setTicks(-1)
242 creature:addCondition(condition)
243 end
244 elseif id == 05 then -- WARZONE
245 if X == 01 or X == 03 or X == 05 or X == 07 or X == 09 or X == 11 or X == 13 or X == 15 or X == 17 or X == 19 or X == 21 or X == 23 or X == 25 or X == 27 or X == 29 then
246 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 01)
247 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
248 condition:setTicks(-1)
249 creature:addCondition(condition)
250 end
251 if X == 02 or X == 04 or X == 06 or X == 08 or X == 10 or X == 12 or X == 14 or X == 16 or X == 18 or X == 20 or X == 22 or X == 24 or X == 26 or X == 28 or X == 30 then
252 creature:setStorageValue(_PVP_ROOM[00].TIME_ID, 02)
253 condition:setOutfit({lookType = creature:getOutfit().lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = creature:getOutfit().lookAddons})
254 condition:setTicks(-1)
255 creature:addCondition(condition)
256 end
257 end
258 end
259 end
260 end
261
262 _PVP_ROOM[id].PLACAR[01] = 00
263 _PVP_ROOM[id].PLACAR[02] = 00
264 _PVP_ROOM[id].ADDEVENT_TIMER = addEvent(onPVPTimer, _PVP_ROOM[id].CRONOMETRO * 60 * 1000, id)
265 if id == 03 then
266 local MON_POS = {
267 [01] = {POS = {x=4092, y=1149, z=7}},
268 [02] = {POS = {x=4092, y=1186, z=7}},
269 [03] = {POS = {x=4093, y=1165, z=6}},
270 [04] = {POS = {x=4093, y=1167, z=6}},
271 [05] = {POS = {x=4093, y=1169, z=6}},
272 [06] = {POS = {x=4091, y=1167, z=4}},
273 }
274 for _MON = 01, #MON_POS do
275 local tile = Tile(MON_POS[_MON].POS.x, MON_POS[_MON].POS.y, MON_POS[_MON].POS.z)
276 local creature = tile:getTopCreature()
277 if creature and creature:isMonster() then
278 doRemoveCreature(creature:getId())
279 end
280 Game.createMonster('Castle Barrier', MON_POS[_MON].POS, false, true)
281 end
282 end
283 if id == 04 then
284 Game.setStorageValue(_PVP_ROOM[00].BATTLE_PLAYER, _PVP_ROOM[id].MAX_PLAYER)
285 WaveCount = 00
286 onBattleroyalZone(301)
287 end
288
289end
290function onSay(player, words, param)
291 local split = param:splitTrimmed(" ")
292 local SALA_PVP_ID = tonumber(split[01])
293 if split[01] == "00" then
294 onLoadPVPRoom(player, 00)
295 return false
296 end
297
298 if SALA_PVP_ID > 00 and SALA_PVP_ID <= #_PVP_ROOM then
299 if player:getStorageValue(_PVP_ROOM[00].PVP_SALA_ID) > 00 or player:getStorageValue(_SYSTEM.DANGEROUS[01][01].STORAGE) > 0 or player:getStorageValue(_SYSTEM.WARZONE) > 00 then
300
301 return false
302 end
303 local COUNT_PLAYER = Game.getStorageValue(_PVP_ROOM[SALA_PVP_ID].CONTAGEM_PLAYER) or 00
304 if COUNT_PLAYER < 00 then
305 COUNT_PLAYER = 00
306 end
307
308 if COUNT_PLAYER == (_PVP_ROOM[SALA_PVP_ID].MAX_PLAYER - 01) then
309 if SALA_PVP_ID < 06 then
310 player:setStorageValue(_PVP_ROOM[00].PVP_SALA_ID, SALA_PVP_ID)
311 Game.setStorageValue(_PVP_ROOM[SALA_PVP_ID].CONTAGEM_PLAYER, _PVP_ROOM[SALA_PVP_ID].MAX_PLAYER)
312 player:teleportTo(_PVP_ROOM[SALA_PVP_ID].INN)
313 table.insert(_PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS, player:getLevel())
314 table.sort(_PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS, function(a, b) return a > b end)
315 onEnterPVP(SALA_PVP_ID)
316 else
317 Game.setStorageValue(_PVP_ROOM[SALA_PVP_ID].CONTAGEM_PLAYER, (COUNT_PLAYER + 01))
318 player:setStorageValue(_PVP_ROOM[00].PVP_SALA_ID, SALA_PVP_ID)
319 player:teleportTo(_PVP_ROOM[SALA_PVP_ID].INN)
320
321 player:getPosition():sendMagicEffect(11)
322 player:setTown(Town(_PVP_ROOM[SALA_PVP_ID].TOWN_ID))
323 player:sendCancelMessage("@NoTeleport 01")
324 player:sendCancelMessage("@EnablePVPMode")
325 end
326 elseif COUNT_PLAYER >= _PVP_ROOM[SALA_PVP_ID].MAX_PLAYER then
327 player:getPosition():sendMagicEffect(03)
328 return false
329 else
330 Game.setStorageValue(_PVP_ROOM[SALA_PVP_ID].CONTAGEM_PLAYER, (COUNT_PLAYER + 01))
331 player:setStorageValue(_PVP_ROOM[00].PVP_SALA_ID, SALA_PVP_ID)
332 player:teleportTo(_PVP_ROOM[SALA_PVP_ID].INN)
333
334 player:getPosition():sendMagicEffect(11)
335 if SALA_PVP_ID < 06 then
336 if Game.getStorageValue(_PVP_ROOM[SALA_PVP_ID].CONTAGEM_PLAYER) == 01 then
337 for k in pairs (_PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS) do
338 _PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS [k] = nil
339 end
340 else
341 table.sort(_PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS, function(a, b) return a > b end)
342 end
343 table.insert(_PVP_ROOM[SALA_PVP_ID].LOB_PLAYERS, player:getLevel())
344
345 else
346 player:setTown(Town(_PVP_ROOM[SALA_PVP_ID].TOWN_ID))
347 player:sendCancelMessage("@NoTeleport 01")
348 player:sendCancelMessage("@EnablePVPMode")
349 end
350 end
351 end
352
353 onLoadPVPRoom(player, 01)
354 onExhaustPVP(03)
355 EnableLoad = false
356 return false
357end