SA-MP Forums Archive
Problem with keys - 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: Problem with keys (/showthread.php?tid=530832)



Problem with keys - BGTrucker - 09.08.2014

I'm using PPC's trucking script,and I wanted to set Num4/Num6 keys to be used to switch to previous/next player(or vehicle) in spectate mode.So in the OnPlayerKeyStateChange callback I made this
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        if ((newkeys & KEY_ANALOG_RIGHT) && !(oldkeys & KEY_ANALOG_RIGHT))
        {
            switch(APlayerData[playerid][SpectateType])
            {
                case ADMIN_SPEC_TYPE_PLAYER:
                {
                    if(APlayerData[playerid][SpectateID] == MAX_PLAYERS - 1)
                    {
                        for(new i;i<MAX_PLAYERS;i++)
                        {
                            if(i != playerid)
                                if(IsPlayerConnected(i))
                                {
                                    APlayerData[playerid][SpectateID] = i;
                                    break;
                                }
                                else continue;
                            else continue;
                        }
                    }
                    else
                    {
                        for(new i=1;i<MAX_PLAYERS;i++)
                        {
                            if(i != playerid)
                                if(IsPlayerConnected(i))
                                {
                                    APlayerData[playerid][SpectateID] = i;
                                    break;
                                }
                                else continue;
                            else continue;
                        }
                    }
                }
                case ADMIN_SPEC_TYPE_VEHICLE:
                {
                    if(APlayerData[playerid][SpectateID] != -1)
                    {
                        if(APlayerData[playerid][SpectateID] == MAX_PLAYERS - 1)
                        {
                            for(new i;i<MAX_PLAYERS;i++)
                            {
                                if(i != playerid)
                                    if(IsPlayerConnected(i))
                                    {
                                        APlayerData[playerid][SpectateID] = i;
                                        break;
                                    }
                                    else continue;
                                else continue;
                            }
                        }
                        else
                        {
                            for(new i=1;i<MAX_PLAYERS;i++)
                            {
                                if(i != playerid)
                                    if(IsPlayerConnected(i))
                                    {
                                        APlayerData[playerid][SpectateID] = i;
                                        break;
                                    }
                                    else continue;
                                else continue;
                            }
                        }
                    }
                    else
                    {
                        if(APlayerData[playerid][SpectateVehicle] == MAX_VEHICLES)
                        {
                            for(new i=1;i<MAX_VEHICLES;i++)
                            {
                                if(400 <= GetVehicleModel(i) <= 611)
                                {
                                    APlayerData[playerid][SpectateVehicle] = i;
                                    break;
                                }
                                else continue;
                            }
                        }
                        else
                        {
                            for(new i=APlayerData[playerid][SpectateVehicle] + 1;i<MAX_VEHICLES;i++)
                            {
                                if(400 <= GetVehicleModel(i) <= 611)
                                {
                                    APlayerData[playerid][SpectateVehicle] = i;
                                    break;
                                }
                                else continue;
                            }
                        }
                    }
                }
            }
        }
        if ((newkeys & KEY_ANALOG_LEFT) && !(oldkeys & KEY_ANALOG_LEFT))
        {
            switch(APlayerData[playerid][SpectateType])
            {
                case ADMIN_SPEC_TYPE_PLAYER:
                {
                    if(APlayerData[playerid][SpectateID] == 0)
                    {
                        for(new i=MAX_PLAYERS - 1;i>-1;i--)
                        {
                            if(i != playerid)
                                if(IsPlayerConnected(i))
                                {
                                    APlayerData[playerid][SpectateID] = i;
                                    break;
                                }
                                else continue;
                            else continue;
                        }
                    }
                    else
                    {
                        for(new i=APlayerData[playerid][SpectateID] - 1;i>-1;i--)
                        {
                            if(i != playerid)
                                if(IsPlayerConnected(i))
                                {
                                    APlayerData[playerid][SpectateID] = i;
                                    break;
                                }
                                else continue;
                            else continue;
                        }
                    }
                }
                case ADMIN_SPEC_TYPE_VEHICLE:
                {
                    if(APlayerData[playerid][SpectateID] != -1)
                    {
                        if(APlayerData[playerid][SpectateID] == 0)
                        {
                            for(new i=MAX_PLAYERS - 1;i>-1;i--)
                            {
                                if(i != playerid)
                                    if(IsPlayerConnected(i))
                                    {
                                        APlayerData[playerid][SpectateID] = i;
                                        break;
                                    }
                                    else continue;
                                else continue;
                            }
                        }
                        else
                        {
                            for(new i=APlayerData[playerid][SpectateID] - 1;i>-1;i--)
                            {
                                if(i != playerid)
                                    if(IsPlayerConnected(i))
                                    {
                                        APlayerData[playerid][SpectateID] = i;
                                        break;
                                    }
                                    else continue;
                                else continue;
                            }
                        }
                    }
                    else
                    {
                        if(APlayerData[playerid][SpectateVehicle] == 1)
                        {
                            for(new i=MAX_VEHICLES;i>0;i--)
                            {
                                if(400 <= GetVehicleModel(i) <= 611)
                                {
                                    APlayerData[playerid][SpectateVehicle] = i;
                                    break;
                                }
                                else continue;
                            }
                        }
                        else
                        {
                            for(new i=APlayerData[playerid][SpectateVehicle] - 1;i>0;i--)
                            {
                                if(400 <= GetVehicleModel(i) <= 611)
                                {
                                    APlayerData[playerid][SpectateVehicle] = i;
                                    break;
                                }
                                else continue;
                            }
                        }
                    }
                }
            }
        }
    }
Since I have disabled spectating yourself,and its my test server and no other players come,I could only test with spectating vehicles.But when I go in the server,and spectate a vehicle,I press Num4/Num6(separately) as they have to be the KEY_ANALOG_RIGHT and KEY_ANALOG_LEFT but nothing happens.It should switch to the next/previous vehicleid but as I said nothing happens.I just wonder if I have made something wrong in the function I have created,or there's some problem with the keys.I took a look at the keys page in SAMP wiki,but it doesnt say anything about these keys not working in spectate mode.Please help me solve this problem.

EDIT: Problem fixed.