SA-MP Forums Archive
[Tutorial] How to create a trucking system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to create a trucking system (/showthread.php?tid=342559)



How to create a trucking system - Why - 14.05.2012

Hello there, and welcome to my tutorial on how to create a simple trucking system. You need ZCMD for the commands.
This tutorial is pretty easy to catch on, skills required: 3/10.
This is my first tutorial, so bare with me.

The first thing we are going to create is a stock.
Stock IsATruck

pawn Код:
stock IsATruck(vehicleid) {
    switch(GetVehicleModel(vehicleid)) { // makes it so it will greab the vehicle model
        case 499, 456: return 1; // If is model 499 or 456, return 1 (true)
        }
    return 0; // Else, false.
}
We'd want a little message when you are entering the truck that tells you to /loadtruck.
In order to do so, we need to check if the player is in state 3 (driver state) and IsATruck.
Go to OnPlayerStateChange and add this:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate) {
if(newstate == 2) {
        if(IsATruck(GetPlayerVehicleID(playerid))) { // if you are in a truck
        SendClientMessage(playerid, COLOR_YELLOW, "You've entered an Ocean Dock truck. /loadtruck to load some goods."); // return this message.
        }
    }
    return 1;
}
Now we are going to create the command to load the truck.

pawn Код:
CMD:loadtruck(playerid, params[]) {
    if(IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469)) { // Checks if you are close enough to the loading point.
    if(IsATruck(GetPlayerVehicleID(playerid))){ // Checks if you are inside a truck.
    LoadTruck(playerid); // calls the script to LoadTruck
    } else return SendClientMessage(playerid, COLOR_WHITE, "You are not in an Ocean Dock truck.");
    } else return SendClientMessage(playerid, COLOR_WHITE, "To load the truck, go to the loading garage in Ocean Docks, then /loadtruck.");
    return 1;
}
Great, now. You may see I added a LoadTruck function, and the command will not work without it so add this:

pawn Код:
forward LoadTruck(playerid);
also add a:
pawn Код:
new truckloaded = 0;
pawn Код:
public LoadTruck(playerid) {
    new rand = random(sizeof(Destinations)); // defines the rand variable.
    SetPlayerCheckpoint(playerid, Destinations[rand][0], Destinations[rand][1], Destinations[rand][2], 3.0); // sets a checkpoint.
    SendClientMessage(playerid, COLOR_YELLOW, "Truck loaded - Go to the checkpoint to collect your payment.");
    truckloaded = 1;
return 1;
}
Still catching on? Great. We need to define the delivery points, so copy these cordinates and add them in the script.

pawn Код:
new Float:Destinations[5][3] = {
   
    { 2401.7175,-1506.1350,23.5402 },
    { 1191.0847,-888.5489,42.7969 },
    { -69.6424,-1162.2354,1.5007 },
    { 334.1184,-1340.1366,14.2125 },
    { 481.7301,-1533.2468,19.6644 }
};
So, you need to get paid after delivering it, and in order to do so, go to OnPlayerEnterCheckpoint and add this:

pawn Код:
if(IsATruck(GetPlayerVehicleID(playerid))) {
            if(truckloaded == 1) {
        SendClientMessage(playerid, COLOR_COOLBLUE, "You've delivered the goods, and the company has paid you $250 for delivering them.");
        GivePlayerMoney(playerid, 250); // gives 250 dollars
        truckloaded = 0; // makes it so the truck is not loaded
        DisablePlayerCheckpoint(playerid);
                } else { DisablePlayerCheckpoint(playerid); SendClientMessage(playerid, COLOR_GREY, "You have apparently lost your truck, and the trucking route has been cancelled.");
                } else return 1;
                }
If I've missed anything or were unclear at any part, feel free to ask.


Re: How to create a trucking system - THE_KING$5$ - 14.05.2012

Nice tutorial. Good for mewbiee.