• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Please help me out with a basic job.
#2
created this code for harvesting job, go try it out
it just creates array of points player has to go through.

Code:
new bool:IsPlayerHarvesting[MAX_PLAYERS];
new HarvestingPointIndex[MAX_PLAYERS];

// creates array of harvesting points, player has to go through
new Float:HarvestingPoints[][] = {
    {21.3124, 62.0883, 3.1172},
    {13.2968, 37.2150, 3.1172},
    {64.9920, -32.5298, 0.7534},
    {72.8307, 19.9228, 0.6094}
};

SetHarvestingPoint(playerid) {
    new index = HarvestingPointIndex[playerid];
    SetPlayerCheckpoint(playerid,
        HarvestingPoints[index][0], HarvestingPoints[index][1], HarvestingPoints[index][2],
        10.0
    );
}

// https://www.open.mp/docs/scripting/callbacks/OnPlayerEnterVehicle
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
    // player enters vehicle as driver
    if (ispassenger == 0) {
        // gets vehicle model id
        new modelid = GetVehicleModel(vehicleid);
        // https://sampwiki.blast.hk/wiki/Vehicles:All (vehicle model ids are here)
        if (modelid == 532) {
            SendClientMessage(playerid, -1, "You entered harvester, drive through checkpoints and get $50!");
            IsPlayerHarvesting[playerid] = true;
            HarvestingPointIndex[playerid] = 0;
            SetHarvestingPoint(playerid);
        }
    }
    return 1;
}

// https://www.open.mp/docs/scripting/callbacks/OnPlayerEnterCheckpoint
public OnPlayerEnterCheckpoint(playerid) {
    DisablePlayerCheckpoint(playerid);
    // checks if player is doing harvesting job
    if (IsPlayerHarvesting[playerid]) {
        HarvestingPointIndex[playerid] += 1; // goes to next point
        if (HarvestingPointIndex[playerid] == sizeof(HarvestingPoints)) {
            IsPlayerHarvesting[playerid] = false; // not harvesting anymore
            GivePlayerMoney(playerid, 50);
        } else {
            SendClientMessage(playerid, -1, "You finished harvesting and earned $50.");
            SetHarvestingPoint(playerid);
        }
    }
    return 1;
}

// player exits vehicle, so we should stop harvesting job
public OnPlayerExitVehicle(playerid, vehicleid) {
    if (IsPlayerHarvesting[playerid]) {
        DisablePlayerCheckpoint(playerid);
        SendClientMessage(playerid, -1, "You exited harvester and stopped working!");
        IsPlayerHarvesting[playerid] = false;
    }
    return 1;
}
  Reply


Messages In This Thread
Please help me out with a basic job. - by x3nt1s - 2024-05-03, 07:19 AM
RE: Please help me out with a basic job. - by carl_anderson - 2024-05-03, 06:39 PM

Forum Jump: