2024-05-03, 06:39 PM
(This post was last modified: 2024-05-04, 10:19 AM by carl_anderson.)
created this code for harvesting job, go try it out
it just creates array of points player has to go through.
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;
}