I'm trying to design a custom lua spawning system where spawn coords are randomly picked from a list. Since the idea is that each 'respawn' rerolls for coords, I assume I can't rely on standard respawn mechanics and thus must handle them myself.
My first idea was to look into sand bag mechanics:
Which I tried to replicate in garnermonster_conf.lua:
Which doesn't throw any error (and I even the the message on the gamerserver console window "confirming" the spawn), but when I enter the game, no monster is actually spawned at those coordinates. I assume it's because I'm using
as the 'role' value, but since the spawn occurs at map level, there's no 'role' context for me to use.
Ideas?
My first idea was to look into sand bag mechanics:
Code:
function ItemUse_ShaBao2(role , Item)
local Cha_Boat = 0
Cha_Boat = GetCtrlBoat ( role )
if Cha_Boat ~= nil then
SystemNotice( role , "Cannot use while sailing" )
UseItemFailed ( role )
return
end
local reg = 0
reg =IsChaInRegion( role, 2 )
if reg == 1 then
SystemNotice( role , "Training in Safe Zone? Dream on!" )
UseItemFailed ( role )
return
end
local x, y = GetChaPos(role)
local x_move=5
local y_move=5
x=x_move+x
y=y_move+y
local MonsterID = 938
local Refresh = 1900000
local life = 1800000
local new = CreateChaX( MonsterID , x , y , 145 , Refresh,role )
SetChaLifeTime( new, life )
end
Which I tried to replicate in garnermonster_conf.lua:
Code:
for index, spawner in ipairs(GlobalRandomSpawns["garner"]) do
if spawner.Enabled then
-- Create a temporary table to remember which spots this spawner has used
local used_spots = {}
for i = 1, spawner.quantity do
-- Pass the used_spots table
local rx, ry, picked_idx = GetRandomLocation(spawner.locations, used_spots)
-- Mark this index as used so the next in the loop can't pick it
used_spots[picked_idx] = true
local final_x = rx --+ math.random(-150, 150)
local final_y = ry
local Refresh = 1900000
local life = 1800000
--local new = CreateCha(spawner.MonsterID, final_x, final_y, spawner.angle, Refresh)
local new = CreateChaX( spawner.MonsterID, final_x, final_y, spawner.angle, Refresh,nil)
SetChaLifeTime( new, life )
print("Spawned MonsterID: " .. spawner.MonsterID .. " at (" .. final_x .. ", " .. final_y .. ")")
end
end
end
Which doesn't throw any error (and I even the the message on the gamerserver console window "confirming" the spawn), but when I enter the game, no monster is actually spawned at those coordinates. I assume it's because I'm using
Code:
nil
Ideas?