SA-MP Forums Archive
What is wrong with this? [TD] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What is wrong with this? [TD] (/showthread.php?tid=467534)



What is wrong with this? [TD] - Isolated - 03.10.2013

pawn Код:
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
    if(_:clickedid == INVALID_TEXT_DRAW) return 1;
    if(clickedid == MainText[3][playerid])
    {
        if(IsInTut[playerid] == 1)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "Tutorial State 2");
            TextDrawSetString(MainText[2][playerid], "You now need to select your sex.~n~Choose from the buttons below.");
            TextDrawSetString(MainText[3][playerid], "Male");
            TextDrawSetString(MainText[4][playerid], "Female");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            TextDrawShowForPlayer(playerid, MainText[4][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid]=2;
        }
        if(IsInTut[playerid] == 2)
        {
            CancelSelectTextDraw(playerid);
            PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid, RED, "You are now a male.");
            for(new i; i < 5; i++)
            {
                TextDrawHideForPlayer(playerid, MainText[i][playerid]);
            }
            ShowModelSelectionMenu(playerid, skinlist, "Select Skin");
        }
        if(IsInTut[playerid] == 4)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SetPlayerCameraPos(playerid, 1230.91,-3651.36,3.11);
            SetPlayerCameraLookAt(playerid, 1230.91,-3651.36,3.11);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "You will now be taken on a tour. - Searching Area");
            TextDrawSetString(MainText[2][playerid], "This is where you can use /search to gather the supplies you need first. Its right at the beach");
            TextDrawSetString(MainText[3][playerid], "Continue");
            SelectTextDraw(playerid, COLOR_YELLOW);
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            IsInTut[playerid] = 5;
        }
        if(IsInTut[playerid] == 5)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SetPlayerCameraPos(playerid, 1192.9080,-3610.2756,4.1661);
            SetPlayerCameraLookAt(playerid, 1192.9080,-3610.2756,4.1661);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "You will now be taken on a tour. - Fishing Bridge");
            TextDrawSetString(MainText[2][playerid], "This is where you can fish. You can find the fishing supplies at the search location.");
            TextDrawSetString(MainText[3][playerid], "Continue");
            SelectTextDraw(playerid, COLOR_YELLOW);
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            IsInTut[playerid] = 6;
        }
        if(IsInTut[playerid] == 6)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SetPlayerCameraPos(playerid, 1212.3618,-3704.2810,9.4407);
            SetPlayerCameraLookAt(playerid, 1212.3618,-3704.2810,9.4407);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "You will now be taken on a tour. - Berry Picking");
            TextDrawSetString(MainText[2][playerid], "If you dont like eating fishes, you can also gather berrys to eat.");
            TextDrawSetString(MainText[3][playerid], "Continue");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid] = 7;
        }
        if(IsInTut[playerid] == 7)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SetPlayerCameraPos(playerid, 1358.5902,-3696.5566,13.3045);
            SetPlayerCameraLookAt(playerid, 1358.5902,-3696.5566,13.3045);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "You will now be taken on a tour. - Water Supply");
            TextDrawSetString(MainText[2][playerid], "You need water in order to survive. This is where you gather it for fresh water!");
            TextDrawSetString(MainText[3][playerid], "Continue");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid] = 8;
        }
        if(IsInTut[playerid] == 8)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SetPlayerCameraPos(playerid, 1230.2572,-3643.3074,7.1817);
            SetPlayerCameraLookAt(playerid, 1230.2572,-3643.3074,7.1817);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "Almost Complete");
            TextDrawSetString(MainText[2][playerid], "You have almost completed the registration process.~n~In order to continue you must complete a RP test.~n~If you get a question wrong, you will have to restart.~n~Your account will be removed.");
            TextDrawSetString(MainText[3][playerid], "Continue");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid] = 9;
        }
        if(IsInTut[playerid] == 9)
        {
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            SendClientMessage(playerid, RED, "You have completed the tour! Well done.");
            FirstSpawn[playerid] = 1;
            TogglePlayerSpectating(playerid, 0);
            PlayerSpectateVehicle(playerid, 0, 1);
            SetSpawnInfo(playerid, -1, PlayerInfo[playerid][pSkin], 1207.6694, -3613.0430, 2.2468, 0.0, -1, -1, -1, -1, -1, -1);
            SpawnPlayer(playerid);
        }
    }
    if(clickedid == MainText[4][playerid])
    {
        if(IsInTut[playerid] == 2)
        {
            CancelSelectTextDraw(playerid);
            PlayerInfo[playerid][pSex] = 2;
            SendClientMessage(playerid, RED, "You are now a female.");
            for(new i; i < 5; i++)
            {
                TextDrawHideForPlayer(playerid, MainText[i][playerid]);
            }
            ShowModelSelectionMenu(playerid, skinlist, "Select Skin");
        }
    }
    if(clickedid == MainMenu[1][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 1; CancelSelectTextDraw(playerid);
    if(clickedid == MainMenu[2][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 2; CancelSelectTextDraw(playerid);
    if(clickedid == MainMenu[3][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 3; CancelSelectTextDraw(playerid);
    if(clickedid == MainMenu[4][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 4; CancelSelectTextDraw(playerid);
    if(clickedid == MainMenu[5][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 5; CancelSelectTextDraw(playerid);
    if(clickedid == MainMenu[6][playerid] && IsInTut[playerid] == 3) return PlayerInfo[playerid][pSkill] = 6; CancelSelectTextDraw(playerid);
       
    for(new i; i < 10; i++)
    {
        if(clickedid == MainMenu[i][playerid] && IsInTut[playerid] == 3 && PlayerInfo[playerid][pSkill] != 0)
        {
            CancelSelectTextDraw(playerid);
            TogglePlayerSpectating(playerid, 0);
            PlayerSpectateVehicle(playerid, 0, 1);
            new stext[20];
            switch(PlayerInfo[playerid][pSkill])
            {
                case 1: stext = "Doctor";
                case 2: stext = "Hoarder";
                case 3: stext = "Drug Addict";
                case 4: stext = "Fisherman";
                case 5: stext = "Hunter";
                case 6: stext = "Technician";
            }
            new string[85];
            format(string, sizeof(string), "Okay, your new talent is %s.", stext);
            SendClientMessage(playerid, RED, string);
            TextDrawHideForPlayer(playerid, MainMenu[i][playerid]);
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "You will now be taken on a tour. - Beach");
            TextDrawSetString(MainText[2][playerid], "This is the beach.~n~This is where you will spawn soon~n~You also gather the supplies you need as a new player here!");
            TextDrawSetString(MainText[3][playerid], "Continue");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid] = 4;
        }
    }
    return 1;
}

The above code seems to just skip onto IsInTut 2, instead of waiting for a click.


Re: What is wrong with this? [TD] - DaRk_RaiN - 03.10.2013

Use the switch case.
pawn Код:
switch(IsInTut[playerid])
{
case 1:
{
            CancelSelectTextDraw(playerid);
            for(new i; i < 5; i++){ TextDrawHideForPlayer(playerid, MainText[i][playerid]); }
            TextDrawSetString(MainText[0][playerid], "~y~ Welcome to Island:RP            ~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~");
            TextDrawSetString(MainText[1][playerid], "Tutorial State 2");
            TextDrawSetString(MainText[2][playerid], "You now need to select your sex.~n~Choose from the buttons below.");
            TextDrawSetString(MainText[3][playerid], "Male");
            TextDrawSetString(MainText[4][playerid], "Female");
            TextDrawShowForPlayer(playerid, MainText[0][playerid]);
            TextDrawShowForPlayer(playerid, MainText[1][playerid]);
            TextDrawShowForPlayer(playerid, MainText[2][playerid]);
            TextDrawShowForPlayer(playerid, MainText[3][playerid]);
            TextDrawShowForPlayer(playerid, MainText[4][playerid]);
            SelectTextDraw(playerid, COLOR_YELLOW);
            IsInTut[playerid]=2;
}
case 2:
{
            CancelSelectTextDraw(playerid);
            PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid, RED, "You are now a male.");
            for(new i; i < 5; i++)
            {
                TextDrawHideForPlayer(playerid, MainText[i][playerid]);
            }
            ShowModelSelectionMenu(playerid, skinlist, "Select Skin");
}
case 3:
{
//code
//and so on
}
}



Re: What is wrong with this? [TD] - Isolated - 03.10.2013

Was going to, but the issue was actually not using "else if".


Re: What is wrong with this? [TD] - Pottus - 03.10.2013

if(_:clickedid == INVALID_TEXT_DRAW) return 1;

This was cause your textdraws to stay up when someone presses escape you need to make sure you close your textdraws when that happens.