Hey guys,
I've been using GameGuru for some days now mainly experimenting with level design and such, which worked just like a charm.
Buuut just as I wanted to start adding some entities for the player to interact with, things went downhill.
So, here's the scenario:
The player should be able to decide if he wants to pick up an item or just leave it (for later use).
For example a medikit or a healing plant or something like this.
So my thought was:"Okay, simple enough! Just take the "health.lua"-script and check online for how to prompt for the pickup option!"
In the end, this is what I came up with:
(for this I copied the "health.lua" and renamed the copy "health_plant.lua". And yes, in the entity-properties this script is used)
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function health_init(e)
end
function health_main(e)
PlayerDist = GetPlayerDistance(e)
--player instruction
if PlayerDist < 80 then
Prompt("Press 'E' to pick up and use 'Healing Plant'");
end
--player heal
if PlayerDist < 80 and g_PlayerHealth > 0 and g_KeyPressE == 1 then
PromptDuration("Healed all wounds!",3000)
PlaySound(e,0)
AddPlayerHealth(e)
Destroy(e)
ActivateIfUsed(e)
end
end
As you can see, it's just the vanilla script with the "press e to pick up" line added.
But for some reason nothing is shown now when approaching the item.
The case gets weirder: (at least for me as the lua-newbie I am)
Tried some modifications with the "weapon.lua" and the "ammo.lua" as well.
Here are the codes:
(weapon_pickup.lua ; I just modified the prompted texts to make them a bit shorter and also changed the "if playerguncount < X"-value from 9 to 2 hoping this would be used as the overall maximum of weapons the player can carry)
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Weapon
weapon_therecanbeonlyone = 0
function weapon_init_name(e,name)
weapon_name[e] = name
end
function weapon_main(e)
if weapon_therecanbeonlyone==-1 then
if g_KeyPressE == 0 and g_InKey == "" then
weapon_therecanbeonlyone = 0
end
end
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 and g_PlayerHealth > 0 and g_PlayerThirdPerson==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 and weapon_therecanbeonlyone==0 then
weapon_therecanbeonlyone = e
end
if Result >= 20.0 and weapon_therecanbeonlyone==e then
weapon_therecanbeonlyone = 0
end
if Result < 20.0 and weapon_therecanbeonlyone==e then
if g_PlayerGunCount < 2 then
if g_PlayerGunID > 0 then
if g_PlayerController==0 then
Prompt ("Press 'E' to pick up " .. weapon_name[e] .. " or T to replace" )
else
Prompt ("Press 'Y' to pick up " .. weapon_name[e] )
end
else
if g_PlayerController==0 then
Prompt ("Press 'E' to pick up " .. weapon_name[e] )
else
Prompt ("Press 'Y' to pick up " .. weapon_name[e] )
end
end
if g_KeyPressE == 1 then
PromptDuration("Picked up " .. weapon_name[e],3000)
PlaySound(e,0)
AddPlayerWeapon(e)
Destroy(e)
ActivateIfUsed(e)
weapon_therecanbeonlyone = -1
end
else
if g_PlayerController==0 then
if g_PlayerGunID > 0 then
Prompt ("Press 'T' to replace current weapon with " .. weapon_name[e] )
else
Prompt ("You can't carry any more weapons." )
end
else
Prompt ("You can't carry any more weapons." )
end
end
if g_InKey == "t" and g_PlayerGunID > 0 then
PromptDuration("Replaced with " .. weapon_name[e],3000)
PlaySound(e,0)
ReplacePlayerWeapon(e)
Destroy(e)
ActivateIfUsed(e)
weapon_therecanbeonlyone = -1
end
end
else
if weapon_therecanbeonlyone==e then
weapon_therecanbeonlyone = 0
end
end
end
(ammo_pickup.lua ; here I added the line "ammo_name[e] = name" in hopes that this would store and later display the name of the entity. also added the "press e to pickup" line so the player can choose to leave it.)
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Ammo
function ammo_init(e)
ammo_name[e] = name
end
function ammo_main(e)
PlayerDist = GetPlayerDistance(e)
--player instruction
if PlayerDist < 60 then
Prompt("Press 'E' to pick up " .. ammo_name[e] );
end
--player pickup
if PlayerDist < 60 and g_PlayerHealth > 0 and g_PlayerThirdPerson==0 then
PromptDuration("Picked up " .. ammo_name[e] ,3000)
PlaySound(e,0)
AddPlayerAmmo(e)
Destroy(e)
ActivateIfUsed(e)
end
end
So, in short:
there are three scripts which were copied, renamed and modified with some (simple?) lines of code.
They are all set in the corresponding entity-properties.
when testing the game and approaching the entities, nothing gets displayed, the "e"-key is not responding as well. It's just as there is no script assigned to them.
The scripts are saved in the same folder as the original ones.
Oh boy, what a long first entry here.
And I have the feeling this won't be the last
Really hope someone can help me out with this, especially since I think I just made a very stupid or simple error there. Would love to know what went wrong *g*
Anyway, wish you all a nice day or evening, depending on where you live of course
/bg