Sweeper job gives me money bug
#1

The Sweeper job gives me money even when im not at the vehicle.
how to fix it?
Quote:

#include <a_samp>

new stimer;

#define WAIT_TIME 40000


public OnFilterScriptInit()
{
print("[FILTERSCRIPT]Street Sweeping Job has loaded successfully");
return 1;
}
public OnFilterScriptExit()
{
print("[FILTERSCRIPT]Street Sweeping Job has unloaded successfully");
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 574)
{
stimer = SetTimerEx("Sweeping", WAIT_TIME, true, "d", playerid);
SendClientMessage(playerid, 0x58E11EC8, "You are now Street Sweeping to earn money. Drive around and earn money!");
}

}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(GetVehicleModel(vehicleid) == 574)
{
KillTimer(stimer);
SendClientMessage(playerid, 0x58E11EC8, "You are no longer doing your Street Sweeping Job!");
}
return 1;
}


forward Sweeping(playerid);
public Sweeping(playerid)
{
new string[128];
new rand = 100 + random(210);
GivePlayerMoney(playerid, rand);
format(string, sizeof(string), "You have received $%d for your Street Sweeping Job!", rand);
SendClientMessage(playerid, 0x58E11EC8, string);
return 1;
}

Reply
#2

I suspect the issue is using 1 timer id for all players, solved by doing new stimer[MAX_PLAYERS];

pawn Код:
#include <a_samp>

new stimer[MAX_PLAYERS]; //You want a timer id for EACH player.

#define WAIT_TIME 40000


public OnFilterScriptInit()  {
    print("[FILTERSCRIPT]Street Sweeping Job has loaded successfully");
    return 1;
}
public OnFilterScriptExit() {
    print("[FILTERSCRIPT]Street Sweeping Job has unloaded successfully");
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate) {
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 574) {
            stimer[playerid] = SetTimerEx("Sweeping", WAIT_TIME, true, "d", playerid);
            SendClientMessage(playerid, 0x58E11EC8, "You are now Street Sweeping to earn money. Drive around and earn money!");
        }

    }
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid) {
    if(GetVehicleModel(vehicleid) == 574) {
        KillTimer(stimer[playerid]);
        SendClientMessage(playerid, 0x58E11EC8, "You are no longer doing your Street Sweeping Job!");
    }
    return 1;
}


forward Sweeping(playerid);
public Sweeping(playerid) {

    new string[128];
    new rand = 100 + random(210);
    GivePlayerMoney(playerid, rand);
    format(string, sizeof(string), "You have received $%d for your Street Sweeping Job!", rand);
    SendClientMessage(playerid, 0x58E11EC8, string);

    return 1;
}
Also, killing your timer in:
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid) {
    if(GetVehicleModel(vehicleid) == 574) {
        KillTimer(stimer[playerid]);
        SendClientMessage(playerid, 0x58E11EC8, "You are no longer doing your Street Sweeping Job!");
    }
    return 1;
}
Wont work if the player is teleported out for example, or if they leave the server.

So its worth adding:

pawn Код:
public OnPlayerDisconnect(playerid, reason) {
   KillTimer(stimer[playerid]);
}
Reply
#3

can't add
pawn Код:
public OnPlayerDisconnect(playerid, reason) {
   KillTimer(stimer[playerid]);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)