Raised This Month: $ Target: $400
 0% 

change variable depending of time hours minutes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-05-2012 , 22:16   change variable depending of time hours minutes
Reply With Quote #1

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


Last edited by simple_user; 05-07-2012 at 23:11.
simple_user is offline
Send a message via Skype™ to simple_user
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-05-2012 , 22:18   Re: array must be indexed <variable "hour">
Reply With Quote #2

PHP Code:
    new hourString[12]
    
get_time("%H"hourString11)
    new 
hour str_to_num(hourString
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-05-2012 , 22:35   Re: array must be indexed <variable "hour">
Reply With Quote #3

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?
__________________
You learn with time. Just gotta push yourself.
simple_user is offline
Send a message via Skype™ to simple_user
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 05-05-2012 , 22:56   Re: array must be indexed <variable "hour">
Reply With Quote #4

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.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-06-2012 , 17:43   Re: array must be indexed <variable "hour">
Reply With Quote #5

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

__________________
You learn with time. Just gotta push yourself.

Last edited by simple_user; 05-06-2012 at 22:45.
simple_user is offline
Send a message via Skype™ to simple_user
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 05-06-2012 , 18:17   Re: array must be indexed <variable "hour">
Reply With Quote #6

Quote:
Originally Posted by simple_user View Post
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.
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-06-2012 , 18:40   Re: array must be indexed <variable "hour">
Reply With Quote #7

Quote:
Originally Posted by Neeeeeeeeeel.- View Post
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
__________________
You learn with time. Just gotta push yourself.
simple_user is offline
Send a message via Skype™ to simple_user
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2012 , 21:58   Re: array must be indexed <variable "hour">
Reply With Quote #8

Quote:
Originally Posted by simple_user View Post
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.
__________________
fysiks is offline
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-06-2012 , 22:48   Re: array must be indexed <variable "hour">
Reply With Quote #9

Quote:
Originally Posted by simple_user View Post
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


well, now I need to define something (compiler says so).
__________________
You learn with time. Just gotta push yourself.
simple_user is offline
Send a message via Skype™ to simple_user
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-06-2012 , 18:15   Re: array must be indexed <variable "hour">
Reply With Quote #10

For getting hours (and minutes and seconds, if you need) as integer, you can do:
Code:
new hour; time(hour);

Last edited by hleV; 05-06-2012 at 18:17.
hleV is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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