open.mp forum
[Pawn] Please help me out with a basic job. - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Please help me out with a basic job. (/showthread.php?tid=2716)



Please help me out with a basic job. - x3nt1s - 2024-05-03

Hey guys I know this is dumb but it's just for training myself I just need some help with a basic job I wanna make since I've been struggling to make even simple things as that. If the player enters any Combine Harvester they get a mark on the map for Checkpoint 1 then when they go through it they gotta go through the next 3 checkpoints and by the end they get $50. They could repeat it over and over to get the money.

The XYZ coordinates are:
21.3124,62.0883,3.1172 = Checkpoint 1
13.2968,37.2150,3.1172 = Checkpoint 2
64.9920,-32.5298,0.7534 = Checkpoint 3
72.8307,19.9228,0.6094 = Checkpoint 4

Thanks in advance.


RE: Please help me out with a basic job. - carl_anderson - 2024-05-03

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;
}



RE: Please help me out with a basic job. - x3nt1s - 2024-05-04

(2024-05-03, 06:39 PM)carl_anderson Wrote: 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 {
            SetHarvestingPoint(playerid);
        }
    }
    return 1;
}

Thanks for your help but the strange thing is when I go in the combine harvester nothing happens. I've tried to make a filterscript out of it but it's like the code isn't even there. No checkpoints and it ain't marked on the map either I've tried to drive around the coordinates just to see if I get the $50 but nothing.


RE: Please help me out with a basic job. - carl_anderson - 2024-05-04

Add this line also to your filterscript.
This just shows, if filterscript was even loaded, when you start your server.

Code:
public OnFilterScriptInit()
{
    print("Harvesting job loaded.");
    return 1;
}

Also general rule is that, you should avoid using filterscripts, because they don't provide any benefits and its even hard to communicate with filterscripts.
Systems can be gamemode itself.