trap.lua

main 75 lines · 1.8 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1local traps = {
2 [26028] = {transformTo = 26026, damage = {-500, -1000}},
3 [1510] = {transformTo = 1511, damage = {-50, -100}},
4 [1513] = {damage = {-50, -100}},
5 [2579] = {transformTo = 2578, damage = {-15, -30}},
6 [4208] = {transformTo = 4209, damage = {-15, -30}, type = COMBAT_EARTHDAMAGE}
7}
8
9function onStepIn(creature, item, position, fromPosition)
10 local trap = traps[item.itemid]
11 if not trap then
12 return true
13 end
14
15 if item.itemid == 26028 then
16 addEvent(onActiveTrap, 1000, creature.uid, item:getPosition(), item:getId())
17 return true
18 end
19
20 if creature:isMonster() then
21 doTargetCombat(0, creature, trap.type or COMBAT_PHYSICALDAMAGE, trap.damage[1], trap.damage[2], CONST_ME_NONE)
22 end
23
24 if trap.transformTo then
25 item:transform(trap.transformTo)
26 end
27 return true
28end
29
30function onActiveTrap(cid, pos, target)
31 local player = Player(cid)
32 local item = Tile(pos):getItemById(target)
33 if item then
34 item:transform(26026)
35 end
36 if player then
37 local playerTile = Tile(pos):getTopCreature()
38 if playerTile ~= nil then
39 if playerTile:isPlayer() then
40 doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, traps[26028].damage[1], traps[26028].damage[2], CONST_ME_NONE)
41 end
42 else
43 if item then
44 addEvent(transforTo, 1000, item:getPosition(), item:getId())
45 end
46 end
47 end
48end
49
50function transforTo(toPosition, itemId)
51 local item = Tile(toPosition):getItemById(itemId)
52 if item then
53 item:transform(26028)
54 end
55end
56
57function onStepOut(creature, item, position, fromPosition)
58 if item.itemid == 26026 then
59 item:transform(26028)
60 return true
61 end
62
63 item:transform(item.itemid - 1)
64 return true
65end
66
67function onRemoveItem(item, tile, position)
68 local itemPosition = item:getPosition()
69 if itemPosition:getDistance(position) > 0 then
70 item:transform(item.itemid - 1)
71 itemPosition:sendMagicEffect(CONST_ME_POFF)
72 end
73 return true
74end
75
Top