Unify data type of player server id (GET_PLAYER_FROM_INDEX returns string instead number)

While making scripts for FiveM it is can be confusing to have a different data types for the same thing. While source (player server id) is always a number, GetPlayers() and GetPlayerFromIndex() functions returns player server id as a string.

I propose to unify player server id to one specific data type everywhere.

Not possible. It is a string internally everywhere already (shorthand of “net:1”-style IDs), however older Lua APIs (such as the source value) cast to number for compatibility with older scripts that assumed it was a number without casting inconsistently i.e. only sometimes using tonumber, and in Lua, number and string are not covariant.

Language runtimes that were added after the Lua runtime already consistently use strings.

Im curious why though?
Strings are way slower to process for anything.

Event sources weren’t designed to be a player, necessarily - these could also originate from other entities and whatnot, similar to the model used in MTA:SA.

A single number wouldn’t be able to represent other kinds of event sources.

Similarly, I doubt “strings being slower” is of any relevance here: other things are way slower than string building/parsing.

Old post I know, but since it got bumped anyway - this isn’t really the case though?

RegisterCommand has always converted string to int, and this commit was just a couple days before your post and added parseInt for event source.

Not really much that can be done, assuming all player natives parse a string to int then the only real issue comes to annoying types when using TypeScript or Lua Language Server – which is as simple as type casting or conversion.

A PlayerSrc union type (string | integer) for native arguments, like Hash, would be nice but unlikely. :person_shrugging:

Doesn’t… look like it did, it really was just a formatting commit:

image

Somehow missed that (I swear GitHub search breaks half the time), so then v8 has always used an int for source; only natives and playerSrc passed through events directly (e.g. playerJoining’s tempId) are strings.