So I wanted the get the stream_distance set in server.cfg, which is a float value.
Since there is no GetConsoleVarAsFloat function, I've tried the approach found in this thread: click. Code:
stock Float:GetConsoleVarAsFloat(var[]) { new string[30]; GetConsoleVarAsString(var, string, sizeof(string)); //Crash happens here return floatstr(string); } GetConsoleVarAsInt and GetConsoleVarAsBool don't return the correct value obviously. I have this line in my server.cfg file: Code:
stream_distance 300.0 |
You've found a bug: using GetConsoleVarAsString on anything other than string (integers, floats), causes segfault. Please report it, and nice find!
|
#include a_samp
#include filemanager
#pragma dynamic 18000
Float:GetServerVarAsFloat(var[])
{
new Handle[5500];
if(!strcmp(var,"stream_distance", true))
{
strcat(Handle, GetServerLog());
new where = strfind(Handle, "stream_distance", true, 0);
strdel(Handle, 0, where);
strdel(Handle, 0, strfind(Handle,"=", true, 0)+2);
where = strfind(Handle,"(float)", true, 0);
if(where != -1)
{
strdel(Handle, where, strlen(Handle));
}
fremove("server_log.txt");
}
else
{
Handle = "0.0";
}
return floatstr(Handle);
}
GetServerLog()
{
SendRconCommand("varlist");
file_copy("server_log.txt", "scriptfiles/server_log.txt");
new File:handle = fopen("server_log.txt", io_read);
new Handle[5500];
if(handle)
{
fseek(handle, -5000, seek_end);
new buf[350];
while(fread(handle, buf))
{
strcat(Handle, buf);
}
new where = strfind(Handle,"Console Variables:", true, where)+1;
while(strlen(Handle) && strfind(Handle,"Console Variables:", true, where))
{
where = strfind(Handle,"Console Variables:", true, where)+1;
strdel(Handle, 0, where-1);
}
fclose(handle);
}
else
{
Handle = "stream_distance = 301.000000";
}
return Handle;
}
public OnFilterScriptInit()
{
new str[128];
format(str, sizeof str,"stream_distance Vaule is: %f", GetServerVarAsFloat("stream_distance"));
SendClientMessageToAll(-1, str);
}