Skip to content

Commit

Permalink
feat(server): add DOES_PLAYER_EXIST native
Browse files Browse the repository at this point in the history
this should replace the need to use GetPlayerPing and other natives which rely on implementation details
  • Loading branch information
AvarianKnight committed Jul 11, 2023
1 parent 3800625 commit 443585a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Expand Up @@ -30,6 +30,11 @@ static void CreatePlayerCommands()
return client->GetName().c_str();
}));

fx::ScriptEngine::RegisterNativeHandler("DOES_PLAYER_EXIST", MakeClientFunction([](fx::ScriptContext& context, const fx::ClientSharedPtr& client)
{
return true;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_PLAYER_GUID", MakeClientFunction([](fx::ScriptContext& context, const fx::ClientSharedPtr& client)
{
return client->GetGuid().c_str();
Expand Down
39 changes: 39 additions & 0 deletions ext/native-decls/DoesPlayerExist.md
@@ -0,0 +1,39 @@
---
ns: CFX
apiset: server
---
## DOES_PLAYER_EXIST

```c
BOOL DOES_PLAYER_EXIST(char* playerSrc);
```
Returns whether or not the player exists
## Return value
True of the player exists, false otherwise

This comment has been minimized.

Copy link
@MichaelCoding25

MichaelCoding25 Jul 11, 2023

Typo. Should be "if".

## Examples
```lua
local deferralMessages = { "Isn't this just magical!", "We can defer all day!", "You'll get in eventually", "You're totally not going to sit here forever", "The Fruit Tree is a lie" }
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local source = source
deferrals.defer()
Wait(0)
local messageIndex = 0
repeat
Wait(2000)
if messageIndex >= #deferralMessages then
deferrals.done()
else
messageIndex = messageIndex + 1
end
deferrals.update(deferralMessages[messageIndex])
until not DoesPlayerExist(source)
end)
```

0 comments on commit 443585a

Please sign in to comment.