OnPlayerStateChange only 'sometimes' called.
#1

Hello,

I got since short a weird problem and I don't know due what. I show you two pieces of code.

http://pastebin.com/7Lep6tHB = My OnPlayerStateChange

http://pastebin.com/CmsRvcEu = dcmd_engine

I explain the problem.

My OnPlayerStateChange never gets called, except the player is doing Car Driving Test. Also, only then he can use the command '/engine'. If he is not doing the driving test plus he is in a vehicle it always returns 'SERVER: Unknown Command'. That is weird, cause I have changed that text. When the player is not into a vehicle, it just returns 'You are not in a vehicle.'

I have searched in these codes for ages for the problem, but cannot find.

Regards, Jochem.
Reply
#2

onplayerstatechange is called 'while' a player is changing its state (state on foot to driver,driver to onfoort etc,) thats why your command wont work.
for making a command like /engine you'll need a if(IsPlayerInAnyVehicle... in your command. so when you execute the command it will check if the player is in a vehicle
Reply
#3

I know, but I think you don't understand it. When the player is in a vehicle, he can type /engine but it would return SERVER: Unknown command. This is not when the player is in a Driving License vehicle.
Reply
#4

hmm..im not sure now all iknow is that most of the time SERVER Unknown command shows up when your missing a 'return 1;' somewhere.
sorry cant help you further
Reply
#5

I will look.
Reply
#6

No, no return 1; missing.
Reply
#7

(Bump) Please help, I cannot find the problem!
Reply
#8

Try making the command without "else return" and just use "else" it might work. I'm not %100 sure it will help but it might well do. like this,
pawn Код:
dcmd_engine(playerid,params[])
{
    #pragma unused params
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(vehicleid) != 481 && GetVehicleModel(vehicleid) != 509 && GetVehicleModel(vehicleid) != 510)
        {
            if(VehicleInfo[vehicleid][EngineRunning] == 0)
            {
                if(VehicleInfo[vehicleid][Fuel] > 0)
                {
                    if(PlayerInfo[playerid][IsInUnboughtCar] == 0)
                    {
                        new rand = random(7);
                        if(rand == 0)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* Engine didn't start, try again.");
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around but the engine didn't start.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 1)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 2)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 3)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 4)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 5)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                        else if(rand == 6)
                        {
                            SendClientMessage(playerid,COLOR_WHITE,"* The engine has been started.");
                            VehicleInfo[vehicleid][EngineRunning] = 1;
                            TogglePlayerControllable(playerid,1);
                            PlayerPlaySound(playerid,1133,0,0,0);
                            VehicleInfo[vehicleid][FuelTimer] = SetTimerEx("FuelLower",40000,true,"i",playerid);
                            new Float:PosX, Float:PosY, Float:PosZ;
                            GetPlayerPos(playerid,PosX,PosY,PosZ);
                            foreach(Player,i)
                            {
                                if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                                {
                                    new string[128],Playername[MAX_PLAYER_NAME];
                                    GetPlayerRPName(playerid,Playername,sizeof(Playername));
                                    format(string,sizeof(string),"* %s puts a key into the ignition, twists it around and the engine starts.",Playername);
                                    SendClientMessage(i,COLOR_LIGHTGREY,string);
                                }
                            }
                        }
                    }
                }
                else SendClientMessage(playerid,COLOR_WHITE,"* The engine didn't start because the vehicle is out of fuel.");
            }
            else if(VehicleInfo[vehicleid][EngineRunning] == 1)
            {
                SendClientMessage(playerid,COLOR_WHITE,"* Engine stopped.");
                TogglePlayerControllable(playerid,0);
                KillTimer(VehicleInfo[vehicleid][FuelTimer]);
                VehicleInfo[vehicleid][EngineRunning] = 0;
                new Float:PosX, Float:PosY, Float:PosZ;
                GetPlayerPos(playerid,PosX,PosY,PosZ);
                foreach(Player,i)
                {
                    if(IsPlayerInRangeOfPoint(i,5,PosX,PosY,PosZ))
                    {
                        new string[128],Playername[MAX_PLAYER_NAME];
                        GetPlayerRPName(playerid,Playername,sizeof(Playername));
                        format(string,sizeof(string),"* %s twists the key in the ignition and stops the engine.",Playername);
                        SendClientMessage(i,COLOR_LIGHTGREY,string);
                    }
                }
            }
        }
        else SendClientMessage(playerid,COLOR_RED,"* This vehicle doesn't have an engine.");
    }
    else SendClientMessage(playerid,COLOR_RED,"* You are not in a vehicle.");
    return 1;
}
Reply
#9

But I haven't changed anything in the command. It had always been like this and all my commands are made this way :S
Reply
#10

Nop, still SERVER: Unknown command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)