btw, just saw pEngfuncs->ServerInfo_ValueForKey... can anyone check if that works ? I can't run CS atm pEngfuncs->ServerInfo_ValueForKey("mp_c4timer") would do the job (Returns string.)
----------------------------------------
I did some research about this and couldn't find anything, so I thought I should post this, just to make the life easier to you. Credits go to BillDoor, the author of Sparky Utilities (Dunno where he took the info from.) Oh and thanks to gfreeman1 ! He told me to search there for the info. Please let me know if there are any bugs. The code should be self-explaining, so there won't be too many comments (There are some stupid ones, but I feel like they had to be there.)
The first thing to do is checking if we have "net_api.h" and "netadr.h", and if we have them, make sure they are included. I had pGL HackBase and they were not included in the package, so I've uploaded the net includes.
Then we declare some globals :
Code:
int ic4timer;
int nextUpdate = 20;
This is the function called when the CVARs are updated.
Code:
void RulesUpdated (const char * rules)
{
// ValueForKey returns a string
const char * c4timer = pEngfuncs->pNetAPI->ValueForKey(rules, "mp_c4timer");
// If we've correctly recieved the cvar
if ( c4timer && atoi(c4timer) )
// Store it, converted to int
ic4timer = atoi(c4timer);
}
This is the function where the response will be "sent".
Code:
static void RulesResponse (net_response_t *response)
{
// If there's been an error
if ( response->error != NET_SUCCESS || response->type != NETAPI_REQUEST_RULES || !response->response )
return;
RulesUpdated((const char*) response->response);
}
Our function that checks for cvar changes. Should be self-explaining.
Code:
void UpdateCVARs()
{
static int contextId = 30;
net_status_t status;
pEngfuncs->pNetAPI->Status(&status);
pEngfuncs->pNetAPI->SendRequest (contextId++, NETAPI_REQUEST_RULES, 0, 5.0, &status.remote_address, RulesResponse);
// We set this to check every 20 seconds. With smaller times, ping may be affected.
nextUpdate = pEngfuncs->GetClientTime() + 20;
}
Now every frame (HUD_Redraw, fifth viewport...) do this :
Code:
if(pEngfuncs->GetClientTime() > nextUpdate)
UpdateCVARs();