Hi all,
I am taking Wolf's advice and dipping my toe into the land of Lua. I think I need to create some global variables.
I managed to create g_seen_ghost and when the player gets close to a barrel and presses 'E' the value of the variable is displayed. Attached to another barrel is a script that adds 1 to g_seen_ghost if the player approaches and presses 'E'.
I tested it and the value did change as planned. In standalone the variable retained the updated value after save game/load game. However, if the game has a second level this number is not carried over to the next level. Is there a way to do this?
Barrel1 script:
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Key
function test1_init(e)
if g_seen_ghost == nil then
g_seen_ghost = 1
end
end
function test1_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 and g_PlayerHealth > 0 then
SourceAngle = g_PlayerAngY
while SourceAngle < 0.0 do
SourceAngle = SourceAngle + 360.0
end
while SourceAngle > 340.0 do
SourceAngle = SourceAngle - 360.0
end
PlayerDX = (g_Entity[e]['x'] - g_PlayerPosX)
PlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ)
DestAngle = math.atan2( PlayerDZ , PlayerDX )
-- Convert to degrees
DestAngle = (DestAngle * 57.2957795) - 90.0
Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle))
if Result > 180 then
Result = 0
end
if Result < 20.0 then
if GetGamePlayerStateXBOX() == 1 then
Prompt("Press Y button to display variable")
else
Prompt("Press E display variable")
end
if g_KeyPressE == 1 then
Prompt(g_seen_ghost)
PlaySound(e,0)
Collected(e)
-- Destroy(e)
ActivateIfUsed(e)
end
end
end
end
And barrel2:
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Key
function test2_init(e)
end
function test2_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 and g_PlayerHealth > 0 then
SourceAngle = g_PlayerAngY
while SourceAngle < 0.0 do
SourceAngle = SourceAngle + 360.0
end
while SourceAngle > 340.0 do
SourceAngle = SourceAngle - 360.0
end
PlayerDX = (g_Entity[e]['x'] - g_PlayerPosX)
PlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ)
DestAngle = math.atan2( PlayerDZ , PlayerDX )
-- Convert to degrees
DestAngle = (DestAngle * 57.2957795) - 90.0
Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle))
if Result > 180 then
Result = 0
end
if Result < 20.0 then
if GetGamePlayerStateXBOX() == 1 then
Prompt("Press Y button to change variable")
else
Prompt("Press E to change variable")
end
if g_KeyPressE == 1 and g_seen_ghost < 3 then
g_seen_ghost = (g_seen_ghost +1)
Prompt(g_seen_ghost)
PlaySound(e,0)
Collected(e)
-- Destroy(e)
ActivateIfUsed(e)
end
end
end
end
Using a different game engine and its visual scripting system I managed to create quite a nice little RPG by using binary switches and variables. That's what I intend to do here but I want multiple levels.
Julian - increasingly disillusioned and jaded