Skip to content

Commit

Permalink
Improvement to zone spawning logic
Browse files Browse the repository at this point in the history
* Improvement to zone spawning logic for when standalone levels are saved and restored
  • Loading branch information
LeeBamberTGC committed Dec 24, 2024
1 parent 65a18a4 commit ee4eaa7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
8 changes: 6 additions & 2 deletions GameGuru Core/GameGuru/Source/G-Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ void entity_init ( void )
t.entid=t.entityelement[t.e].bankindex;
if ( t.entid>0 )
{
// Activate entity
t.entityelement[t.e].active=1;
// Activate entity
if (t.entityelement[t.e].eleprof.spawnatstart == 1 )
{
// LB: only activate entities that are set to spawn at start
t.entityelement[t.e].active = 1;
}
t.tobj=t.entityelement[t.e].obj;
if ( t.tobj>0 )
{
Expand Down
44 changes: 23 additions & 21 deletions Scripts/scriptbank/markers/plrinzone.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player In Zone v14 by Necrym59 and Lee
-- Player In Zone v15 by Necrym59 and Lee
-- DESCRIPTION: Re-triggerable zone to trigger an event.
-- DESCRIPTION: [ZONEHEIGHT=100] controls how far above the zone the player can be before the zone is not triggered.
-- DESCRIPTION: Set for [@MULTI_TRIGGER=2(1=Yes, 2=No)]
Expand All @@ -8,7 +8,7 @@
-- DESCRIPTION: [SoundVolume=100[1,100] adjust this sounds volume
-- DESCRIPTION: <Sound0> when entering zone

local plrinzone = {}
local g_plrinzone = {}
local multi_dead = {}
local multi_switch = {}
local status = {}
Expand All @@ -17,20 +17,20 @@ local wait = {}
local waittime = {}

function plrinzone_properties(e, zoneheight, multi_trigger, delay, spawnatstart, soundvolume)
plrinzone[e].zoneheight = zoneheight or 100
plrinzone[e].multi_trigger = multi_trigger or 2
plrinzone[e].delay = delay or 0
plrinzone[e].spawnatstart = spawnatstart or 1
plrinzone[e].soundvolume = soundvolume or 1
g_plrinzone[e].zoneheight = zoneheight or 100
g_plrinzone[e].multi_trigger = multi_trigger or 2
g_plrinzone[e].delay = delay or 0
g_plrinzone[e].spawnatstart = spawnatstart or 1
g_plrinzone[e].soundvolume = soundvolume or 1
end

function plrinzone_init(e)
plrinzone[e] = {}
plrinzone[e].zoneheight = 100
plrinzone[e].multi_trigger = 2
plrinzone[e].delay = 0
plrinzone[e].spawnatstart = 1
plrinzone[e].soundvolume = 100
g_plrinzone[e] = {}
g_plrinzone[e].zoneheight = 100
g_plrinzone[e].multi_trigger = 2
g_plrinzone[e].delay = 0
g_plrinzone[e].spawnatstart = 1
g_plrinzone[e].soundvolume = 100
status[e] = "init"
doonce[e] = 0
multi_dead[e] = 0
Expand All @@ -41,31 +41,31 @@ end

function plrinzone_main(e)
if status[e] == "init" then
if plrinzone[e].delay ~= nil then waittime[e] = plrinzone[e].delay * 1000 end
if plrinzone[e].spawnatstart > 0 then SetActivated(e,1) end
if plrinzone[e].spawnatstart == 0 then SetActivated(e,0) end
if g_plrinzone[e].delay ~= nil then waittime[e] = g_plrinzone[e].delay * 1000 end
if g_plrinzone[e].spawnatstart > 0 then SetActivated(e,1) end
if g_plrinzone[e].spawnatstart == 0 then SetActivated(e,0) end
status[e] = "endinit"
end
if g_Entity[e]['activated'] == 1 then
if g_Entity[e]['plrinzone'] == 1 and multi_switch[e] == 0 and g_PlayerPosY > g_Entity[e]['y'] and g_PlayerPosY < g_Entity[e]['y']+plrinzone[e]['zoneheight'] then
if g_Entity[e]['plrinzone'] == 1 and multi_switch[e] == 0 and g_PlayerPosY > g_Entity[e]['y'] and g_PlayerPosY < g_Entity[e]['y']+g_plrinzone[e]['zoneheight'] then
if doonce[e] == 0 then
PlaySound(e,0)
SetSound(e,0)
SetSoundVolume(plrinzone[e].soundvolume)
SetSoundVolume(g_plrinzone[e].soundvolume)
wait[e] = g_Time + waittime[e]
doonce[e] = 1
end
end
if g_Time > wait[e] then
if plrinzone[e].multi_trigger == 1 and multi_switch[e] == 0 then
if g_plrinzone[e].multi_trigger == 1 and multi_switch[e] == 0 then
if doonce[e] == 1 then
multi_switch[e] = 1
ActivateIfUsed(e)
PerformLogicConnections(e)
doonce[e] = 2
end
end
if plrinzone[e].multi_trigger == 2 then
if g_plrinzone[e].multi_trigger == 2 then
if multi_dead[e] == 0 then
ActivateIfUsed(e)
PerformLogicConnections(e)
Expand All @@ -85,7 +85,9 @@ function plrinzone_main(e)
if g_EntityExtra[e]['restoremenow'] == 1 then
g_EntityExtra[e]['restoremenow'] = 0
status[e] = "init"
plrinzone[e].spawnatstart = GetEntitySpawnAtStart(e)
-- no good, as GetEntitySpawnAtStart is always 1 and different from plrinzone[e].spawnatstart
-- plrinzone[e].spawnatstart = GetEntitySpawnAtStart(e)
-- instead the 'init' will use the newly renamed g_plrinzone state that is correct for new and reloaded level states!
end
end

Expand Down

0 comments on commit ee4eaa7

Please sign in to comment.