GetConsoleVarAsString float Server Crash
#1

So, I created this thread in the Scripting Help forums. I'll post the contents of my first post again:
Quote:
Originally Posted by Freaksken
View Post
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);
}
But whenever I execute GetConsoleVarAsFloat("stream_distance"); the server crashes immediately.
GetConsoleVarAsInt and GetConsoleVarAsBool don't return the correct value obviously.
I have this line in my server.cfg file:
Code:
stream_distance 300.0
Does anyone know a solution?
Misiur replied this:
Quote:
Originally Posted by Misiur
View Post
You've found a bug: using GetConsoleVarAsString on anything other than string (integers, floats), causes segfault. Please report it, and nice find!
So, here I am reporting the problem.

EDIT:
See also this post in the Useful Functions thread.

EDIT 2:
The server also crashes if a nonexistent console variable is used.
I've updated the wiki page to show that this is a known bug.
Reply
#2

You can use this as non stable way to check stream_distance vaule at the moment until this bug gets fixed.

how it works?
Sending rcon command varlist by the script then by a help from FileManager plugin move server log to scriptfiles folder then read last lines and get stream_distance vaule.

FileManager Plugin:
http://www.jatochnietdan.com/project/sa-mp/filemanager

Script:

PHP Code:
#include a_samp
#include filemanager
#pragma dynamic 18000
Float:GetServerVarAsFloat(var[])
{
   new 
Handle[5500];
   if(!
strcmp(var,"stream_distance"true))
   {
      
strcat(HandleGetServerLog());
      new 
where strfind(Handle"stream_distance"true0);
      
strdel(Handle0where);
      
strdel(Handle0strfind(Handle,"="true0)+2);
      
where strfind(Handle,"(float)"true0);
      if(
where != -1)
      {
         
strdel(Handlewherestrlen(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, -5000seek_end);
       new 
buf[350];
       while(
fread(handlebuf))
       {
          
strcat(Handlebuf);
       }
       new 
where strfind(Handle,"Console Variables:"truewhere)+1;
       while(
strlen(Handle) && strfind(Handle,"Console Variables:"truewhere))
       {
          
where strfind(Handle,"Console Variables:"truewhere)+1;
          
strdel(Handle0where-1);
       }
       
fclose(handle);
   }
   else
   {
      
Handle "stream_distance       = 301.000000";
   }
   return 
Handle;

Usage example:

PHP Code:
public OnFilterScriptInit()
{
   new 
str[128];
   
format(strsizeof str,"stream_distance Vaule is: %f"GetServerVarAsFloat("stream_distance"));
   
SendClientMessageToAll(-1str);

Reply
#3

The server also crashes if a nonexistent console variable is used.
I've updated the wiki page to show that this is a known bug.
Reply
#4

You should use other alternatives
Reply
#5

Quote:
Originally Posted by LolerotehC
View Post
You should use other alternatives
There is no alternative, and this is a bug as described.

There is a work-around, but it's not a fix, it only just works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)