#include <a_samp>
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define COLOR_ORANGE 0xFFA500FF
#define COLOR_LIMEGREEN 0x32CD32FF
#define COLOR_ROYALBLUE 0x4169E1FF
#define COLOR_SALMON 0xFA8072FF
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_RED 0xAA3333AA
enum MisLocationsEnum
{
ID,
LoadName[128],
Float:LoadX,
Float:LoadY,
Float:LoadZ,
Float:UnloadX,
Float:UnloadY,
Float:UnloadZ,
Pay
}
new MisLocations[][MisLocationsEnum] =
{
{0, "Beer from Red County Brewery to Bone County Diner",-24.4073,-281.8898,5.9985,-305.4319,1315.6797,54.6189, 5980},
{1, "Fuel from LV Oil Refinery to LV Dirtring",266.8981,1416.5417,10.2001,1097.5164,1741.7422,10.5474, 5700},
{2, "Vehicle Parts from SF Airport ATC to Wang Cars",-1268.8223,13.6925,14.8682,-1986.3477,253.9728,35.8985, 3000},
{3, "Fuel from SF Oil Refinery to RS Haul",-1016.3634,-688.2434,32.7284,-55.3397,-1138.2479,0.8052, 18770}//The last one in the array doesn't have a comma at the end.
};
{id, text of mission, load:x co-ord, load:y co-ord, load:z co-ord, unload:x co-ord, unload:y co-ord, unload:z co-ord, pay}
#define TEAM_TRUCKER 1
main(){}
public OnGameModeInit()
{
AddPlayerClass(72, -2105.3228, -124.2982, 37.2531, 0.0, 0,0,0,0,0,0);//Change the co-ords to where you want the player to spawn!
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
switch (classid)
{
case 0:
{
GameTextForPlayer(playerid, "Trucker", 3000, 4);
SetPlayerTeam(playerid, TEAM_TRUCKER);
}
}
return 1;
}
public OnPlayerSpawn(playerid)
{
if(GetPlayerTeam(playerid) == TEAM_TRUCKER)
{
SetPlayerColor(playerid, COLOR_GREEN);
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(work, 4, cmdtext);
dcmd(stopwork, 8, cmdtext);
return 0;
}
dcmd_work(playerid, params[])
{
#pragma unused params
if(GetPlayerTeam(playerid) == TEAM_TRUCKER) return T_NewJob(playerid);
return 1;
}
dcmd_stopwork(playerid, params[])
{
#pragma unused params
if(GetPlayerTeam(playerid) == TEAM_TRUCKER) return StopWork(playerid);
return 1;
}
new iMissionText[512][MAX_PLAYERS], Float:unx[MAX_PLAYERS], Float:uny[MAX_PLAYERS], Float:unz[MAX_PLAYERS], iPay[MAX_PLAYERS], MissionStatus[MAX_PLAYERS];
stock T_NewJob(playerid)
{
new vID = GetPlayerVehicleID(playerid); //gets called on the next line
if(GetVehicleModel(vID)== 403 || GetVehicleModel(vID)== 515 || GetVehicleModel(vID) == 514)//this checks wether the player is in a Roadtrain, Tanker or Linerunner
{
if(IsTrailerAttachedToVehicle(vID))// This checks wether the player has a trailer attached
{
MissionStatus[playerid] = 1;// this sets the players mission status as 1 - So they are on a mission.
new MisRand = random(sizeof(MisLocations));// this is the line that will call a random mission.
new LoadText[128], Float:x, Float:y, Float:z;// these are where we will store each co-ord and the text for the mission
x = MisLocations[MisRand][LoadX];//this sets one of the above
y = MisLocations[MisRand][LoadY];//this sets one of the above
z = MisLocations[MisRand][LoadZ];//this sets one of the above
unx[playerid] = MisLocations[MisRand][UnloadX];//these set what we made in step 10.
uny[playerid] = MisLocations[MisRand][UnloadY];//these set what we made in step 10.
unz[playerid] = MisLocations[MisRand][UnloadZ];//these set what we made in step 10.
iPay[playerid] = MisLocations[MisRand][Pay];//these set what we made in step 10.
SetPlayerCheckpoint(playerid, x, y, z, 7);//This creates the checkpoint that the player will enter.
format(LoadText, 128, "%s",MisLocations[MisRand][LoadName]);// this is formatting the text the player will see in the console
SendClientMessage(playerid, COLOR_GREEN, "Mission:");//sends message in console
SendClientMessage(playerid, COLOR_GREEN, "_____________________");//sends message in console
SendClientMessage(playerid, COLOR_GREEN, "");//sends message in console
SendClientMessage(playerid, 0xFFFFFFFF, LoadText);//sends the text we formatted earlier in console
SendClientMessage(playerid, COLOR_GREEN, "_____________________");//sends message in console
}
else//if the player doesnt have a trailer attached
{
SendClientMessage(playerid, COLOR_RED, "You need a trailer!");//sends message in console
}
}
else//if the player isnt in a truck
{
SendClientMessage(playerid, COLOR_RED, "You must be in a Truck to perform this!");//sends message in console
}
return 1;
}
stock StopWork(playerid)
{
DisablePlayerCheckpoint(playerid);
SendClientMessage(playerid, COLOR_RED, "You chose to cancel the mission and got fined $100");
GivePlayerMoney(playerid, -100);
MissionStatus[playerid] = 0;
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
CheckpointEntered(playerid);
return 1;
}
stock CheckpointEntered(playerid)
{
new gString[128];//A new string for storage
new vID = GetPlayerVehicleID(playerid);//Explained earlier
if(!IsTrailerAttachedToVehicle(vID)) return SendClientMessage(playerid, COLOR_RED, "You need a trailer to unload!");//This line checks wether the player has a trailer attached to their truck.
if(MissionStatus[playerid] == 1)//checks the players mission status
{
DisablePlayerCheckpoint(playerid);//disables the checkpoint
SetPlayerCheckpoint(playerid, unx[playerid], uny[playerid], unz[playerid], 7);//creates the new checkpoint from the saved positions we made earlier
SendClientMessage(playerid, COLOR_ORANGE, "Loaded. Please head to the second checkpoint!");//sends message
MissionStatus[playerid] = 2;//sets the players mission status
}
else if(MissionStatus[playerid] == 2)//checks the mission status of the player
{
DisablePlayerCheckpoint(playerid);//disables the checkpoint
GivePlayerMoney(playerid, iPay[playerid]);//gives the money that was defined earlier
SendClientMessage(playerid, COLOR_GREEN, "Well done! You completed the mission!");//sends the player a message
format(gString, 512, "%s has completed mission: %s", pName(playerid), iMissionText[playerid]);//formats the message
SendClientMessageToAll(COLOR_GREEN, gString);//sends everyone message saying player completed mission
SetPlayerScore(playerid, GetPlayerScore(playerid)+2);//gives the player 2 score
MissionStatus[playerid] = 0;//sets the mission status of the player to '0'
}
return 1;
}
stock pName(PN)
{
new PX[MAX_PLAYER_NAME];
GetPlayerName(PN, PX, sizeof(PX));
return PX;
}
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
I started to read this and then i seen
pawn Код:
Its great to get a good tutorial on stuff like this, but it would be better to use one of the better command processors, when writing a tutorial you should always make sure your using the best coding practices. |
Nice tutorial dude!
But.. When I write /work I only get this message "SERVER:Unknown command" And I'm in the vehicle and also I'm in the right team. Please help me! EDIT: I converted it to ZCMD, so it's working fine now |
You didn't #define dcmd...
I think I will convert the whole tutorial to zcmd soon anyway |
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1