-
-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathclosing_door.lua
132 lines (107 loc) · 3.28 KB
/
closing_door.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- Level and quests closing door (onStepIn).
-- This prevents a player who has not yet done the quest, from crossing the player who has already done so, skipping the entire quest and going straight to the final reward.
local doorIds = {}
local closingDoor = MoveEvent()
closingDoor:type("stepin")
for index, value in ipairs(QuestDoorTable) do
if not table.contains(doorIds, value.openDoor) then
table.insert(doorIds, value.openDoor)
end
end
for index, value in ipairs(LevelDoorTable) do
if not table.contains(doorIds, value.openDoor) then
table.insert(doorIds, value.openDoor)
end
end
function closingDoor.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return
end
for index, value in ipairs(QuestDoorTable) do
if value.openDoor == item.itemid then
if player:getStorageValue(item.actionid) ~= -1 then
return true
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
player:teleportTo(fromPosition, true)
return false
end
end
end
for index, value in ipairs(LevelDoorTable) do
if value.openDoor == item.itemid then
if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
return true
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Only the worthy may pass.")
player:teleportTo(fromPosition, true)
return false
end
end
end
return true
end
for index, value in ipairs(doorIds) do
closingDoor:id(value)
end
closingDoor:register()
-- Level and quests closing door (onStepOut).
-- This closes the door after the player passes through it.
local doorIds = {}
local closingDoor = MoveEvent()
closingDoor:type("stepout")
for index, value in ipairs(QuestDoorTable) do
if not table.contains(doorIds, value.openDoor) then
table.insert(doorIds, value.openDoor)
end
end
for index, value in ipairs(LevelDoorTable) do
if not table.contains(doorIds, value.openDoor) then
table.insert(doorIds, value.openDoor)
end
end
function closingDoor.onStepOut(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return
end
local tile = Tile(position)
if tile:getCreatureCount() > 0 then
return true
end
local newPosition = { x = position.x + 1, y = position.y, z = position.z }
local query = Tile(newPosition):queryAdd(creature)
if query ~= RETURNVALUE_NOERROR or query == RETURNVALUE_NOTENOUGHROOM then
newPosition.x = newPosition.x - 1
newPosition.y = newPosition.y + 1
query = Tile(newPosition):queryAdd(creature)
end
if query == RETURNVALUE_NOERROR or query ~= RETURNVALUE_NOTENOUGHROOM then
position:relocateTo(newPosition)
end
local i, tileItem, tileCount = 1, true, tile:getThingCount()
while tileItem and i < tileCount do
tileItem = tile:getThing(i)
if tileItem and tileItem:getUniqueId() ~= item.uid and tileItem:getType():isMovable() then
tileItem:remove()
else
i = i + 1
end
end
for index, value in ipairs(LevelDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
end
end
for index, value in ipairs(QuestDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
end
end
return true
end
for index, value in ipairs(doorIds) do
closingDoor:id(value)
end
closingDoor:register()