Scripts / Accessing (x,y,z) entity coordinates in Lua scripts

Author
Message
kehagiat
11
Years of Service
User Offline
Joined: 16th Jul 2013
Location:
Posted: 2nd Feb 2014 19:27
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





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





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
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 3rd Feb 2014 01:40
Yep I'm looking for some of the same information as well.

smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Feb 2014 15:52
i'm not 100% but even if u change the value yourself e.g
and let it update it doesnt have any effect on the character so i'm guessing it just isnt using those values for reference once the models are ingame

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
kehagiat
11
Years of Service
User Offline
Joined: 16th Jul 2013
Location:
Posted: 3rd Feb 2014 16:22
True, I also tried it. Of course this is what I really want to do: change the entity coordinates through a script and it seems it doesn't work with g_entity[e]['z']=whatever. Interestingly enough, it seems to work with, for example, g_Entity[e]['activated'] = 1 (this is from the door script).



Three additional points.



1. It may of course be the case that g_entity[e]['z']=whatever WILL work in a future version. We have to wait and see. Certainly FPI had commands like this.

2. Still, my original question remains. Let me rephrase if the main lua script is run in every update of the game, it should read and print g_entity[e]['z'] even if it cannot change it. Why is this not happening?

3. Ok, trying to move the entity around, here is another approach that I unsuccesfully tried. Again, it needs a small preface.

3.1 I remember reading in one of Lee's post (can't remember which one) that the lua implementation in FPSC-R depends on the Unity plugin of Dark Basic (this is a plugin that gives Lua functionality in Dark Basic).

3.2 Ok, I am the proud owner of the Unity plugin, so I went to its documentation and found the following command: MoveObject(object number, speed#). This looks vaguely familiar to g_PlayerPosX so I tried to see if it would work inside a Lua script.

3.3 So in my previous script I added the line MoveObject(1, 0.1), hoping that this would move my single entity. Now, things get interesting: when I tried to run the level, it went through all the "compiling" phase (i.e., where it says "loading physics", "loading AI" etc.) and then when it tried to actually run, I got an error message which said "Nonexisting Onject Number". The way I read this, the MoveObject command IS available to the Lua script, but my entity does not have object number 1. Interesting! I tried some other object numbers: 2, 3, ... gave the same erro message, while 0 gave "Invalid Object Number".

3.4 So what's going on here? Are the entities objects? Do they have object numbers? If so what numbers?



Obviously all of this is trying to second-guess Lee (who I believe is on holidays ... his return and possible help anxiously awaited). But maybe SOMEONE is reading these posts who has the answers ....



Thanasis

Whereof one cannot speak thereof one must be silent

Login to post a reply

Server time is: 2024-12-22 01:02:42
Your offset time is: 2024-12-22 01:02:42