1. Before actually stating my question, let me say that I am totally in favor of replacing the FPI language with Lua. I get the impression that this decision has already been made, but I am just saying.
2. What I want is to have access, in the Lua scripts, to some "basic" entity variables, such as (x,y,z) position, orientation etc. Let's not worry, for the time being, about WHY I want this, I am asking HOW. I have some idea on how to do this but something is not quite working for me. To explain this I need a somewhat lengthy introduction. Please bear with me.
3. OK, I just got the latest version of FPSC-R, and I looked at the Lua scripts in the scriptbank and I noticed that several of them have expressions like
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
This tells me that there is a way to access the PLAYER's (x,y,z) coordinates with g_PlayerPosX etc. and also the ENTITY's coordinates with g_Entity[e]['x'] etc. So I went on to test my theory. I started a level, added a character (Combat Soldier) and wrote a little script (actually stole the health.lua script) named than304.lua, which goes as follows
function than304_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
Prompt(g_PlayerPosZ);
--Prompt(g_Entity[e]['z']);
if PlayerDist < 80 then
PlaySound0(e);
AddPlayerHealth(e);
Destroy(e);
Prompt("He bought the farm!!!");
end
end
The two "Prompt" lines just before the "if" statement are there to test if the g_PlayerPosZ and g_Entity[e]['z'] variables actually exist, and what their values are.
Then I attached than304.lua to my character (made it the Main script of the character) saved the level and ran it. I did this twice: first with the 2nd prompt commented out as above, second with the 1st prompt commented and the 2nd uncommented. Actually I did something slightly different, because we have the problem that if a script is "compiled" and the changed, FPSC-R will still run the older version; but this is not crucial for the current discussion; I did what was needed to have FPSC-R run the two different versions of the script.
4. I got the following results. With both versions of the script I got at the low-center part of the screen a number printed out. I conclude that both g_PlayerPosZ and g_Entity[e]['z'] actually exist. BUT:
4.1 When I was printing out g_PlayerPosZ the printed number was actually changing when I was moving the player around (with the WASD keys). This is as it should be: when the player moves, his (x,y,z) coordinates change.
4.2 When I was printing out g_Entity[e]['z'], I got a number which remained fixed even when the character was moving around. This tells me that g_Entity[e]['z'] is the z coordinate of the entity (the soldier) at a particular time and is not updated continuously.
5. So here is my precise question: what to do so that g_Entity[e]['z'] (and g_Entity[e]['x'], g_Entity[e]['y']) are continuously updated. This is obviously the case for g_PlayerPosZ ; why is g_Entity[e]['z'] different? Or, alternatively, is there some other variable which I can access and which contains the (x,y,z) coordinates of an entity?
ANy an dall help will be greatly appreciated
Thanasis
Whereof one cannot speak thereof one must be silent