Jump to content


Photo

Scar Group objects Question along with other Scar Questions

scar question scar

Best Answer Gambit, 26 June 2022 - 05:41 AM

Hello again brother.

 

...for example Player_GetEntities returns an Egroup, and I wonder if I can randomly select individual entities in the Egroup.

To select an individual entity, you need to us the EGroup_GetSpawnedEntityAt function.

Here is an example:

EGroup_Clear(EGroup_CreateIfNotFound("eg_TheNameYouWannaCallIt"))
local total = EGroup_CountSpawned("eg_TheNameYouWannaCallIt") -- All the entities of the EGroup
local rnd =  World_GetRand(1,total) -- Indexing starts from 1.
local entityID = EGroup_GetSpawnedEntityAt("eg_TheNameYouWannaCallIt",rnd)

... Or something. :grad:
The entityID  is of course a random entity, chosen from the EG.

 

 

 

 

Aside from these group objects I've been trying to print the players name with Player_GetDisplayName. But it prints out "table: 312B0D10" does this mean the LocString object is a table? and if so how do I get the display name out of it?

Player_GetDisplayName, indeed returns an array with more info. What you seek is the first element of that array. In other words:

local player_name = Player_GetDisplayName(playerID)[1]

 

And lastly I've been trying to get an alert to show up with the following line:
UIWarning_Show("hello World")

but it seems it doesn't do anything, I feel I'm missing something but I don't know what.

Try:

Util_MissionTitle("hello World")

... But remember, if a different event is running, then you may miss this one...

There is an alternative for this. You can try calling a function from your current function:

function YOUR_FUNCTION()
...
    Rule_Add(Rule_Display_Your_Message)
...
end


function Rule_Display_Your_Message()
    if not Event_IsAnyRunning() then
        Util_MissionTitle("hello World")
        Rule_Remove(Rule_Display_Your_Message)
    end
end
Go to the full post


3 replies to this topic

#1 YOUSLESS

YOUSLESS
  • Members
  • 15 posts

Posted 25 June 2022 - 09:21 PM

I'm working with several functions that return these group objects. for example Player_GetEntities returns an Egroup, and I wonder if I can randomly select individual entities in the Egroup. It doesn't seem like it works like a standard Lua table with some added functionality. I've been looking around the groups.scar file and groupcallers.scar file and there doesn't seem to be any underlying data structure I can access.

Aside from these group objects I've been trying to print the players name with Player_GetDisplayName. But it prints out "table: 312B0D10" does this mean the LocString object is a table? and if so how do I get the display name out of it?

And lastly I've been tryong to get an alert to show up with the following line:
UIWarning_Show("hello World")

but it seems it doesn't do anything, I feel I'm missing something but I don't know what.

Thanks in advance.



#2 YOUSLESS

YOUSLESS
  • Members
  • 15 posts

Posted 26 June 2022 - 12:18 AM

also, can you use lua extensions in SCAR? I want to use the socket library so my scar script can talk to a python script running locally
 

EDIT: I tried using the io library and I got an "attempt to index a nil value" from that does SCAR have its own io?


Edited by YOUSLESS, 26 June 2022 - 03:38 AM.


#3 Gambit

Gambit

    title available

  • Members
  • 6,718 posts
  • Location:Athens, Greece

Posted 26 June 2022 - 05:41 AM   Best Answer

Hello again brother.

 

...for example Player_GetEntities returns an Egroup, and I wonder if I can randomly select individual entities in the Egroup.

To select an individual entity, you need to us the EGroup_GetSpawnedEntityAt function.

Here is an example:

EGroup_Clear(EGroup_CreateIfNotFound("eg_TheNameYouWannaCallIt"))
local total = EGroup_CountSpawned("eg_TheNameYouWannaCallIt") -- All the entities of the EGroup
local rnd =  World_GetRand(1,total) -- Indexing starts from 1.
local entityID = EGroup_GetSpawnedEntityAt("eg_TheNameYouWannaCallIt",rnd)

... Or something. :grad:
The entityID  is of course a random entity, chosen from the EG.

 

 

 

 

Aside from these group objects I've been trying to print the players name with Player_GetDisplayName. But it prints out "table: 312B0D10" does this mean the LocString object is a table? and if so how do I get the display name out of it?

Player_GetDisplayName, indeed returns an array with more info. What you seek is the first element of that array. In other words:

local player_name = Player_GetDisplayName(playerID)[1]

 

And lastly I've been trying to get an alert to show up with the following line:
UIWarning_Show("hello World")

but it seems it doesn't do anything, I feel I'm missing something but I don't know what.

Try:

Util_MissionTitle("hello World")

... But remember, if a different event is running, then you may miss this one...

There is an alternative for this. You can try calling a function from your current function:

function YOUR_FUNCTION()
...
    Rule_Add(Rule_Display_Your_Message)
...
end


function Rule_Display_Your_Message()
    if not Event_IsAnyRunning() then
        Util_MissionTitle("hello World")
        Rule_Remove(Rule_Display_Your_Message)
    end
end

-In search of Papasmurf...

#4 YOUSLESS

YOUSLESS
  • Members
  • 15 posts

Posted 26 June 2022 - 05:57 AM

Thank you again Gambit 





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users