why dosent work ?
#1

Hey, i wanna made when a player press "2" turn on the lights, and when the player press "2" again, the lights turn OFF, the problem is what the lights dosent turn OFF, why ?


pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
        new vehicleid = GetPlayerVehicleID(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
        {
            if(IsPlayerInVehicle(playerid, vehicleid))
            {
               
                GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(vehicleid,engine,true,alarm,doors,bonnet,boot,objective);
            } else SetVehicleParamsEx(vehicleid,engine,false,alarm,doors,bonnet,boot,objective);
        }
    return 1;
}
??
Reply
#2

Notice the changes:
pawn Код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))        
{            
    if(IsPlayerInVehicle(playerid, vehicleid))            
   {                                
       GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
       SetVehicleParamsEx(vehicleid,engine,true,alarm,doors,bonnet,boot,objective);            
   }
   else
   {
       GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective); //Was missing
       SetVehicleParamsEx(vehicleid,engine,false,alarm,doors,bonnet,boot,objective);        
   }
   return 1;
}
Reply
#3

Thanks men.
Reply
#4

?? is that code supposed to work? i mean, if a player is not in a vehicle, then the lights may get switched off? how can a player not be in a vehicle, and turn off its lights?
lights=0; 1-lights=1;
lights=1; 1-lights=0;
so you can do:
pawn Код:
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehicleid,engine,1-lights,alarm,doors,bonnet,boot,objective);
.. also saves an if-else check as little bonus, heh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)