Thread: [Tutorial] Random questions thread
View Single Post
Old 08-28-2016, 04:46 PM   #726   Add To Ignore List  
Adamasterr's Avatar
Joined: Dec 2011
Adamasterr is offline
Default Re: Random questions thread

Is there a way to save the current table of players (names) to a file? (SS3 but it's a random question)
A little explanation:

In console there exist these commands:
> strSaveText("PathTo/file", "stringtowrite")
> strLoadText_unsigned("PathTo/file")
> gamListPlayers()
In Script entity you can only do one thing related to files as far as I know but it has to be a resource file
Since I can't redirect or save what gamListPlayers() prints on the console I tried defining the print function to
> function print(a) globals.x = a end gamListPlayers() print("blabla")
--[[Here it still printed the table of players then I checked if my print() worked on globals.x]]
> globals.x
This didn't affect whatever printing function is inside gamListPlayers() (because it's C++ or I don't know)...

A possible solution to this might be to run a loop in the Script entity to get all the players, store it to some PLACE and then read this PLACE from the console.
Is there a way to make this work?
Do you have an idea?
Is it all in vain?
Cries in vain - BFMV

Example of an expected code:

local x = worldInfo:GetAllEntitiesOfClass("CPlayerPuppetEntity") -- or get players in range 9001
worldGlobals.table = {}
for i = 1, #x do
  worldGlobals.table[i] = x[i]:GetPlayerName()


> --[[somehow read the global table worldGlobals.table]] --[[do my magic]]
Another idea I had was to open the SeriousEditor.log inside the editor with strLoadText_unsigned("Log/SeriousEditor.log") but that gave error 32 which may be because I tried to open a file that was being written to, I expected similar results trying to do this in-game so I didn't.

Last idea with strLoadText_unsigned() was to have an external program to copy and paste last 20 lines of SeriousEditor.log or Sam3_Unrestricted.log into another file (File) in 0.1 second intervals and then do something like this:
> gamListPlayers()
A table of players.
> globals.text = strLoadText_unsigned("Log/File")
> -- now I can strip the string and do whatever I want with it
Unless I am too slow or someone has super long name or I want to read a text too long this would work but this can't be the only solution.
Any ideas?

Last edited by Adamasterr; 08-28-2016 at 04:58 PM.
  Reply With Quote