Skip to content

Commit

Permalink
make nests spawn stuff when host is far away
Browse files Browse the repository at this point in the history
  • Loading branch information
bgkillas committed Dec 6, 2024
1 parent 6ba3ece commit 4775b2a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
40 changes: 40 additions & 0 deletions quant.ew/data/scripts/buildings/firebugnest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
dofile_once("data/scripts/lib/utilities.lua")

local entity_id = GetUpdatedEntityID()
local pos_x, pos_y = EntityGetTransform( entity_id )
SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

if( Random(0,100) < 75 ) then
local spawn_distance = 200
local e_id = EntityGetClosestWithTag( pos_x, pos_y, "ew_peer")

if( e_id ~= 0 ) then
local x, y = EntityGetTransform( e_id )
local distance_sqrt = (x-pos_x)*(x-pos_x)+(y-pos_y)*(y-pos_y)
if( distance_sqrt < spawn_distance * spawn_distance ) then
local spawned_entities = GetValueInteger("spawned", 0)

if (spawned_entities < 10) then
-- spawn enemy
pos_x = pos_x + Random(-4,4)
pos_y = pos_y + Random(-4,4)

local new_entity = 0

if (Random(1,10) < 9) then
new_entity = EntityLoad( "data/entities/animals/firebug.xml", pos_x, pos_y )
else
new_entity = EntityLoad( "data/entities/animals/bigfirebug.xml", pos_x, pos_y )
end

edit_component( new_entity, "LuaComponent", function(comp,vars)
vars.script_death = ""
end)

spawned_entities = spawned_entities + 1

SetValueInteger("spawned", spawned_entities)
end
end
end
end
35 changes: 35 additions & 0 deletions quant.ew/data/scripts/buildings/flynest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dofile_once("data/scripts/lib/utilities.lua")

local entity_id = GetUpdatedEntityID()
local pos_x, pos_y = EntityGetTransform( entity_id )
SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

if( Random(0,100) < 75 ) then
local spawn_distance = 200
local e_id = EntityGetClosestWithTag( pos_x, pos_y, "ew_peer")

SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

if( e_id ~= 0 ) then
local x, y = EntityGetTransform( e_id )
local distance_sqrt = (x-pos_x)*(x-pos_x)+(y-pos_y)*(y-pos_y)
if( distance_sqrt < spawn_distance * spawn_distance ) then
local spawned_entities = GetValueInteger("spawned", 0)

if (spawned_entities < 15) then
-- spawn enemy
pos_x = pos_x + Random(-4,4)
pos_y = pos_y + Random(-4,4)

local new_entity = EntityLoad( "data/entities/animals/fly.xml", pos_x - 3, pos_y - 4 )
edit_component( new_entity, "LuaComponent", function(comp,vars)
vars.script_death = ""
end)

spawned_entities = spawned_entities + 1

SetValueInteger("spawned", spawned_entities)
end
end
end
end
35 changes: 35 additions & 0 deletions quant.ew/data/scripts/buildings/spidernest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dofile_once("data/scripts/lib/utilities.lua")

local entity_id = GetUpdatedEntityID()
local pos_x, pos_y = EntityGetTransform( entity_id )
SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

if( Random(0,100) < 75 ) then
local spawn_distance = 200
local e_id = EntityGetClosestWithTag( pos_x, pos_y, "ew_peer")

SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

if( e_id ~= 0 ) then
local x, y = EntityGetTransform( e_id )
local distance_sqrt = (x-pos_x)*(x-pos_x)+(y-pos_y)*(y-pos_y)
if( distance_sqrt < spawn_distance * spawn_distance ) then
local spawned_entities = GetValueInteger("spawned", 0)

if (spawned_entities < 15) then
-- spawn enemy
pos_x = pos_x + Random(-4,4)
pos_y = pos_y + Random(-4,4)

local new_entity = EntityLoad( "data/entities/animals/longleg.xml", pos_x, pos_y-12 )
edit_component( new_entity, "LuaComponent", function(comp,vars)
vars.script_death = ""
end)

spawned_entities = spawned_entities + 1

SetValueInteger("spawned", spawned_entities)
end
end
end
end
2 changes: 1 addition & 1 deletion quant.ew/files/system/item_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function rpc.open_chest(gid)
file = "data/scripts/items/chest_random.lua"
end
if file ~= nil then
wait_for_gid[gid] = GameGetFrameNum() + 600
wait_for_gid[gid] = GameGetFrameNum() + 3600
EntityAddComponent2(ent, "LuaComponent", {
script_source_file = file,
execute_on_added = true,
Expand Down

0 comments on commit 4775b2a

Please sign in to comment.