SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/12/2019, 12:29 AM   #1
Mattski
Big Clucker
 
Mattski's Avatar
 
Join Date: Oct 2019
Location: Under Your Moms Bed
Posts: 142
Reputation: 1
Question Online time money

Hey guys...so how to award a player who is online already 30min
and when another 30min passes, give player money again

how to do this...it's such a brain fucker for me
__________________
___________________________________________
LATVIA FREEROAM : Release 19.12.19
(first server creation)


MY WORK:
Player Name Tags - https://pastebin.com/xncXzr0R
Mattski is online now   Reply With Quote
Old 03/12/2019, 01:38 AM   #2
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 535
Reputation: 18
Default Re: Online time money

Something like this?

pawn Code:
new PlayingMinutes[MAX_PLAYERS];

SetTimer("CountOnlineTime", 60000, true); //1 minute

public CountOnlineTime()
{
    foreach(new i : Player)
    {
        PlayingMinutes[i] ++;

        if(PlayingMinutes[i] == 30)
        {
            GivePlayerMoney(i, 5000);
            PlayingMinutes[i] = 0;
        }
    }
}

I suggest you also to use y_timers.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 03/12/2019, 01:38 AM   #3
IzadorO
Big Clucker
 
IzadorO's Avatar
 
Join Date: Feb 2015
Location: Scotland, Glasgow
Posts: 175
Reputation: 14
Default Re: Online time money

If you already have a variable which records minutes played, such as PlayerInfo[playerid][pMinutes], once it reaches 30 give them money, once it reaches 60 give them money and then reset it to 0.

You will need to use a callback for this which will detect when a minute has passed.

Symon beat me too it but the ideas were similar.
IzadorO is offline   Reply With Quote
Old 03/12/2019, 09:11 AM   #4
Mattski
Big Clucker
 
Mattski's Avatar
 
Join Date: Oct 2019
Location: Under Your Moms Bed
Posts: 142
Reputation: 1
Question Re: Online time money

Could this work, because i need this for admins

PHP Code:
new PlayingMinutes[MAX_PLAYERS];

SetTimer("CountOnlineTime"60000true); //1 minute

public CountOnlineTime()
(
    if(
pInfo[playerid][AdminLevel] == 1)
    {
        foreach(new 
Player)
        {
            
PlayingMinutes[i] ++;

            if(
PlayingMinutes[i] == 30)
            {
                
GivePlayerMoney(i5000);
                
PlayingMinutes[i] = 0;
            }
        }
    }

__________________
___________________________________________
LATVIA FREEROAM : Release 19.12.19
(first server creation)


MY WORK:
Player Name Tags - https://pastebin.com/xncXzr0R
Mattski is online now   Reply With Quote
Old 03/12/2019, 10:38 AM   #5
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 535
Reputation: 18
Default Re: Online time money

There is nothing wrong with the code i gave you. The yours, it's a bit incorrect. Should be:

pawn Code:
public CountOnlineTime()
(
    foreach(new i : Player) if(pInfo[i][AdminLevel] == 1)
    {
        PlayingMinutes[i] ++;

        if(PlayingMinutes[i] == 30)
        {
            GivePlayerMoney(i, 5000);
            PlayingMinutes[i] = 0;
        }
    }
}
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 03/12/2019, 10:46 AM   #6
Mattski
Big Clucker
 
Mattski's Avatar
 
Join Date: Oct 2019
Location: Under Your Moms Bed
Posts: 142
Reputation: 1
Default Re: Online time money

Ohh, thanks bro +REP
__________________
___________________________________________
LATVIA FREEROAM : Release 19.12.19
(first server creation)


MY WORK:
Player Name Tags - https://pastebin.com/xncXzr0R
Mattski is online now   Reply With Quote
Old 03/12/2019, 11:42 AM   #7
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,121
Reputation: 68
Default Re: Online time money

You have to reset these variables when player disconnects, also, kill the timer.

EDIT: killing is not necessary, it's global, nvm.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.

Last edited by Mugala; 04/12/2019 at 07:29 AM.
Mugala is offline   Reply With Quote
Old 03/12/2019, 03:35 PM   #8
Mattski
Big Clucker
 
Mattski's Avatar
 
Join Date: Oct 2019
Location: Under Your Moms Bed
Posts: 142
Reputation: 1
Question Re: Online time money

Sooo, i assume this is done and will work 99%

PHP Code:
new PlayingMinutes[MAX_PLAYERS];

SetTimer("CountOnlineTime"60000true); //1 minute

public CountOnlineTime()
(
    foreach(new 
Player) if(pInfo[playerid][AdminLevel] == 1)
    {
        
PlayingMinutes[i] ++;

        if(
PlayingMinutes[i] == 30)
        {
            
SendClientMessage(playeridWHITE"{FFFFFF}[SERVER] {00CC33}30 Min playing time bonus $25000");
            
GivePlayerMoney(i25000);
            
PlayingMinutes[i] = 0;
        }
    }
}

public 
OnPlayerDisconnect(playeridreason)
{
    
KillTimer(PlayingMinutes[playerid]);
    return 
1;

__________________
___________________________________________
LATVIA FREEROAM : Release 19.12.19
(first server creation)


MY WORK:
Player Name Tags - https://pastebin.com/xncXzr0R
Mattski is online now   Reply With Quote
Old 03/12/2019, 03:45 PM   #9
Mattski
Big Clucker
 
Mattski's Avatar
 
Join Date: Oct 2019
Location: Under Your Moms Bed
Posts: 142
Reputation: 1
Default Re: Online time money

bump
__________________
___________________________________________
LATVIA FREEROAM : Release 19.12.19
(first server creation)


MY WORK:
Player Name Tags - https://pastebin.com/xncXzr0R
Mattski is online now   Reply With Quote
Old 03/12/2019, 03:45 PM   #10
Joe Staff
High-roller
 
Joe Staff's Avatar
 
Join Date: Aug 2007
Posts: 2,582
Reputation: 379
Default Re: Online time money

Quote:
Originally Posted by Mattski View Post
Sooo, i assume this is done and will work 99%

PHP Code:
new PlayingMinutes[MAX_PLAYERS];

SetTimer("CountOnlineTime"60000true); //1 minute

public CountOnlineTime()
(
    foreach(new 
Player) if(pInfo[playerid][AdminLevel] == 1)
    {
        
PlayingMinutes[i] ++;

        if(
PlayingMinutes[i] == 30)
        {
            
SendClientMessage(playeridWHITE"{FFFFFF}[SERVER] {00CC33}30 Min playing time bonus $25000");
            
GivePlayerMoney(i25000);
            
PlayingMinutes[i] = 0;
        }
    }
}

public 
OnPlayerDisconnect(playeridreason)
{
    
KillTimer(PlayingMinutes[playerid]);
    return 
1;

No, because the timer is for everybody, not for each player.

PHP Code:
public OnPlayerDisconnect(playeridreason)
{
    
PlayingMinutes[playerid] = 0;
    return 
1;


Edit: fixed typo
__________________
Big bottom girls make this rockin' world go 'round.
Joe Staff is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Earning money online on PayPal fast ? VIP475 Everything and Nothing 2 11/06/2014 11:46 AM
How can I get money online? SounDD Everything and Nothing 6 11/08/2013 02:03 AM
Some simple ways to earn money online! kanersps Everything and Nothing 3 24/02/2013 07:20 PM
[How To] Make Money Online Mikailcan Everything and Nothing 3 24/02/2013 02:38 PM
Suggest me How to make some money online Black_Death Everything and Nothing 23 18/09/2011 10:30 PM


All times are GMT. The time now is 08:43 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.