Score per minutes
#1

Hey there,

I would like to know how to make a score so it counts in minutes. For example, when someone gets into the truck and drives it for a 10 minutes, his score will go up to 10. Is it possible first of all? If yes, I would really appreciate if someone could show me how.

Thank You
Puzi
Reply
#2

just make a timer, wich adds +1 every minute to the score
Reply
#3

I tried, but I am bad with timers, my code doesn't work, please help.
Reply
#4

First of all you'll need to create an IsInTruck function or something, or you can easily rip one.
For this example let us assume that you have this function implented into your script.

First define the timer variable (put this under #include <a_samp>):

pawn Код:
new TruckTimer;
First we'll do OnPlayerStateChange, so that when the player becomes the driver, we'll check if the player is in a truck, then set the timer:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(IsInTruck(playerid))
        {
            TruckTimer = SetTimerEx("HasDriven", 600000, false, "i", playerid);
        }
    }
    return 1;
}
Now we'll check if the player gets out during that timer:

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsInTruck(playerid))
    {
        KillTimer(TruckTimer);
        SendClientMessage(playerid, 0xFF4040FF, "INFO: You haven't been driving long enough to earn points");
    }
}
Now for the HasDriven function itself:

pawn Код:
forward HasDriven(playerid);
public HasDriven(playerid)
{
    if(IsInTruck(playerid))
    {
        SendClientMessage(playerid, 0x33FF33AA, "INFO: You have driven this truck for 30 seconds, 10 points gained.");
        Account[playerid][Points] + 10; // just an example variable, put your own here.
    }  
    return 1;
}
Hope that helps.
If the player earns 10 points, and you want the player to have the ability to earn another 10, change the timer repeating to true:

pawn Код:
TruckTimer = SetTimerEx("HasDriven", 600000, true, "i", playerid);
Reply
#5

This is not exactly the way I ment, and it doesn't work for me as well unfortunately
The way I mean it is without messages and when person gets in truck, timer starts, for every minute driven you get one point and when you exit the vehicle, timer stops. Is that possible?
Reply
#6

You can make a timer that checks all players (loop) and if they are in a truck, gives them +1 score.
Reply
#7

How to do that?
Reply
#8

This is an example how to do it, but it isn't very effective because you don't have to be in a truck all the time to get score.

pawn Код:
forward GiveScore();

//under OnGameModeInit
SetTimer("GiveScore", 60000, true); // timer for every 1 minute

public GiveScore()
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && IsPlayerInTruck(i)) // You need to get or make yourself the IsPlayerInTruck function
        {
            SetPlayerScore(i, GetPlayerScore(i) + 1);
        }
    }
}
Reply
#9

Well, I'll make it easier...
How to make it so it earns points after a minute in any vehicle that you get into? Just delete the IsPlayerInTruck or what?
Reply
#10

Put IsPlayerInAnyVehicle instead of IsPlayerInTruck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)