You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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,
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.
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.
The text was updated successfully, but these errors were encountered:
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:
Could be from calling SERVER_CHECK(0) 420 times when one time is enough, but I'm not sure,
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.
The text was updated successfully, but these errors were encountered: