OK, so here's my first tiny contribution to the scripting section. I have many objects in my game that I want the player to collect to perform tasks and I wanted to display a prompt of what that object is when they are in range. It quickly became obvious that I'd be copying and pasting the same code over and over again so I decided to make some stuff global and simplify the process.
Here are 2 global functions that help.
function GetPlayerDist(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
return math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
end
function Collectible(e, str)
PlayerDist = GetPlayerDist(e)
if (PlayerDist < 160) then
Prompt(str);
end
if (PlayerDist < 80) then
PlaySound0(e)
Collected(e)
Destroy(e);
end
end
To use this, just call Collectible in an object that you want to be collected.
function object_main(e)
Collectible(e, "A Great Object");
end
The only caveat is that if you have 2 objects in close proximity and are in range of them both then this would be problematic. I have some ideas on how you could display a concatenated string of multiple objects and if I need it myself then I'll post the code here at that time.
You can easily change the ranges or even make them additional parameters to the Collectible function.
Edit: This is free for any use and you don't need to give credit.