temp variable, not 0 even if defined
#1

Hello there!

I am having some difficulties here.

I am having a /loadtruck command to load the truck.

pawn Код:
CMD:loadtruck(playerid, params[]) {
    if(pInfo[playerid][pJob] == 1){
    if(IsVehicleTruck(GetPlayerVehicleID(playerid))){ // Checks if you are inside a truck.
    if(IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469)) { // Checks if you are close enough to the loading point.
    if(pInfo[playerid][pCheckpoint] == 0){
    CountDownCheck10(playerid); // calls the script to start the timer to load the truck
    } else return SendClientMessage(playerid, COLOR_WHITE, "You are not a trucker.");
    } 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.");
    } else return SendClientMessage(playerid, COLOR_WHITE, "You already have an existing checkpoint or trucking route.");
    return 1;
}
pawn Код:
enum PlayerInfo
{
    /* Temp Values */
    pTruckLoaded = 0,
    pCheckpoint = 0,
    /* ----------- */
    pPass[129], //User's password
    pAdmin, //User's admin level
    pDonator, //User's vip level
    pMoney, //User's money
    pBank, // User's bank money
    pLevel, //User's scores
    pKills, //User's kills
    pDeaths, //User's deaths
    pSkin, // User's skin.
    Float:pHealth, // User's health.
    Float:pArmor, // User's armor.
    Float:pPosX, // User's posX.
    Float:pPosY, // User's posY.
    Float:pPosZ, // User's posZ.
    pFaction,
    pFacRank,
    pJob,
    pJobSkill1,
    pJobSkill2,
    pBanned,
    pBanReason,
    pIP[20]
}
Anyone know's what wrong?

Any help appreciated.
Reply
#2

Like I just said in another topic a few hours ago: enums are not arrays! You cannot assign default values to enum declarations. An enumerator is merely a list of structured defines.
Reply
#3

Alright, so I made it:

pawn Код:
new pTruckLoaded[MAX_PLAYERS] = 0;
new pCheckpoint[MAX_PLAYERS] = 0;
and edited the /loadtruck to:
pawn Код:
CMD:loadtruck(playerid, params[]) {
    if(pInfo[playerid][pJob] == 1){
    if(IsVehicleTruck(GetPlayerVehicleID(playerid))){ // Checks if you are inside a truck.
    if(IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469)) { // Checks if you are close enough to the loading point.
    if(pTruckLoaded[playerid] == 0 && pCheckpoint[playerid] == 0){
    CountDownCheck10(playerid); // calls the script to start the timer to load the truck
    } else return SendClientMessage(playerid, COLOR_WHITE, "You are not a trucker.");
    } 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.");
    } else return SendClientMessage(playerid, COLOR_WHITE, "You already have an existing checkpoint or trucking route.");
    return 1;
}
It didn't work then either, and so I created a debug command:
pawn Код:
CMD:debugtruck(playerid, params[])
{
new str[50];
format(str, 50, "pTruckLoaded = %i - pCheckpoint = %i", pTruckLoaded, pCheckpoint);
SendClientMessage(playerid, COLOR_WHITE, str);
return 1;
}
and I got this:

and


The script clearly states that if we have 0 on those values, which we had, it would continue, but it didn't.
Reply
#4

EDIT:

Use print("test1"); in your code, so you can follow your flow of code and find out EXACTLY which line is not working. Its a slow process but guarenteed to find the problem!
Reply
#5

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
pawn Код:
CMD:loadtruck(playerid, params[]) {
    if(!pInfo[playerid][pJob] == 1) return SendClientMessage(playerid, COLOR_WHITE, "You already have an existing checkpoint or trucking route.");
    if(!IsVehicleTruck(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid, COLOR_WHITE, "To load the truck, go to the loading garage in Ocean Docks, then /loadtruck.");
    if(!IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469))  eturn SendClientMessage(playerid, COLOR_WHITE, "You are not in an Ocean Dock truck.");
// Checks if you are close enough to the loading point.
    if(!pTruckLoaded[playerid] == 0 && pCheckpoint[playerid] == 0) return SendClientMessage(playerid, COLOR_WHITE, "You are not a trucker.");
    CountDownCheck10(playerid); // calls the script to start the timer to load the truck
    return 1;
}
thats neater.

now what problem are you having?
This:


and


I have no checkpoints or active trucking routes, but still it rejects me from loading the truck.
Reply
#6

that code i posted was wrong... look at my edit on the post
Reply
#7

I cleaned up the code a bit, got a better view of it and removed unnecesarry brackets, easier to track the problem then.

I found the source of the problem.

Thanks for the help.

Final code:
pawn Код:
CMD:loadtruck(playerid, params[])
{
    if(pInfo[playerid][pJob] == 1){  // If has the truckerjob (job 1)
    if(IsVehicleTruck(GetPlayerVehicleID(playerid))) // If is in a truck
    if(IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469)) // If is next to the loading point
    if(pTruckLoaded[playerid] == 0 && pCheckpoint[playerid] == 0) // If you don't have a checkpoint or trucking route, then
    CountDownCheck10(playerid); // execute the timer (loading truck screen)
   
    if(pInfo[playerid][pJob] != 1) return SendClientMessage(playerid, COLOR_WHITE, "You are not a trucker."); // But if you don't have the trucking job, return you are not a trucker and cancel.
    if(!IsVehicleTruck(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid, COLOR_WHITE, "You are not in an Ocean Dock truck."); // If you are not in a truck, cancel.
    if(!IsPlayerInRangeOfPoint(playerid, 5, 2197.8425,-2662.9883,13.5469)) return SendClientMessage(playerid, COLOR_WHITE, "To load the truck, go to the loading garage in Ocean Docks, then /loadtruck."); // If not next to the loading garage, describe where to load it, and cancel.
    if(pTruckLoaded[playerid] != 0 && pCheckpoint[playerid] != 0) return SendClientMessage(playerid, COLOR_WHITE, "You already have an existing checkpoint or trucking route."); // If you already have a checkpoint or trucking route, cancel.
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)