BREAKING NEWS

Welcome to File Townz | A TOWN Where you find all Files !

Search

Monday, 12 September 2016

How to create a trucking system

How to create a trucking system

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.

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

Code:
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:

Code:
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.

Code:
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:

Code:
forward LoadTruck(playerid);
also add a:
Code:
new truckloaded = 0;
Code:
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.
Code:
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:

Code:
        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.



Share this:

Post a Comment

 
Copyright © 2014 Filetownz. Designed by OddThemes | Distributed By Gooyaabi Templates