Building a payday function
#1

Hello there,

First of all let me state that I'm new to scripting and so, if there is an obvious mistake here please don't laugh at me.

Anyways, I'm trying to build a simple timer interval; however, it doesn't seem to be working.

The OnGameModeInit function:
PHP код:
public OnGameModeInit()
{
    
SetTimer("MinuteTimer"1000true);
        return 
true;

The MinuteTimer stock function
PHP код:
stock MinuteTimer()
{
    new 
hoursminutesseconds;
    
gettime(hoursminutesseconds);
    
    
// I know, there is no statement that checks for whole hours, that's because I'm still trying to get the Timer   function properly.
    
for(i=0MAX_PLAYERSi++)
    {
        
SendClientMessage(i, -1"Timer called.");
        
Player[i][pMinutes]++;
        
        if(
Player[i][pMinutes]>= 15)
        {
            
Paycheck(i);
        }
    }
    
    return 
1;

Payday function:
PHP код:
stock Paycheck(playerid)
{
    
SendClientMessage(playerid, -1"Timer worked.");

Well, it just doesn't work. Can someone explain me why it doesn't?

Thanks in advance
Reply
#2

Hello!

First, we don't laugh at you because we all was also beginners.

Your problem:
All timers are calling publics (callbacks), and you tries to call a function.
You have to write it like this:
PHP код:
forward MinuteTimer();
public 
MinuteTimer()
{
    new 
hours,minutes,seconds;
    
gettime(hours,minutes,seconds);
    
    
// I know, there is no statement that checks for whole hours, that's because I'm still trying to get the Timer   function properly.
    
for(i=0MAX_PLAYERSi++)
    {
        
SendClientMessage(i, -1"Timer called.");
        
Player[i][pMinutes]++;
        if(
Player[i][pMinutes]>= 15)
        {
            
Paycheck(i);
        }
    }
    return 
1;

I have to apologize for my bad english. Sorry!
Reply
#3

Hello there,

Thanks for the quick reply. That really helped me out. Also good to know for my other functions.

Also, I forgot to define the 'i' variable properly
PHP код:
new 
Reply
#4

Oh, I don't saw it.
Great! Well, does it work now?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)