Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the total number of players #42

Open
DavidBrenner3 opened this issue Dec 27, 2017 · 0 comments
Open

get the total number of players #42

DavidBrenner3 opened this issue Dec 27, 2017 · 0 comments

Comments

@DavidBrenner3
Copy link

Hi.

I'm a C++/Delphi programmer.
I use the Open-SAMP-API dll in one of my applications.

I'm trying to get the total number of players. Some servers use it to create events at specific time intervals (more often when there are many players).

For now I'm using this function:

`function GetPlayerNameByID(id: Integer; var playername: PAnsiChar; max_len: Integer): Boolean; cdecl; external 'Open-SAMP-API.dll' name 'GetPlayerNameByID'

function GetNumberOfPlayers: Integer;
var
i: Integer;
buffer: array[0..31] of AnsiChar;
p: PAnsiChar;
begin
Result := 0;
i := 0;
while i < 420 do
begin
FillChar(buffer, Length(buffer), 0);
p := @buffer[0];
if GetPlayerNameByID(i, p, High(buffer)) then
if buffer[0] <> #0 then
Inc(Result);
Inc(i);
end;
end;`

Problems:

  1. It's very slow (it takes a few sec) but I need to display a value (which I got from it and some other variables) in real time without hogging one of the logical CPUs.
    Could be from calling SERVER_CHECK(0) 420 times when one time is enough, but I'm not sure,
  2. Since checking the first char from playername would suffice, I tried to lower the length of the buffer and the max_len parameter. But at some point the dll is crashing my app. Using a try..except doesn't help.
  3. I tried to compile the dll sources in Visual C++ 2010 but I end up with some strange compilation errors in German language.
    The gold was to add this function and then to send you the sources so others can benefit as well.

Can you help me please?
Thank you.

Merry Christmas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant