How do I set vehicle to give money every minute for example
#1

Hello, I wanted to create a job which people will drive in a specific vehicle and after driving
1 minute, It will Pay them 100 dollars for example.
Reply
#2

pawn Code:
new PaymentTimer[MAX_PLAYERS] = {-1, ...}; //At the top of your script.

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) //They have entered the car as a driver
    {
        if(GetPlayerVehicleID(playerid) == SpecialVehicleID) //If the vehicle is the specific vehicle that you want
        {
            PaymentTimer[playerid] = SetTimerEx("PayDriver", 60000, false, "i", playerid); //Set a timer for 1 minute to pay them
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER) //They exited a car as a driver
    {
        KillTimer(PaymentTimer[playerid]); //Kill the payment timer
        PaymentTimer[playerid] = -1;
    }
    return 1;
}

forward PayDriver(playerid);
public PayDriver(playerid)
{
    if(GetPlayerVehicleID(playerid) != SpecialVehicleID) //If the player isn't in the vehicle, do not give them money.
    {
        KillTimer(PaymentTimer[playerid]);
        PaymentTimer[playerid] = -1;
    }
    GivePlayerMoney(playerid, 100); //Give them $100
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/OnPlayerStateChange
https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle
https://sampwiki.blast.hk/wiki/GivePlayerMoney
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

Hello,

i did just the same like you did but it doesnt work. The code is without errors but in the game i give me 0 money in the vehicle... Is there any other solution for this? Or anybody know where is the problem in this code? Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)