endziu2222
New Member
- Joined
- Nov 2, 2010
- Messages
- 49
- Reaction score
- 3
So i have been trying to sort this script out and all the time does same thing it detects if players are inside but when players leave/die before they kill boss. Another group enters and still have to face previous boss and one that spawn for them. I am using otx revsript server. (cooldown was done on purpose so I don't have to change it every time I test)
and this is player_death_lua
Anybody had this problem with bosses? It seems to happen with all sort of scripts including anhilator.
Lua:
local bossConfig = {
[25550] = { -- ActionID
requiredLevel = 250,
minPlayersRequired = 1,
boss = "Megasylvan Yselda",
bossGlobalStorage = 25567,
playerStorage = 25568,
teleportPosition = Position(1845, 1972, 14),
centerRoomPosition = Position(1845, 1972, 14),
northRange = 9, eastRange = 12, southRange = 11, westRange = 10,
exit = Position(1854, 1933, 14),
bossPosition = Position(1846, 1975, 14),
time = 15,
playerPositions = {
[1] = Position(1854, 1927, 14),
[2] = Position(1854, 1928, 14),
[3] = Position(1854, 1929, 14),
[4] = Position(1854, 1930, 14),
[5] = Position(1854, 1931, 14)
}
}
}
local function resetBoss(bossConfigData, bossId)
local monster = Monster(bossId)
if monster then
monster:remove()
end
local spectators = Game.getSpectators(bossConfigData.centerRoomPosition, false, true, bossConfigData.westRange, bossConfigData.eastRange, bossConfigData.northRange, bossConfigData.southRange)
local playersNearby = false
for i = 1, #spectators do
if spectators[i]:isPlayer() then
playersNearby = true
break
end
end
if not playersNearby then
for i = 1, #spectators do
spectators[i]:teleportTo(bossConfigData.exit)
end
setGlobalStorageValue(bossConfigData.bossGlobalStorage, 0) -- Reset the global storage
end
end
local function startBossFight(player, bossConfigData)
local errorMsg
local rPlayers = {}
-- Check for nearby players
local playersNearby = false
local nearbyPlayers = Game.getSpectators(bossConfigData.centerRoomPosition, false, true, 15, 15, 15, 15)
for _, nearbyPlayer in ipairs(nearbyPlayers) do
if nearbyPlayer:isPlayer() then
playersNearby = true
break
elseif nearbyPlayer:isMonster() then
nearbyPlayer:remove()
end
end
if playersNearby then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Wait until it's your turn.")
return
end
local bossId = getGlobalStorageValue(bossConfigData.bossGlobalStorage)
-- Check if there is already a boss
if bossId > 0 then
local existingBoss = Monster(bossId)
if existingBoss then -- Check if existingBoss is not nil
-- Remove the existing boss
existingBoss:remove()
end
-- Reset the global storage
setGlobalStorageValue(bossConfigData.bossGlobalStorage, 0)
end
for index, ipos in pairs(bossConfigData.playerPositions) do
local playerTile = Tile(ipos):getTopCreature()
if playerTile then
if playerTile:isPlayer() then
if playerTile:getLevel() >= bossConfigData.requiredLevel then
if playerTile:getStorageValue(bossConfigData.playerStorage) <= os.time() then
table.insert(rPlayers, playerTile:getId())
else
errorMsg = 'One or more players have already entered in the last 20 hours.'
end
else
errorMsg = 'All the players need to be level ' .. bossConfigData.requiredLevel .. ' or higher.'
end
end
end
end
if #rPlayers >= bossConfigData.minPlayersRequired then
for _, pid in pairs(rPlayers) do
local rplayer = Player(pid)
if rplayer:isPlayer() then
rplayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, ('You have %o minutes before you get kicked out.'):format(bossConfigData.time))
bossConfigData.playerPositions[_]:sendMagicEffect(CONST_ME_POFF)
rplayer:teleportTo(bossConfigData.teleportPosition)
rplayer:setStorageValue(bossConfigData.playerStorage, os.time() + (10))
bossConfigData.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
rplayer:setDirection(DIRECTION_NORTH)
end
end
setGlobalStorageValue(bossConfigData.bossGlobalStorage, 1)
addEvent(setGlobalStorageValue, bossConfigData.time * 60 * 1000, bossConfigData.bossGlobalStorage, 0)
local monster = Game.createMonster(bossConfigData.boss, bossConfigData.bossPosition)
addEvent(resetBoss, bossConfigData.time * 60 * 1000, bossConfigData, monster and monster:getId() or 0)
else
if not errorMsg then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, ("You need %u players."):format(bossConfigData.minPlayersRequired))
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, errorMsg)
end
end
end
local secretBrokul = Action()
function secretBrokul.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local bossConfigData = bossConfig[item:getActionId()]
if not bossConfigData then
return false
end
if item.itemid == 2772 then
-- Check if there is already a boss
local bossId = getGlobalStorageValue(bossConfigData.bossGlobalStorage)
if bossId > 0 then
local existingBoss = Monster(bossId)
if existingBoss then -- Check if existingBoss is not nil
-- Remove the existing boss
existingBoss:remove()
end
-- Reset the global storage
setGlobalStorageValue(bossConfigData.bossGlobalStorage, 0)
end
-- Spawn the boss and start the boss fight
startBossFight(player, bossConfigData)
else
item:transform(item.itemid == 2773 and 2772 or 2773)
end
return true
end
secretBrokul:aid(25550)
secretBrokul:register()
and this is player_death_lua
Code:
local deathListEnabled = true
local playerDeath = CreatureEvent("PlayerDeath")
function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
if not deathListEnabled then
return
end
local byPlayer = 0
local killerName = "unknown" -- Default value
if killer ~= nil then
if killer:isPlayer() then
byPlayer = 1
killerName = killer:getName()
else
local master = killer:getMaster()
if master and master ~= killer and master:isPlayer() then
killer = master
byPlayer = 1
killerName = killer:getName()
elseif killer:isMonster() and killer:getType() then
-- Check if the creature type has a getNameDescription method
if killer:getType().getNameDescription then
killerName = killer:getType():getNameDescription()
else
killerName = killer:getName()
end
end
end
end
local byPlayerMostDamage = 0
local mostDamageKillerName = "unknown" -- Default value
if mostDamageKiller ~= nil then
if mostDamageKiller:isPlayer() then
byPlayerMostDamage = 1
mostDamageKillerName = mostDamageKiller:getName()
elseif mostDamageKiller:isMonster() and mostDamageKiller:getType() then
-- Check if the creature type has a getNameDescription method
if mostDamageKiller:getType().getNameDescription then
mostDamageKillerName = mostDamageKiller:getType():getNameDescription()
else
mostDamageKillerName = mostDamageKiller:getName()
end
end
end
-- Rest of your code remains the same
-- ...
local playerGuid = player:getGuid()
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 .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ')')
-- Start Webhook Player Death
local playerName = player:getName()
local playerLevel = player:getLevel()
local killerLink = string.gsub(killerName, "%s+", "+")
local playerLink = string.gsub(playerName, "%s+", "+")
local serverURL = getConfigInfo("url")
if killer and killer:isPlayer() then
Webhook.sendMessage(playerName .. " just got killed!", "**[" .. playerName .. "](" .. serverURL .. "/?characters/" .. playerLink .. ")** got killed at level " .. playerLevel .. " by **[" .. killerName .. "](" .. serverURL .. "/?characters/" .. killerLink .. ")**", WEBHOOK_COLOR_OFFLINE, announcementChannels["player-kills"])
else
Webhook.sendMessage(playerName .. " has just died!", "**[" .. playerName .. "](" .. serverURL .. "/?characters/" .. playerLink .. ")** died at level " .. playerLevel .. " by " .. killerName, WEBHOOK_COLOR_WARNING, announcementChannels["player-kills"])
end
-- End Webhook Player Death
local deathRecords = 0
local tmpResultId = resultId
while tmpResultId ~= false do
tmpResultId = Result.next(resultId)
deathRecords = deathRecords + 1
end
if resultId ~= false then
Result.free(resultId)
end
if byPlayer == 1 then
local targetGuild = player:getGuild()
targetGuild = targetGuild and targetGuild:getId() or 0
if targetGuild ~= 0 then
local killerGuild = killer:getGuild()
killerGuild = killerGuild and killerGuild:getId() or 0
if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(player:getId(), killer.uid) then
local warId = false
resultId = db.storeQuery('SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND \z
((`guild1` = ' .. killerGuild .. ' AND `guild2` = ' .. targetGuild .. ') OR \z
(`guild1` = ' .. targetGuild .. ' AND `guild2` = ' .. killerGuild .. '))')
if resultId ~= false then
warId = Result.getNumber(resultId, 'id')
Result.free(resultId)
end
if warId ~= false then
db.asyncQuery('INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) \z
VALUES (' .. db.escapeString(killerName) .. ', ' .. db.escapeString(player:getName()) .. ', ' .. killerGuild .. ', \z
' .. targetGuild .. ', ' .. os.time() .. ', ' .. warId .. ')')
end
end
end
end
end
playerDeath:register()
Anybody had this problem with bosses? It seems to happen with all sort of scripts including anhilator.