Unknown Soldier
Mapping a map
- Joined
- Oct 30, 2010
- Messages
- 307
- Solutions
- 11
- Reaction score
- 688
Hello,
recently, after some chanegs in my script, I have noticed some crashes. Crash happens ocassionally while using the following script, so entering the boss area, usually after a fight or at the very end of it, or few seconds after player leaves the arena and enters it again. I blame addEvent, but have no crashlog yet, can somebody just take a look at this poorly written script and find possible cause? Maybe for somebody it would be an obvious thing, if not I will try to get crashlog. TFS 1.4.2.
Thanks in advance
recently, after some chanegs in my script, I have noticed some crashes. Crash happens ocassionally while using the following script, so entering the boss area, usually after a fight or at the very end of it, or few seconds after player leaves the arena and enters it again. I blame addEvent, but have no crashlog yet, can somebody just take a look at this poorly written script and find possible cause? Maybe for somebody it would be an obvious thing, if not I will try to get crashlog. TFS 1.4.2.
Thanks in advance
Lua:
local bossConfig = {
[50074] = { -- ActionID
requiredLevel = 400,
minPlayersRequired = 1,
fromPos = {x = 2446, y = 1720, z = 9}, --position needed for reward chest to be removed
toPos = {x = 2473, y = 1743, z = 9},
boss = "Embertacle",
playerStorage = 60095, -- storage counting the time, number of hours between fights
playerQuestStorage = 60084, --storage, which will allow player to enter the room
teleportPosition = Position(2451, 1738, 9),
centerRoomPosition = Position(2460, 1732, 9),
northRange = 18,
eastRange = 18,
southRange = 18,
westRange = 18,
exit = Position(2457, 1734, 7),
bossPosition = Position(2460, 1732, 9),
time = 2, --fight time in minutes, 0.1 = 6 seconds
timebetweenfights = 0.0005, --in hours, 20 as default, 0.1 = 6 minutes
playerPositions = {
[1] = Position(2464, 1732, 7),
[2] = Position(2464, 1733, 7),
[3] = Position(2464, 1734, 7),
[4] = Position(2464, 1735, 7),
[5] = Position(2464, 1736, 7)
}
}
}
local function resetBoss_embertacle(bossConfig, bossId)
local spectators = Game.getSpectators(bossConfig.centerRoomPosition,false,true,bossConfig.westRange,bossConfig.eastRange,bossConfig.northRange,bossConfig.southRange)
for i = 1, #spectators do
spectators[i]:teleportTo(bossConfig.exit)
spectators[i]:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Time's up.")
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == 1946 then
local bossConfig = bossConfig[item:getActionId()]
if not bossConfig then
return false
end
local spectators2 = Game.getSpectators(bossConfig.centerRoomPosition,false,true,bossConfig.westRange,bossConfig.eastRange,bossConfig.northRange,bossConfig.southRange)
if #spectators2 >= 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The arena is occupied. Please wait for your turn.")
return true
else
--removing all "old" creatures from arena
local monsters = {}
for x = bossConfig.fromPos.x, bossConfig.toPos.x do
for y = bossConfig.fromPos.y, bossConfig.toPos.y do
for z = bossConfig.fromPos.z, bossConfig.toPos.z do
local v = getTopCreature({x=x, y=y, z=z})
if v.type == 1 then
return
elseif v.type == 2 then
table.insert(monsters, v.uid)
end
end
end
end
for i = 1, #monsters do
doRemoveCreature(monsters[i])
end
--removing reward chest
iterateArea(
function(position)
local tile = Tile(position)
if not tile then
return
end
local items = tile:getItems()
if items then
for i = 1, #items do
local checkitem = items[i]
if checkitem:getId() == 18472 then
local item = items[i]
item:remove()
end
end
end
end,
Position(bossConfig.fromPos.x, bossConfig.fromPos.y, bossConfig.fromPos.z),
Position(bossConfig.toPos.x, bossConfig.toPos.y, bossConfig.toPos.z)
)
stopEvent(resetBossEvent_embertacle)
local errorMsg
local rPlayers = {}
for index, ipos in pairs(bossConfig.playerPositions) do
local playerTile = Tile(ipos):getTopCreature()
if playerTile then
if playerTile:isPlayer() then
if playerTile:getLevel() >= bossConfig.requiredLevel then
if playerTile:getStorageValue(bossConfig.playerStorage) <= os.time() then
if playerTile:getStorageValue(bossConfig.playerQuestStorage) >= 1 then
table.insert(rPlayers, playerTile:getId())
else
errorMsg = "One or more players have not acomplished required quest progress yet."
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, errorMsg)
return true
end
else
local cur_time, cur_storage = os.time(), player:getStorageValue(bossConfig.playerStorage)
if cur_storage > cur_time then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can enter again in " .. os.date("!%H hours %M minutes and %S seconds", cur_storage - cur_time) ..".")
else
errorMsg ="One or more players have already entered in the last " .. bossConfig.timebetweenfights .. " hours."
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, errorMsg)
return true
end
return true
end
else
errorMsg = "All the players need to be level " .. bossConfig.requiredLevel .. " or higher."
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, errorMsg)
return true
end
end
end
end
if (#rPlayers >= bossConfig.minPlayersRequired) then
for _, pid in pairs(rPlayers) do
local rplayer = Player(pid)
if rplayer:isPlayer() then
rplayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, ("You have " .. bossConfig.time .. " minutes to kill " .. bossConfig.boss .. "."))
for j = 1, 5 do
bossConfig.playerPositions[j]:sendMagicEffect(CONST_ME_POFF)
end
rplayer:teleportTo(bossConfig.teleportPosition)
rplayer:setStorageValue(bossConfig.playerStorage, os.time() + (bossConfig.timebetweenfights * 60 * 60)) --should be 20*60*60 for 20 hours
bossConfig.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
rplayer:setDirection(DIRECTION_NORTH)
end
end
local monster = Game.createMonster(bossConfig.boss, bossConfig.bossPosition)
resetBossEvent_embertacle = addEvent(resetBoss_embertacle, bossConfig.time * 60 * 1000, bossConfig, monster and monster.uid or 0)
else
if not errorMsg then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, ("You need at least %u player."):format(bossConfig.minPlayersRequired))
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, errorMsg)
end
return true
end
end
end
item:transform(item.itemid == 1946 and 1945 or 1946)
return true
end
Last edited: