• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[0.4 Lua] Boss dynamic attacks

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, otlanders i was wondering if someone could help me to build a script with these characteristics.

1-.Boss teleport to certain waypoints with 10% chance (on battle)
2-.Boss can teleport all players on room after reaching 50% HP
3-.Boss revive once after dead (no corpse until second death)
4-.Boss has 10% chance to teleport a player inside the battle room.

Its a cool idea to make boss battles more dynamic.

I am using TFS 0.4 REV 3777
 
Everything untested tested.

monsterfile.xml
XML:
<script>
   <event name="nameOfThisEvent"/>
</script>
data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="nameOfThisEvent" event="script" value="file_name.lua"/>

[1]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_waypoints = {
   {75, {x = 1000, y = 1000, z = 7}}, -- {hp_threshold, {new_pos}},
   {60, {x = 1000, y = 1000, z = 7}}, -- highest
   {45, {x = 1000, y = 1000, z = 7}}, -- to
   {30, {x = 1000, y = 1000, z = 7}}, -- lowest
   {15, {x = 1000, y = 1000, z = 7}}  -- thresholds
}
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

local function tp_thing(cid, position)
   doTeleportThing(cid, position)
   return true
end

function onStatsChange(cid, attacker, type, combat, value)
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x or cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y or cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z or cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- it's the correct monster, let's start tracking it
       boss_temp[cid] = 1
  
   -- if no more thesholds
   elseif boss_temp[cid] == 0 then
       return true
   end
   -- check if boss has reached an hp_threshold
   -- if (1% of total hp * threshold) <= (current_hp - damage about to be taken) then
   if getCreatureMaxHealth(cid) / 100 * boss_waypoints[boss_temp[cid]][1] >= getCreatureHealth(cid) - value then
       addEvent(tp_thing, 0, cid, boss_waypoints[boss_temp[cid]][2])
       boss_temp[cid] = boss_temp[cid] + 1
       -- check if more thresholds
       if boss_temp[cid] > #boss_waypoints then
           boss_temp[cid] = 0
       end
       return true
   end
  
   return true
end

[2]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_hp_threshold = 50
local players_new_position = {x = 1000, y = 1000, z = 7}
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

local function tp_thing(cid)
   doTeleportThing(cid, players_new_position)
   return true
end

function onStatsChange(cid, attacker, type, combat, value)
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x or cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y or cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z or cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- it's the correct monster, let's start tracking it
       boss_temp[cid] = 0
 
   -- to ensure players aren't teleported twice.
   elseif boss_temp[cid] == 1 then
       return true
   end
 
   -- check if boss has reached an hp_threshold
   -- if (1% of total hp * threshold) <= (current_hp - damage about to be taken) then
   if getCreatureMaxHealth(cid) / 100 * boss_hp_threshold >= getCreatureHealth(cid) - value then
       for _, pid in ipairs(getPlayersOnline()) do
           local pid_pos = getThingPos(pid)
           if pid_pos.x >= boss_battle_area[1].x and pid_pos.x <= boss_battle_area[2].x then
               if pid_pos.y >= boss_battle_area[1].y and pid_pos.y <= boss_battle_area[2].y then
                   if pid_pos.z <= boss_battle_area[1].z and pid_pos.z >= boss_battle_area[2].z then
                       addEvent(tp_thing, 0, pid)
                   end
               end
           end
       end
       boss_temp[cid] = boss_temp[cid] + 1
       return true
   end
 
   return true
end

[3]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

function onStatsChange(cid, attacker, type, combat, value)
   -- if boss has not been killed before
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- check if it's about to die
       if value == getCreatureHealth(cid) then
           doCreatureSay(cid, "Round 2\nAre you ready?", TALKTYPE_ORANGE_1)
           doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
           boss_temp[cid] = 0
           return false
       end
   end
   return true
end

[4]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

local function tp_thing(cid)
   doTeleportThing(cid, random_positions[math.random(#random_positions)])
   return true
end
function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if isPlayer(attacker) then
       if math.random(100) <= boss_chance_to_teleport then
           addEvent(tp_thing, 0, attacker)
       end
   end
   return true
end
 
Last edited:
Everything untested.

monsterfile.xml
XML:
<script>
   <event name="nameOfThisEvent"/>
</script>
data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="nameOfThisEvent" event="script" value="file_name.lua"/>

[1]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_waypoints = {
   {75, {x = 1000, y = 1000, z = 7}}, -- {hp_threshold, {new_pos}},
   {60, {x = 1000, y = 1000, z = 7}}, -- highest
   {45, {x = 1000, y = 1000, z = 7}}, -- to
   {30, {x = 1000, y = 1000, z = 7}}, -- lowest
   {15, {x = 1000, y = 1000, z = 7}}  -- thresholds
}
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

function onStatsChange(cid, attacker, type, combat, value)
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- it's the correct monster, let's start tracking it
       boss_temp[cid] = 1
   end
 
   -- check if boss has reached an hp_threshold
   -- if (1% of total hp * threshold) <= (current_hp - damage about to be taken) then
   if getCreatureMaxHealth(cid) / 100 * boss_waypoints[boss_temp[cid]][1] <= getCreatureHealth(cid) - value then
       doTeleportThing(cid, boss_waypoints[boss_temp[cid]][2], true)
       boss_temp[cid] = boss_temp[cid] + 1
       return true
   end
 
   return true
end

[2]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_hp_threshold = 50
local players_new_position = {x = 1000, y = 1000, z = 7}
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

function onStatsChange(cid, attacker, type, combat, value)
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- it's the correct monster, let's start tracking it
       boss_temp[cid] = 0
 
   -- to ensure players aren't teleported twice.
   elseif boss_temp[cid] == 1
       return true
   end
 
   -- check if boss has reached an hp_threshold
   -- if (1% of total hp * threshold) <= (current_hp - damage about to be taken) then
   if getCreatureMaxHealth(cid) / 100 * boss_hp_threshold <= getCreatureHealth(cid) - value then
       for _, pid in ipairs(getPlayersOnline()) do
           local pid_pos = getThingPos(pid)
           if pid_pos.x >= boss_battle_area[1].x and pid_pos.x <= boss_battle_area[2].x then
               if pid_pos.y >= boss_battle_area[1].y and pid_pos.y <= boss_battle_area[2].y then
                   if pid_pos.z <= boss_battle_area[1].z and pid_pos.z >= boss_battle_area[2].z then
                       doTeleportThing(pid, players_new_position, true)
                   end
               end
           end
       end
       boss_temp[cid] = boss_temp[cid] + 1
       return true
   end
 
   return true
end

[3]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_temp = {}
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}

function onStatsChange(cid, attacker, type, combat, value)
   -- if boss has not been killed before
   if boss_temp[cid] == nil then
       -- make sure it's a monster
       if not isMonster(cid) then
           return true
       end
       -- make sure it's losing health
       if type ~= STATSCHANGE_HEALTHLOSS then
           return true
       end
       -- ensure it's the correct monster
       if getCreatureName(cid):lower() ~= boss_name:lower() then
           return true
       end
       -- ensure the correct monster is in the specified area
       local cid_pos = getThingPos(cid)
       if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
           return true
       end
       if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
           return true
       end
       if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
           return true
       end
       -- check if it's about to die
       if value == getCreatureHealth(cid) then
           doCreatureSay(cid, "Round 2\nAre you ready?", TALKTYPE_ORANGE_1)
           doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
           boss_temp[cid] = 0
           return false
       end
   end
   return true
end

[4]
data/creaturescripts/scripts/file_name.lua
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if math.random(100) <= boss_chance_to_teleport then
       doTeleportThing(cid, random_positions[math.random(#random_positions)], true)
   end
   return true
end

wow, sir. you are awesome, gonna test your scripts :D!

I've tested the first one and last one and wont work properly, on first strike the boss teleport and crash the server

the second one has this error in console (might miss some parameter)

Code:
[16:24:14.742] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/boss/teleport2.lua:40: 'then' expected near 'return'
[16:24:14.743] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/boss/teleport2.lua)
[16:24:14.744] data/creaturescripts/scripts/boss/teleport2.lua:40: 'then' expected near 'return'

the third one works perfect.


 
Last edited:
Hope it all works good. :oops: :p

-- edit 1
-- Edited the first script in my original post to fix a small error I saw in script #1

-- edit 2
-- Edited script # 1 & #2 for similar bug, and fixed #2 line 40 issue

-- edit 3
-- Post below new or currently existing issues, thanks (I'm a bit confused where we stand)
 
Last edited:
Hope it all works good. :oops: :p

-- edit 1
-- Edited the first script in my original post to fix a small error I saw in script #1

-- edit 2
-- Edited script # 1 & #2 for similar bug, and fixed #2 line 40 issue

-- edit 3
-- Post below new or currently existing issues, thanks (I'm a bit confused where we stand)

i've tested them all, but still getting crashes from the 3 teleport scripts.
 
i've tested them all, but still getting crashes from the 3 teleport scripts.
try removing ", true" from the ending of each teleport thing?
It's [pushmove==true].. it shouldn't effect anything, but otherwise idk why all 3 of them would error otherwise.
Lua:
doTeleportThing(cid, position, true)
doTeleportThing(cid, position)

-- edit
Fixed small error in #4, and added a check to ensure only players get teleported

Also removed above ", true" 's, in case you weren't sure what to do
 
Last edited:
try removing ", true" from the ending of each teleport thing?
It's [pushmove==true].. it shouldn't effect anything, but otherwise idk why all 3 of them would error otherwise.
Lua:
doTeleportThing(cid, position, true)
doTeleportThing(cid, position)

-- edit
Fixed small error in #4, and added a check to ensure only players get teleported

Also removed above ", true" 's, in case you weren't sure what to do

sometimes they work but then it crashes. (almost always)
 
sometimes they work but then it crashes. (almost always)
If you greentext the teleport line, does it still crash?

If all 3 scripts stop crashing after greentexting the line, I may have a solution. (which makes no sense why it's required, but I'll script it anyway.)
 
If you greentext the teleport line, does it still crash?

If all 3 scripts stop crashing after greentexting the line, I may have a solution. (which makes no sense why it's required, but I'll script it anyway.)

what do you mean by "greentexting" are those the <!--comments?-->
 
what do you mean by "greentexting" are those the <!--comments?-->
Yes.
It stops the script from looking at that part of the script.
Lua:
doTeleportThing(attacker, random_positions[math.random(#random_positions)])
-- doTeleportThing(attacker, random_positions[math.random(#random_positions)])

--[[
multiple line greentext
:)
]]
 
Yes.
It stops the script from looking at that part of the script.
Lua:
doTeleportThing(attacker, random_positions[math.random(#random_positions)])
-- doTeleportThing(attacker, random_positions[math.random(#random_positions)])

--[[
multiple line greentext
:)
]]
so it must be like this?

Code:
local boss_chance_to_teleport = 90
local boss_name = "Princess Lumelia"
local boss_battle_area = {
   {x = 908, y = 123, z = 6}, -- top left
   {x = 941, y = 144, z = 6} -- bottom right
}
local random_positions = {
   {x = 925, y = 128, z = 6},
   {x = 914, y = 139, z = 6},
   {x = 937, y = 141, z = 6}
}
function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if isPlayer(attacker) then
       if math.random(100) <= boss_chance_to_teleport then
           doTeleportThing(attacker, random_positions[math.random(#random_positions)])
-- doTeleportThing(attacker, random_positions[math.random(#random_positions)])
--[[
multiple line greentext
:)
]]
       end
   end
   return true
end
 
so it must be like this?

Code:
local boss_chance_to_teleport = 90
local boss_name = "Princess Lumelia"
local boss_battle_area = {
   {x = 908, y = 123, z = 6}, -- top left
   {x = 941, y = 144, z = 6} -- bottom right
}
local random_positions = {
   {x = 925, y = 128, z = 6},
   {x = 914, y = 139, z = 6},
   {x = 937, y = 141, z = 6}
}
function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if isPlayer(attacker) then
       if math.random(100) <= boss_chance_to_teleport then
           doTeleportThing(attacker, random_positions[math.random(#random_positions)])
-- doTeleportThing(attacker, random_positions[math.random(#random_positions)])
--[[
multiple line greentext
:)
]]
       end
   end
   return true
end
._. I was showing you the difference between non-green text and greentext. lol

do like this.
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if isPlayer(attacker) then
       if math.random(100) <= boss_chance_to_teleport then
           --doTeleportThing(attacker, random_positions[math.random(#random_positions)])
       end
   end
   return true
end
 
._. I was showing you the difference between non-green text and greentext. lol

do like this.
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   if not isMonster(cid) then
       return true
   end
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   -- teleport chance
   if isPlayer(attacker) then
       if math.random(100) <= boss_chance_to_teleport then
           --doTeleportThing(attacker, random_positions[math.random(#random_positions)])
       end
   end
   return true
end
ok, i got it. Done what you said and still crashing even after greentexting the teleport line.

This is the log what i do
1-.go to the battle room
2-. /m princess lumelia (my boss)
3-. start dealing damage
4-. crash


updated: the first script wont crash after greentexting.
 
Last edited:
ok, i got it. Done what you said and still crashing even after greentexting the teleport line.

This is the log what i do
1-.go to the battle room
2-. /m princess lumelia (my boss)
3-. start dealing damage
4-. crash

o_O
Okay, let's do step by step then.

Try each script step by step until it errors. (don't worry about the script working as intended.. just see when/if it crashes server or not)

-- also make sure this is only script running in the boss
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   -- teleport chance
   if isPlayer(attacker) then
       print("Player is attacking..")
       if math.random(100) <= boss_chance_to_teleport then
           print("teleporting player to random position..")
           doTeleportThing(attacker, random_positions[math.random(#random_positions)])
       end
   end
   print("Finished!")
   return true
end
 
o_O
Okay, let's do step by step then.

Try each script step by step until it errors. (don't worry about the script working as intended.. just see when/if it crashes server or not)

-- also make sure this is only script running in the boss
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   print("Finished!")
   return true
end
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   -- teleport chance
   if isPlayer(attacker) then
       print("Player is attacking..")
       if math.random(100) <= boss_chance_to_teleport then
           print("teleporting player to random position..")
           doTeleportThing(attacker, random_positions[math.random(#random_positions)])
       end
   end
   print("Finished!")
   return true
end

it printed everything well until last script

Code:
[18:27:55.792] [Error - CreatureScript Interface]
[18:27:55.795] data/creaturescripts/scripts/boss/teleport.lua:onStatsChange
[18:27:55.798] Description:
[18:27:55.804] data/creaturescripts/scripts/boss/teleport.lua:45: attempt to compare number with nil
[18:27:55.806] stack traceback:
[18:27:55.809]  data/creaturescripts/scripts/boss/teleport.lua:45: in function <data/creaturescripts/scripts/boss/teleport.lua:12>
got this error :eek:
 
it printed everything well until last script

Code:
[18:27:55.792] [Error - CreatureScript Interface]
[18:27:55.795] data/creaturescripts/scripts/boss/teleport.lua:onStatsChange
[18:27:55.798] Description:
[18:27:55.804] data/creaturescripts/scripts/boss/teleport.lua:45: attempt to compare number with nil
[18:27:55.806] stack traceback:
[18:27:55.809]  data/creaturescripts/scripts/boss/teleport.lua:45: in function <data/creaturescripts/scripts/boss/teleport.lua:12>
got this error :eek:
Can you show console messages?
Line 45 is a print for me.
(try with below script though)
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   print(cid)
   print(attacker)
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   -- teleport chance
   if isPlayer(attacker) then
       print("Player is attacking..")
       local rand = math.random(100)
       if rand <= boss_chance_to_teleport then
           print("teleporting player to random position..")
           rand = random_positions[math.random(#random_positions)]
           doTeleportThing(attacker, rand)
       end
   end
   print("Finished!")
   return true
end
 
Can you show console messages?
Line 45 is a print for me.
(try with below script though)
Lua:
local boss_chance_to_teleport = 10
local boss_name = "xikini"
local boss_battle_area = {
   {x = 1000, y = 1000, z = 7}, -- top left
   {x = 1000, y = 1000, z = 7} -- bottom right
}
local random_positions = {
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7},
   {x = 1000, y = 1000, z = 7}
}

function onStatsChange(cid, attacker, type, combat, value)
   print("Working..")
   print(cid)
   print(attacker)
   if not isMonster(cid) then
       return true
   end
   print("Is monster..")
   -- make sure it's losing health
   if type ~= STATSCHANGE_HEALTHLOSS then
       return true
   end
   print("Monster is losing health..")
   -- ensure it's the correct monster
   if getCreatureName(cid):lower() ~= boss_name:lower() then
       return true
   end
   print("" .. getCreatureName(cid):lower() .. " is correct creature name..")
   -- ensure the correct monster is in the specified area
   local cid_pos = getThingPos(cid)
   if cid_pos.x < boss_battle_area[1].x and cid_pos.x > boss_battle_area[2].x then
       return true
   end
   print("Within x parameter..")
   if cid_pos.y < boss_battle_area[1].y and cid_pos.y > boss_battle_area[2].y then
       return true
   end
   print("Within y parameter..")
   if cid_pos.z > boss_battle_area[1].z and cid_pos.z < boss_battle_area[2].z then
       return true
   end
   print("Within z parameter..")
   -- teleport chance
   if isPlayer(attacker) then
       print("Player is attacking..")
       local rand = math.random(100)
       if rand <= boss_chance_to_teleport then
           print("teleporting player to random position..")
           rand = random_positions[math.random(#random_positions)]
           doTeleportThing(attacker, rand)
       end
   end
   print("Finished!")
   return true
end
when i hit the monster
Code:
[18:37:06.759] [Error - CreatureScript Interface]
[18:37:06.762] data/creaturescripts/scripts/boss/teleport.lua:onStatsChange
[18:37:06.764] Description:
[18:37:06.770] data/creaturescripts/scripts/boss/teleport.lua:48: attempt to compare number with nil
[18:37:06.773] stack traceback:
[18:37:06.775]  data/creaturescripts/scripts/boss/teleport.lua:48: in function <data/creaturescripts/scripts/boss/teleport.lua:12>
 
when i hit the monster
Code:
[18:37:06.759] [Error - CreatureScript Interface]
[18:37:06.762] data/creaturescripts/scripts/boss/teleport.lua:onStatsChange
[18:37:06.764] Description:
[18:37:06.770] data/creaturescripts/scripts/boss/teleport.lua:48: attempt to compare number with nil
[18:37:06.773] stack traceback:
[18:37:06.775]  data/creaturescripts/scripts/boss/teleport.lua:48: in function <data/creaturescripts/scripts/boss/teleport.lua:12>
Can you pm me teamviewer details or something?
This doesn't make sense.

-- edit
Fixed all scripts teleporting issue with a simple workaround.
All scripts updated in Original Post.
 
Last edited:

Similar threads

Back
Top