Scripts / Sprites/ Huds/ Decals?

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 5th May 2019 04:56
Noob question yo!
Sprites are Huds, and Huds are Sprites-- it seems
according to what I've been seeing?

And Huds and Sprites can be moved around
the 2-D screen, but can't Decals be moved
by script anywhere 3-D on the map? How?
Thanks. I'm sure I seen it somewhere, just
gotta find it again. But no global functions
for it that I can see... Thanks.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th May 2019 12:23
Decals are simply entities so you can move them around in the same way, i.e. ResetPosition( entityId, x, y, z ) & ResetRotation( entityId, angx, angy, angz ).



Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th May 2019 17:23
as amen said they're treated just like any other 3D entity, just remember they are flat so for the player to really see them you will likely want to rotate them to face the camera at all times - RotateToPlayer(e)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th May 2019 17:49
RotateToPlayer only works in Y rotation, if you need to rotate in X or Z you will need to use quaternions to do it properly. (for example for decals above or below the players eyeline, especially when they are close to the player)
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 5th May 2019 21:43
Thanks again--- told ya it was a noob question!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2019 00:36
Maybe I should start a new thread for this question...
but I was hoping that I could assign a decal (and for
this example any entity as you said above) but assign
an object to "follow" or be close to another object that
has a different script using Global variables. (x, y, z) for example.)

My first attempt made a run-time error. For I am completely
uneducated on the methods or requirements to using
globals vs locals. (I've always made variables local.)
In one script I simply tried to assign the object to move
using global variables from another script. Do I have
to initialize those variables in the second script?

I looked at some global threads and they didn't seem to
clearly approach this topic exactly. But maybe...?

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th May 2019 01:20
When you attach a script to an entity the 'e' value passed into the script (i.e. _main( e ) ) allows you to access values related to that particular entity.

You do this using a global list called g_Entity

For example to get the current position of the entity use g_Entity[ e ].x, g_Entity[ e ].y, g_Entity[ e ].z

You can make this a wee bit more readable by:

local Ent = g_Entity[ e ]

local pos = { x = Ent.x, y= Ent.y, z = Ent.z }

Then the entity position is given by:

pos.x, pos., pos.z

Hope that helps.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2019 22:58
Okay. I have used g_enityx or g_playerx of course.
I'm starting to get something. Maybe?
Is this new syntax, I've never seen it!

But lua never allows me to get away with
a variable unless I do this;

10 local plrx = {}
20
30 function do_something_init(e)
40 plrx[e] = 0
50 end

I see that your scripts get away with it all the time!
Lua is biased against me?! lol or I'm too dense!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 6th May 2019 23:06

I pulled this line out of your script;

43 local plrx, plry, plrz, plrya = g_PlayerPosX, g_PlayerPosY - 10, g_PlayerPosZ, g_PlayerAngY

and I get this error-- (first screen shot)

so I changed the line to
43 local plrx[e], plry[e], plrz[e], plrya[e] = g_PlayerPosX, g_PlayerPosY - 10, g_PlayerPosZ, g_PlayerAngY

and get the other error (second screen shot)

I need multiple entities using the same script, so don't I have to use
like
local var = {}
var[e] = 200

??


Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 7th May 2019 19:53
In our first example the error is on line 45 but you've indicated the code is on line 43 What does line 45 look like?

The line you show is simply making local variables and setting them from the global versions, if you are going to use those values a lot in your script then that is a good idea, if you only use them once then it's a bit pointless.

Each script will be executed every frame with the only difference being the value of 'e' passed into it so if you need to store extra values on a per entity basis then you have to use a list.

g_Entity is a global list which contains some useful values related to entities which are updated by the engine every frame, so for example g_Entity[ e ].x contains that entities current x position value when the script is called.

If you want to store your own per-entity values you can simply do the same in your script, for example:



Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 10th May 2019 04:27
Thanks AmenMoses.
Guess sometimes I'm slow with new ideas,
so I'm not ignoring you, just messing with some
things, and trying to get a jiff of it all. haha

The thing I was trying to clarify was that I've seen scripts
by other people (like yourself) where they use global
variables without issue, but when I go to try to use them
Lua throws a error message my way saying that the variable
should be made a local one. I know you can't tell
me what's wrong without seeing the script. I'll compare
again when time is available and see what comes up!

PM

Login to post a reply

Server time is: 2024-12-22 14:50:24
Your offset time is: 2024-12-22 14:50:24