15.01.2015, 05:36
(
Последний раз редактировалось Markus1337; 16.01.2015 в 06:30.
)
Sorted. TY
Use SetTimerEx if you're basing the timer on a player.
https://sampwiki.blast.hk/wiki/SetTimerEx |
public StartDropOff(playerid)
{
SendClientMessage(playerid, -1,"Creating Drop off CP");
DestroyDynamicCP(PickupCP[playerid]);
CreateTruckDropoff(playerid);
return 1;
}
public TruckingCompleted(playerid)
{
new string[126];
new random_money = DropLoc[playerid][minPay]+random(DropLoc[playerid][maxPay]); //Random money based on minPay and maxPay in the array.
GameTextForPlayer(playerid, string, 3000, 3);
format(string, sizeof(string), "Truck Delivery Completed~n~~g~%s$", random_money);
GivePlayerMoney(playerid, random_money);
DestroyDynamicCP(DropoffCP[playerid]); //Destroys the checkpoint once delivery is completed.
return 1;
}
It looks like the old variable for storing the pick up checkpoint is not being reset and because that checkpoint is destroyed, the next available ID just so happens to be that same ID, resulting in the pick up and drop off variables containing the same value.
The best practice to prevent this is: whenever you call a Destroy* function on a variable, reset that variable to an invalid value. *This goes for anything: vehicles (DestroyVehicle(var), var = INVALID_VEHICLE_ID), objects (DestroyObject(var), var = INVALID_OBJECT_ID), etc... In situations like this, it's always best to print out your variables so you can actually see what values they are storing then check them against what you expect the code to do. The expectation here is that in OnPlayerEnterDynamicCP, PickupCP[playerid] does not contain the same value as DropoffCP[playerid] because if that's so, then the pick up code gets run first (and blocks the other code since there's a return). Hope that helped! If not, print out the variables around the code and post your findings. |