SA-MP Forums Archive
Building a payday function - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Building a payday function (/showthread.php?tid=598100)



Building a payday function - Josh_Lotus - 08.01.2016

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


Re: Building a payday function - Mencent - 08.01.2016

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!


Re: Building a payday function - Josh_Lotus - 08.01.2016

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 



Re: Building a payday function - Mencent - 08.01.2016

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