OnPlayerEnterDynamicCP Messing up.
#1

pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == DrivingCheck[playerid][0])
    {
        DestroyDynamicCP(DrivingCheck[playerid][0]);
        RemovePlayerMapIcon(playerid, 0);
        SendClientMessage(playerid, COLOUR_ORANGE, "Please proceed ahead and REVERSE park in the highlighted bay (checkpoint). Mind your speed and obstacles.");
        SendClientMessage(playerid, COLOUR_RED, "You must reverse park or the test will not continue, you must park parallel to the other vehicles");
        DrivingCheck[playerid][1] = CreateDynamicCP(-2065.4126,-164.0089,35.2117, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
        SetPlayerMapIcon(playerid, 0, -2065.4126,-164.0089,35.2117, 0, COLOUR_RED, MAPICON_LOCAL);
    }
    if(checkpointid == DrivingCheck[playerid][1])
    {
        new vehicleid = GetPlayerVehicleID(playerid), Float: angle;
        GetVehicleZAngle(vehicleid, angle);
        new newangle = floatround(angle);
        if(newangle == 267 ||newangle == 268 || newangle == 269 || newangle == 270 || newangle == 271 || newangle == 272 || newangle == 273 || newangle == 274)
        {
            DestroyDynamicCP(DrivingCheck[playerid][2]);
            RemovePlayerMapIcon(playerid, 0);
            SendClientMessage(playerid, COLOUR_ORANGE, "Well Done! You completed the reverse bay park!");
            SendClientMessage(playerid, COLOUR_ORANGE, "Please proceed ahead to the next checkpoint at the car park exit. Mind your speed and obstacles.");
            DrivingCheck[playerid][2] = CreateDynamicCP(-2035.7332,-167.8290,35.1569, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
            SetPlayerMapIcon(playerid, 0, -2035.7332,-167.8290,35.1569, 0, COLOUR_RED, MAPICON_LOCAL);
        }
        else
        {
            SendClientMessage(playerid, COLOUR_RED, "Please attempt the reverse park again (exit and enter the checkpoint at correct angle).");
        }
    }
    if(checkpointid == DrivingCheck[playerid][2])
    {
        DestroyDynamicCP(DrivingCheck[playerid][2]);
        RemovePlayerMapIcon(playerid, 0);
        SendClientMessage(playerid, COLOUR_ORANGE, "Independent Driving Module.");
        SendClientMessage(playerid, COLOUR_ORANGE, "Please proceed ahead to the next checkpoint at the end of the street. Mind your speed and obstacles.");
        SendClientMessage(playerid, COLOUR_RED, "Be very aware of obstacles on the road, damage to the vehicle may cause you to fail your test.");
        DrivingCheck[playerid][3] = CreateDynamicCP(-2050.1340,-260.8407,35.0739, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
        SetPlayerMapIcon(playerid, 0, -2050.1340,-260.8407,35.0739, 0, COLOUR_RED, MAPICON_LOCAL);
    }
    if(checkpointid == DrivingCheck[playerid][3])
    {
        DestroyDynamicCP(DrivingCheck[playerid][3]);
        RemovePlayerMapIcon(playerid, 0);
        SendClientMessage(playerid, COLOUR_ORANGE, "Urban area driving and parking.");
        SendClientMessage(playerid, COLOUR_ORANGE, "Please proceed ahead to the next checkpoint at the end of the street on the right and park your vehicle.");
        SendClientMessage(playerid, COLOUR_RED, "You do not have to park the vehicle at any certain angle, just as long as you enter the bay (Checkpoint) and turn around.");
        SendClientMessage(playerid, COLOUR_RED, "Be extremely aware of obstacles on the road, damage to the vehicle may cause you to fail your test.");
        DrivingCheck[playerid][4] = CreateDynamicCP(-2044.6074,-205.7463,35.0555, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
        SetPlayerMapIcon(playerid, 0, -2044.6074,-205.7463,35.0555, 0, COLOUR_RED, MAPICON_LOCAL);
    }
    if(checkpointid == DrivingCheck[playerid][4])
    {
        DestroyDynamicCP(DrivingCheck[playerid][4]);
        RemovePlayerMapIcon(playerid, 0);
        SendClientMessage(playerid, COLOUR_ORANGE, "For the final part of you test, continue out of the garage following the road to the two trucks on the side of the street.");
        SendClientMessage(playerid, COLOUR_RED, "Please park the vehicle between the two trucks, you must park at a reasonable angle so as to not block traffic.");
        SendClientMessage(playerid, COLOUR_RED, "Be extremely aware of obstacles on the road, damage to the vehicle may cause you to fail your test.");
        DrivingCheck[playerid][5] = CreateDynamicCP(-2027.6936,-233.1335,35.1566, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
        SetPlayerMapIcon(playerid, 0, -2027.6936,-233.1335,35.1566, 0, COLOUR_RED, MAPICON_LOCAL);
    }
    if(checkpointid == DrivingCheck[playerid][5])
    {
        new vehicleid = GetPlayerVehicleID(playerid), Float: angle;
        GetVehicleZAngle(vehicleid, angle);
        new newangle = floatround(angle);
        if(newangle == 356 ||newangle == 357 || newangle == 358 || newangle == 359 || newangle == 360 || newangle == 361 || newangle == 362)
        {
            DestroyDynamicCP(DrivingCheck[playerid][5]);
            RemovePlayerMapIcon(playerid, 0);
            SendClientMessage(playerid, COLOUR_ORANGE, "Well Done! You completed the parallel park!");
            SendClientMessage(playerid, COLOUR_ORANGE, "To complete your test, please proceed to the last checkpoint on your map to receieve your results. Mind your speed and obstacles.");
            DrivingCheck[playerid][6 = CreateDynamicCP(-2024.5856,-126.0978,35.1566, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
            SetPlayerMapIcon(playerid, 0, -2024.5856,-126.0978,35.1566, 0, COLOUR_RED, MAPICON_LOCAL);
        }
        else
        {
            SendClientMessage(playerid, COLOUR_RED, "Please attempt the parallel park again (exit and enter the checkpoint at correct angle).");
        }
    }
    if(checkpointid == DrivingCheck[playerid][6])
    {
        new string[128], reason[64], Float: health;
        DestroyDynamicCP(DrivingCheck[playerid][6]);
        RemovePlayerMapIcon(playerid, 0);
        RemovePlayerFromVehicle(playerid);
        SetPlayerPos(playerid, -2033.55774, -117.38980, 1034.62805);
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerInterior(playerid, 3);
        TakingTest[playerid] = 0;
        if(GetVehicleHealth(testcar[playerid], health) < 950)
        {
            TestFailed[playerid] = 1;
            format(reason, sizeof(reason), "Test vehicle damaged significantly.");
        }
        if(TestSpeed[playerid] > 30)
        {
            TestFailed[playerid] = 1;
            format(reason, sizeof(reason), "Excessive speed: %d MPH - LIMIT 30 MPH.", TestSpeed[playerid]);
            TestSpeed[playerid] = 0;
        }
        if(TestTimeTaken[playerid] > 360000)
        {
            TestFailed[playerid] = 1;
            format(reason, sizeof(reason), "Exceeded reasonable time of completion - LIMIT: 6 minutes - Your Time: %d minutes", TestTimeTaken[playerid]);
            TestTimeTaken[playerid] = 0;
        }
        switch(TestFailed[playerid])
        {
            case 0:
            {
                SendClientMessage(playerid, COLOUR_GREEN, "_________Driving Test Results_________");
                format(string, sizeof(string), "Driving Test "COL_GREEN"PASSED.");
                SendClientMessage(playerid, COLOUR_WHITE, string);
                SendClientMessage(playerid, COLOUR_ORANGE, "Congratulations! You are now the holder of a driving license, good luck!");
                SendClientMessage(playerid, COLOUR_GREEN, "________________________________________");
                GameTextForPlayer(playerid, "~g~DRIVING TEST PASSED", 3000, 1);
            }
            case 1:
            {
                SendClientMessage(playerid, COLOUR_GREEN, "_________Driving Test Results_________");
                format(string, sizeof(string), "Driving Test "COL_RED"FAILED.");
                SendClientMessage(playerid, COLOUR_WHITE, string);
                format(string, sizeof(string), "Reason for failure: "COL_RED"%s", reason);
                SendClientMessage(playerid, COLOUR_WHITE, string);
                SendClientMessage(playerid, COLOUR_WHITE, "Please consider your reason for failing and try again when you are prepared.");
                SendClientMessage(playerid, COLOUR_GREEN, "________________________________________");
                GameTextForPlayer(playerid, "~r~DRIVING TEST FAILED", 3000, 1);
           
            }
        }
       
    }
I can't find any issues with my code but the checkpoints seem to mess up. It's confusing, after I enter the second checkpoint DrivingCheck[playerid][1] I get a spam of text (the client messages from the rest of the checkpoints except the last one) and then they don't display, I'm extremely confused.

It seems to be skipping most of the checkpoints!"

Any assistance would be kind.
Reply
#2

You should use
pawn Код:
if (..)
else if(..)
else if(..)
instead of just using if statements.

This is what's happening with your code.

Enters callback with checkpointid being 15

if(checkpointid == DrivingCheck[playerid][1])
-> checkpointid (value of 15) == DrivingCheck[playerid][0] (value of 15) is true so enters code block
->-> destroy checkpoint (next checkpoint created will be id 15 again)
->-> DrivingCheck[playerid][2] = CreateCP(..) //recreate checkpoint (returns id 15)
->->-> leaves if statement..
if(checkpointid == DrivingCheck[playerid][2]) // checkpointid is 15 and so is the value of DrivingCheck[playerid][2] because of the returned value from CreateCP(..).

repeat until the end.

Hope that makes sense xD
Reply
#3

This didn't work at all, same issue.
Reply
#4

EDIT: SORRY DOUBLE POST
Reply
#5

Hmm, maybe try creating the new CP before destroying the old one? I'm not 100% it functions the way I mentioned above but it should in theory.

Also, I'm guessing (as it's not a compilation issue) you pasted the code before you fixed this but the closing ] bracket before the = sign is missing:
pawn Код:
DrivingCheck[playerid][6 = CreateDynamicCP(-2024.5856,-126.0978,35.1566, 2, GetPlayerVirtualWorld(playerid), 0, playerid, 100.0);
Reply
#6

That is actually a very good point tbh. I shall do that. Also yeah I fixed it after I posted, I used 'undo' because I was trying different fixes etc
Reply
#7

try to give a return value
Reply
#8

What do you mean?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)