26.11.2011, 02:21
Aiight for the restocking part atleast, define a new global constant, set the amount to however many trips you would like to enable a player to make without loading up again
Then we create a global variable to handle that number for each player.
Every time they reach a destination, you will need to run this code
You will then need to make yourself a loadup command, to replenish the stock in the truck.
But before we can do that, ensure you have a function to detect if a player is @ a certain point, such as this one
Now that we have a function to detect if a player is @ a certain position, we can produce something like this:
As for making the transition between jobs automatic, if you wanna use your current script still
Just use the following @ the end of each job
e'z
pawn Код:
#define LOAD_UP_MAX = 5 //pick whatever number you like
pawn Код:
new Stock[MAX_PLAYERS] = LOAD_UP_MAX;
Every time they reach a destination, you will need to run this code
pawn Код:
if(Stock[playerid] > 0)
{
Stock[playerid] = Stock[playerid] - 1;
GivePlayerMoney(playerid, /*payment earned from the run*/);
return 1;
}
else
{
//If they have reached their destination but have no stock on board events here
return 0;
}
But before we can do that, ensure you have a function to detect if a player is @ a certain point, such as this one
pawn Код:
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
if(IsPlayerConnected(playerid))
{
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
tempposx = (oldposx -x);
tempposy = (oldposy -y);
tempposz = (oldposz -z);
//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
return 1;
}
}
return 0;
}
pawn Код:
if(strcmp(cmdtext, "/loadup", true) == 0)
{
new Float:Radius, Float:LoadX, Float:LoadY, Float:LoadZ; //Define these as global constants, don't leave them here
LoadX = /*insert your loadup x coord here*/
LoadY = /*insert your loadup y coord here*/
LoadZ = /*insert your loadup z coord here*/
Radius = /*insert a reasonable radius to detect here*/
//again, make sure you make these global constants, they are just here for demonstration purposes
if(!PlayerToPoint(Radius, playerid, LoadX, LoadY, LoadZ))
{
SendClientMessage(playerid, /*color of your choosing in hex value*/, "You are not at the loading bay!");
return 0;
}
new Cost;
Cost = /* Cost of the loadup*/;
if(Stock[playerid] == 0)
{
GivePlayerMoney(playerid, -Cost);
SendClientMessage(playerid, /*color of your choosing in hex value*/, "You have successfully loaded up!");
Stock[playerid] = STOCK_MAX;
return 1;
}
else
{
SendClientMessage(playerid, /*color of your choosing in hex value*/, "You still have stock on board!");
return 1;
}
}
As for making the transition between jobs automatic, if you wanna use your current script still
Just use the following @ the end of each job
pawn Код:
OnPlayerCommandText("/job trucker");