Player
Client Functions
Name | Description |
---|---|
GetServerID | Gets serverID from any playerID. |
GetIDFromServerID | Gets playerID from any serverID. |
GetRockstarID | Gets rockstarID of local player. |
Server Functions
Name | Description |
---|---|
IsConnected | Returns if player is connected. |
GetName | Gets name of a player. |
GetPing | Gets ping of a player. |
Kick | Kicks a specified player. |
SetSession | Sets session of a player. |
GetSession | Gets session of a player. |
IsSessionActive | Returns whether a player is active in their session. |
GetServerID
Get serverID from any playerID.
int serverID = Player.GetServerID(int playerID)
This function only works for players who are in the same session as the local player.
Example:
- Lua
- Squirrel
Events.Subscribe("chatCommand", function(command)
if command == "/myserverid" then
local playerID = Game.GetPlayerId()
Chat.AddMessage("My serverID: " .. Player.GetServerID(playerID))
end
end)
Events.Subscribe("chatCommand", function(command) {
if (command == "/myserverid") {
local playerID = Game.GetPlayerId();
Chat.AddMessage("My serverID: " + Player.GetServerID(playerID));
}
});
GetIDFromServerID
Get playerID from any serverID.
int playerID = Player.GetIDFromServerID(int serverID)
This function only works for players who are in the same session as the local player.
Example:
- Lua
- Squirrel
Events.Subscribe("chatCommand", function(command)
if command == "/testid" then
local playerID = Game.GetPlayerId()
local serverID = Player.GetServerID(playerID)
local playerID2 = Player.GetIDFromServerID(serverID)
if playerID == playerID2 then
Chat.AddMessage("GetIDFromServerID works!")
end
end
end)
Events.Subscribe("chatCommand", function(command) {
if (command == "/testid") {
local playerID = Game.GetPlayerId();
local serverID = Player.GetServerID(playerID);
local playerID2 = Player.GetIDFromServerID(serverID);
if (playerID == playerID2) {
Chat.AddMessage("GetIDFromServerID works!");
}
}
});
GetRockstarID
Get rockstarID of local player.
int rockstarID = Player.GetRockstarID()
You can use this ID as a unique identifier to assign data or ban players.
Example:
- Lua
- Squirrel
Events.Subscribe("chatCommand", function(command)
if command == "/myrockstarid" then
Chat.AddMessage("My rockstarID: " .. Player.GetRockstarID())
end
end)
Events.Subscribe("chatCommand", function(command) {
if (command == "/myrockstarid") {
Chat.AddMessage("My rockstarID: " + Player.GetRockstarID());
}
});
IsConnected
Returns if player is connected.
bool connected = Player.IsConnected(int serverID)
GetName
Gets name of a player.
string name = Player.GetName(int serverID)
Example:
- Lua
- Squirrel
Events.Subscribe("testEvent", function()
local source = Events.GetSource()
Console.Log(Player.GetName(source) .. " called testEvent!")
end, true)
Events.Subscribe("testEvent", function() {
local source = Events.GetSource();
Console.Log(Player.GetName(source) + " called testEvent!");
}, true);
GetPing
Gets ping of a player.
int ping = Player.GetPing(int serverID)
Example:
- Lua
- Squirrel
-- in client script:
Events.Subscribe("chatCommand", function(command)
if command == "/myping" then
Events.CallRemote("commandMyPing", {})
end
end)
-- in server script:
Events.Subscribe("commandMyPing", function()
local source = Events.GetSource()
Chat.SendMessage(source, "Your ping is: {0000FF}" .. Player.GetPing(source))
end, true)
// in client script:
Events.Subscribe("chatCommand", function(command) {
if (command == "/myping") {
Events.CallRemote("commandMyPing", []);
}
});
// in server script:
Events.Subscribe("commandMyPing", function() {
local source = Events.GetSource();
Chat.SendMessage(source, "Your ping is: {0000FF}" + Player.GetPing(source));
}, true);
Kick
Kicks a specified player.
Player.Kick(int serverID, [optional] string reason)
If you want to send a chat message to the player before the kick, you have to create a thread and delay the kick by 1 second, otherwise the message will not reach the player.
Example:
- Lua
- Squirrel
-- in client script:
Events.Subscribe("chatCommand", function(command)
if command == "/kickme" then
Events.CallRemote("commandKickMe", {})
end
end)
-- in server script:
Events.Subscribe("commandKickMe", function()
Player.Kick(Events.GetSource())
end, true)
// in client script:
Events.Subscribe("chatCommand", function(command) {
if (command == "/kickme") {
Events.CallRemote("commandKickMe", []);
}
});
// in server script:
Events.Subscribe("commandKickMe", function() {
Player.Kick(Events.GetSource());
}, true);
SetSession
Sets session of a player.
Player.SetSession(int serverID, int sessionID)
Valid session ids are from 0-65535. 0 is the default session.
This function only sets which session the player should be in, it does not mean that he is currently in it. Use IsSessionActive to check this.
Example:
- Lua
- Squirrel
-- in client script:
Events.Subscribe("chatCommand", function(command)
if command == "/privatesession" then
Events.CallRemote("commandSession", { true })
elseif command == "/publicsession" then
Events.CallRemote("commandSession", { false })
end
end)
-- in server script:
Events.Subscribe("commandSession", function(private)
local source = Events.GetSource()
if private then
Player.SetSession(source, source)
else
Player.SetSession(source, 0)
end
end, true)
// in client script:
Events.Subscribe("chatCommand", function(command) {
if (command == "/privatesession") {
Events.CallRemote("commandSession", [ true ]);
}
else if (command == "/publicsession") {
Events.CallRemote("commandSession", [ false ]);
}
});
// in server script:
Events.Subscribe("commandSession", function(private) {
local source = Events.GetSource();
if (private) Player.SetSession(source, source);
else Player.SetSession(source, 0);
}, true);
GetSession
Gets session of a player.
int sessionID = Player.GetSession(int serverID)
This function only gets which session the player should be in, it does not mean that he is currently in it. Use IsSessionActive to check this.
Example:
- Lua
- Squirrel
-- in client script:
Events.Subscribe("chatCommand", function(command)
if command == "/mysession" then
Events.CallRemote("commandMySession", {})
end
end)
-- in server script:
Events.Subscribe("commandMySession", function()
local source = Events.GetSource()
Chat.SendMessage(source, "My sessionID: " .. Player.GetSession(source))
end, true)
// in client script:
Events.Subscribe("chatCommand", function(command) {
if (command == "/mysession") {
Events.CallRemote("commandMySession", []);
}
});
// in server script:
Events.Subscribe("commandMySession", function() {
local source = Events.GetSource();
Chat.SendMessage(source, "My sessionID: " + Player.GetSession(source));
}, true);
IsSessionActive
Returns whether a player is active in their session.
bool active = Player.IsSessionActive(int serverID)
For example, a player is not active in his session if he is currently switching or lost the connection.
Example:
- Lua
- Squirrel
-- in client script:
Events.Subscribe("chatCommand", function(command)
if command == "/privatesession" then
Events.CallRemote("commandSession", { true })
elseif command == "/publicsession" then
Events.CallRemote("commandSession", { false })
end
end)
-- in server script:
Events.Subscribe("commandSession", function(private)
local source = Events.GetSource()
if private then
Player.SetSession(source, source)
else
Player.SetSession(source, 0)
end
Thread.Create(function()
while not Player.IsSessionActive(source) do
Thread.Pause(50)
if Player.IsSessionActive(source) then
Chat.BroadcastMessage(Player.GetName(source) .. " switched the session!")
end
end
end)
end, true)
// in client script:
Events.Subscribe("chatCommand", function(command) {
if (command == "/privatesession") {
Events.CallRemote("commandSession", [ true ]);
}
else if (command == "/publicsession") {
Events.CallRemote("commandSession", [ false ]);
}
});
// in server script:
Events.Subscribe("commandSession", function(private) {
local source = Events.GetSource();
if (private) Player.SetSession(source, source);
else Player.SetSession(source, 0);
Thread.Create(function() {
while (!Player.IsSessionActive(source)) {
Thread.Pause(50);
if (Player.IsSessionActive(source)) {
Chat.BroadcastMessage(Player.GetName(source) + " switched the session!");
}
}
});
}, true);