Dynamic checkpoints not working properly. -
rangerxxll - 01.06.2014
So I've tried to make it so when you enter the first dynamic cp another will appear at a different location - but it didn't work. So I tried to add a timer to "debug" it, so to speak. Adding the timer successfully made the second checkpoint move to the correct position, but upon entering it the original timer i created will repeat and therefor respawn the checkpoint. (No, the timer doesn't loop. It is only called once.)
Relevant code below.
pawn Код:
new cp_truckerjob;
new cp_tdelivery;
stock TruckerRandomCP(playerid) //This is the stock that creates the first "Random checkpoint"
{
new rand = random(2);
switch(rand)
{
case 0:
{
cp_truckerjob = CreateDynamicCP(663.7012,-547.2297,16.1418, 3.0, -1, -1, playerid, 50000);
}
case 1:
{
cp_truckerjob = CreateDynamicCP(1341.0321,332.4201,19.8278, 3.0, -1, -1, playerid, 50000);
}
case 2:
{
cp_truckerjob = CreateDynamicCP(2319.1831,-93.5659,26.2110, 3.0, -1, -1, playerid, 50000);
}
}
}
//This is when they enter the checkpoints.
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
if(checkpointid == cp_truckerjob)
{
new string[128];
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsTrailerAttachedToVehicle(TruckerJobVehicle[i]))
{
if(IsPlayerInVehicle(playerid, TruckerJobVehicle[i]))
{
DestroyDynamicCP(cp_truckerjob);
tamount[playerid] = tJob[tLoadAmount] *2;
format(string,sizeof(string), "You have earned %d$ for your packages. Deliver the truck back to the depot to collect your pay.", tamount[playerid]);
SCM(playerid,COLOR_GREEN, string);
tJob[tLoaded] = 0;
tJob[tLoadAmount] = 0; ///unload the truck
TIMER_TDELIVERY[playerid] = SetTimerEx("tDeliveryTimer", 4000, false, "i", playerid);
break;
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You're not in a Semi Truck.");
}
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You need a trailer attached to a semi truck.");
}
}
}
if(checkpointid == cp_tdelivery)
{
DestroyDynamicCP(cp_tdelivery);
SCM(playerid,COLOR_GREEN, "Truck returned and payment collected.");
tJob[tDeliverFinished] = 1;
GivePlayerMoney(playerid, tamount[playerid]);
tamount[playerid] = 0; //resetting it.
}
}
Thanks for any help.
Re: Dynamic checkpoints not working properly. -
RajatPawar - 01.06.2014
I don't know what the problem is, I haven't looked at the code from a meaningful POV - but the mistakes I can gather are -
1) You are using a GLOBAL variable to store per - player checkpoints! You need an array for that.
2) You are using random(2) to get a random number between 0, 1 & 2. This is wrong - for that, you use random(3) - 3 is the maximum SIZE.
I'll edit this when I look at the code again
Re: Dynamic checkpoints not working properly. -
rangerxxll - 01.06.2014
Thanks for the response. Will try to apply the checkpoints for specific playerids and change the random value.
EDIT: I've modified a lot of the job and the only issue left is when you deliver to the delivery checkpoint. For some reason the message "format(string,sizeof(string), "You have earned %d$ for your packages. Deliver the truck back to the depot to collect your pay.", tJob[playerid][tTempPayment]);" appears when delivering to the deliver checkpoint.
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
if(checkpointid == cp_truckerjob[playerid])
{
new string[128];
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsTrailerAttachedToVehicle(TruckerJobVehicle[i]))
{
if(IsPlayerInVehicle(playerid, TruckerJobVehicle[i]))
{
DestroyDynamicCP(cp_truckerjob[playerid]);
tJob[playerid][tTempPayment] = tJob[playerid][tLoadAmount] *2;
format(string,sizeof(string), "You have earned %d$ for your packages. Deliver the truck back to the depot to collect your pay.", tJob[playerid][tTempPayment]);
SCM(playerid,COLOR_GREEN, string);
TIMER_TDELIVERY[playerid] = SetTimerEx("tDeliveryTimer", 4000, false, "i", playerid);
break;
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You're not in a Semi Truck.");
}
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You need a trailer attached to a semi truck.");
}
}
}
if(checkpointid == cp_tdelivery[playerid])
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsTrailerAttachedToVehicle(TruckerJobVehicle[i]))
{
if(IsPlayerInVehicle(playerid, TruckerJobVehicle[i]))
{
DestroyDynamicCP(cp_tdelivery[playerid]);
KillTimer(TIMER_TDELIVERY[playerid]);
SCM(playerid,COLOR_GREEN, "Payment collected.");
GivePlayerMoney(playerid, tJob[playerid][tTempPayment]);
tJob[playerid][tTempPayment] = 0;
tJob[playerid][tLoaded] = 0;
tJob[playerid][tLoadAmount] = 0;
break;
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You need to be in your semi truck to complete the delivery.");
}
}
if(i == MAX_VEHICLES - 1)
{
SCM(pid,COLOR_GREY, "[ERROR]: You need a trailer attached to complete the delivery. (/quitjob if stuck.)");
}
}
}
}