The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on November 28, 2024, 09:28:38 PM

Title: [API script] get player_x id
Post by: Yona-TYT on November 28, 2024, 09:28:38 PM
I noticed that in the scripts tool the pl parameter is actually a player_x , so there is no method to get the player id.

0001-Add-player_x-get_id.patch

I need to send the player id (integral), because plain data does not accept class.

Title: Re: [API script] get player_x id
Post by: prissi on December 03, 2024, 12:24:49 AM
Would it not be better to change the script tools to accept player_x?
Title: Re: [API script] get player_x id
Post by: Yona-TYT on December 03, 2024, 03:00:10 AM
Quote from: prissi on December 03, 2024, 12:24:49 AMWould it not be better to change the script tools to accept player_x?
I think I don't understand you.

The script tools do accept player_x, the problem is that I didn't know how to get the player id.

But now I discovered that you can easily get the id from player_x, although I didn't see it in the documentation.

Example:
local player = player_x(1)
local id = player.id
Title: Re: [API script] get player_x id
Post by: Andarix on December 03, 2024, 05:57:45 AM
local pl_id = player_x.nr
Title: Re: [API script] get player_x id
Post by: Yona-TYT on December 08, 2024, 08:00:42 PM
Quote from: Andarix on December 03, 2024, 05:57:45 AMlocal pl_id = player_x.nr

I noticed that this is only working on my builds, but releases are not working.
Can you confirm this?.
Captura de pantalla -2024-12-08 15-58-35.png

It seems that get_id() is needed, if I revert the patch changes, player_x.id will no longer work.

@Prissi, can you merge this?. 0001-Add-player_x-get_id.patch
Title: Re: [API script] get player_x id
Post by: prissi on December 08, 2024, 11:45:28 PM
player.nr works for me in normal builds.
Title: Re: [API script] get player_x id
Post by: Yona-TYT on December 09, 2024, 12:01:50 AM
Quote from: prissi on December 08, 2024, 11:45:28 PMplayer.nr works for me in normal builds.
That's strange, it doesn't work for me, are you using a script tool in your case?.