Scripts / [SOLVED] Broadcast #49: GetEntityLUAHealth(e) is no longer a command? Help

Author
Message
sbegley001
8
Years of Service
User Offline
Joined: 24th Jun 2016
Location: Southern Oregon, USA
Posted: 14th Feb 2019 04:44 Edited at: 14th Feb 2019 05:13
Was following Lee along in Broadcast#49 "Spawning Millions of AI" and although I made the necessary modifications to my ai script to reposition the enemies, I can't for the life of me figure out how to identify entities in the for loop like he does.

GetEntityLUAHealth(e) gives me this error:


While the new g_Entity[e]['health'] gives me this one:


If anyone could help me with this I would be very grateful.

My current script (attached to barrel):

The author of this post has marked a post as an answer.

Go to answer
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Feb 2019 10:25
This post has been marked by the post author as the answer.
for k, v in pairs( g_Entity ) do
if v.health <= 0 then Spawn( k ) end
end


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: 14th Feb 2019 11:03
Never saw that GetHealth command but the g_entity one should work however you shouldn't use e as your for loop variable as you're already using it a variable for the main function... This is causing conflict as it is getting confused what value e is.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
sbegley001
8
Years of Service
User Offline
Joined: 24th Jun 2016
Location: Southern Oregon, USA
Posted: 14th Feb 2019 19:12
Much thanks guys! AmenMoses - I just plugged that in and conflict solved ;] What does "k" reference?

Im guessing "pairs( g_Entity )" references the array of entities and passing "v"(variable, yeah?) allows us to access the entity's variables with "v.health" and I assume you could also access other things like "v.weight" and "v.speed"?
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Feb 2019 20:19
That is the 'proper' Lua way to access items in lists.

k is the key, v is the value. Lists are key/value pairs.

The pairs function simply iterates all items in the specified list, as we are iterating through the g_Entity list the key is the entity id and the value is the entry from the list. So yes v.health, v.x, v.y, v.z etc are all accessible.

When you say g_Entity[e] you are saying to Lua "look up the entry in the g_Entity list with the key value of 'e'".

Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 14:13:55
Your offset time is: 2024-12-22 14:13:55