Second case not being run
#1

Can someone explain to me why the second case in the switch isn't being run?

pawn Код:
public InitPlayerHospitalize(playerid)
{
    if(IsPlayerConnected(playerid) && GetPVarInt(playerid, "LoggedIn"))
    {
        switch(Player[playerid][pHospitalized])
        {
            case 1:
            {
                TogglePlayerSpectating(playerid, true);

                new
                    rand = random(2);

                switch(rand)
                {
                    case 0:
                    {
                        InterpolateCameraPos(playerid, 1202.2297, -1347.2051, 17.0514, 1202.2297, -1347.2051, 17.0514, 1000, CAMERA_CUT);
                        InterpolateCameraLookAt(playerid, 1201.4558, -1346.5638, 17.1263, 1201.4558, -1346.5638, 17.1263, 1000, CAMERA_CUT);

                        Player[playerid][pPos][0] = 1172.9600;
                        Player[playerid][pPos][1] = -1323.4587;
                        Player[playerid][pPos][2] = 15.3983;
                        Player[playerid][pPos][3] = 269.1798;
                    }
                    case 1:
                    {
                        InterpolateCameraPos(playerid, 2012.1938, -1437.4775, 13.7904, 2012.1938, -1437.4775, 13.7904, 1000, CAMERA_CUT);
                        InterpolateCameraLookAt(playerid, 2012.7936, -1436.6704, 14.0102, 2012.7936, -1436.6704, 14.0102, 1000, CAMERA_CUT);

                        Player[playerid][pPos][0] = 2036.3348;
                        Player[playerid][pPos][1] = -1403.9457;
                        Player[playerid][pPos][2] = 17.2718;
                        Player[playerid][pPos][3] = 146.9548;
                    }
                }

                Player[playerid][pHospitalized] = 2;

                SendClientMessage(playerid, Colour_White, "You have been admitted into hospital, the doctors treat you and you will be released soon.");

                SetTimerEx("InitPlayerHospitalize", 5000, false, "d", playerid);
            }
            case 2:
            {
                Player[playerid][pHospitalized] = 0;

                Player[playerid][pMoney] = Player[playerid][pMoney] - 1500;

                TogglePlayerSpectating(playerid, false);

                SendClientMessage(playerid, Colour_White, "You have been treated by the doctors and you are now free to go, your hospital bill adds up to $1,500.");
            }
        }
    }
    return 1;
}
Reply
#2

Try this:
Код:
 case 2:
public InitPlayerHospitalize(playerid)
{
    if(IsPlayerConnected(playerid) && GetPVarInt(playerid, "LoggedIn"))
    {
        switch(Player[playerid][pHospitalized])
        {
            case 1:
            {
                TogglePlayerSpectating(playerid, true);

                new
                    rand = random(3);//<-- like this

                switch(rand)
                {
                    case 0:
Reply
#3

this is because random(2) will return either 0 or 1 it will never return 2
example random(n) will return random variable between 0 and (n - 1)
Reply
#4

Sorry I meant case two in this switch
pawn Код:
switch(Player[playerid][pHospitalized])
{

}
Quote:
Originally Posted by BroZeus
Посмотреть сообщение
this is because random(2) will return either 0 or 1 it will never return 2
example random(n) will return random variable between 0 and (n - 1)
I know that's why it's set up like it is.
Reply
#5

Still need help.
Reply
#6

Have you tried debugging it?
Reply
#7

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Have you tried debugging it?
It what way do you mean?
Reply
#8

Quote:
Originally Posted by arko123
Посмотреть сообщение
It what way do you mean?
https://sampwiki.blast.hk/wiki/Debugging

Also, are you certain you actually set those variables?
Reply
#9

Quote:
Originally Posted by Mionee
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Debugging

Also, are you certain you actually set those variables?
I'll try to take a look over it also, I am certain that the variables are set as case 1 works and inside the case it sets the next variable and then calls the function again using a SetTimerEx.

pawn Код:
Player[playerid][pHospitalized] = 2;

SendClientMessage(playerid, Colour_White, "You have been admitted into hospital, the doctors treat you and you will be released soon.");

SetTimerEx("InitPlayerHospitalize", 5000, false, "d", playerid);
Reply
#10

Try doing that before the switch(rand()) and see if it works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)