AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   change variable depending of time hours minutes (https://forums.alliedmods.net/showthread.php?t=184507)

simple_user 05-05-2012 22:16

change variable depending of time hours minutes
 
I've searched this forum. Found something similar, but it doesn't make me smarter in this case. Please don't post a valid code, just tell me more than compiler does.
I commented lines, where the errors are.
Thanks.


PHP Code:

public SetConfig()
{
    new 
config[64];
    
get_configsdir(configsizeof(config) - 1);
    
add(configsizeof(config) - 1"/day.cfg");
    
    if( 
file_exists(config) )
    {
        
server_cmd("exec %s"config);
    }
}

public 
itstime()
{

    new 
hour[24]
    
get_time("%H"hour23)

    if ( 
hour >= 22 || hour <= 6   /*** array must be indexed <variable "hour"> ***/
    
|| task_exists ("SetConfig"0) )
    {
        
remove_task("SetConfig" 0)  /*** argument type mismatch ***/
    
}
    
    else 
    {
        
    if ( 
hour && hour 22 )   /*** array must be indexed <variable "hour"> ***/
    
    
{
        
set_task (1.0"SetConfig")
    }
    return 
PLUGIN_HANDLED



Exolent[jNr] 05-05-2012 22:18

Re: array must be indexed <variable "hour">
 
PHP Code:

    new hourString[12]
    
get_time("%H"hourString11)
    new 
hour str_to_num(hourString


simple_user 05-05-2012 22:35

Re: array must be indexed <variable "hour">
 
PHP Code:

    new hourString[12]
    
get_time("%H"hourString11)
    new 
hour str_to_num(hourString

that was fast. may I ask what does it do and why?

mottzi 05-05-2012 22:56

Re: array must be indexed <variable "hour">
 
get_time fills your string (hourString) with the Hour. For your check (hour >= 22....) you need an Intenger (Number). Exolents code basictly converts the String into an Integer so you can use it.

simple_user 05-06-2012 17:43

Re: array must be indexed <variable "hour">
 
naah... basically what I'm trying to do is to change cvar value depending on time. so I have for example weapon_lights "1" and it changes 0/1 depending of conditions.

PHP Code:

public itstime()
{

    new 
hourString[12]         
    
get_time("%H"hourString11)
    new 
hour str_to_num(hourString

    if ( 
hour && hour 22 )
    
    {
     
set_cvar_num (weapon_lights0)
    }
    
    else 
    if ( 
hour >= 22 || hour <= && task_exists (id) )
    {
    
set_cvar_num (weapon_lights1)
    }

    return 
PLUGIN_HANDLED



hleV 05-06-2012 18:15

Re: array must be indexed <variable "hour">
 
For getting hours (and minutes and seconds, if you need) as integer, you can do:
Code:
new hour; time(hour);

Neeeeeeeeeel.- 05-06-2012 18:17

Re: array must be indexed <variable "hour">
 
Quote:

Originally Posted by simple_user (Post 1703769)
naah... basically what I'm trying to do is to change cvar value depending on time. ideal would be to change them directly in amxx.cfg. so I have for example weapon_lights "1" and it changes 0/1 depending of conditions.

PHP Code:

public itstime()
{

    new 
hourString[12]         
    
get_time("%H"hourString11)
    new 
hour str_to_num(hourString

    if ( 
hour && hour 22 )
    
    {
     
//.....set cvars = 0
    
}
    
    else 
    if ( 
hour >= 22 || hour <= && task_exists (id) )
    {
    
//.... set cvars = 1
    
}

    return 
PLUGIN_HANDLED



Your code it is ok.

simple_user 05-06-2012 18:40

Re: array must be indexed <variable "hour">
 
Quote:

Originally Posted by Neeeeeeeeeel.- (Post 1703797)
Your code it is ok.

it's ok so far. I have no idea, how to look for cvar in amxx.cfg, how to change it

Neeeeeeeeeel.- 05-06-2012 18:57

Re: array must be indexed <variable "hour">
 
You can just use set_cvar_num.

And you can execute that function in every map change.

fysiks 05-06-2012 21:58

Re: array must be indexed <variable "hour">
 
Quote:

Originally Posted by simple_user (Post 1703812)
it's ok so far. I have no idea, how to look for cvar in amxx.cfg, how to change it

There is no good reason to change it in amxx.cfg dynamically. It would require file operations. It would be better just to check the hour every map start or new round and set the cvar accordingly.


All times are GMT -4. The time now is 00:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.