24.11.2012, 02:49
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new string[128];
new sendername[MAX_PLAYER_NAME];
new pveh = GetVehicleModel(GetPlayerVehicleID(playerid));//you can move these down under into the key checks so you don't use these functions every time a player presses or releases a key
new newcar = GetPlayerVehicleID(playerid);
new gun1 = GetPlayerWeapon(playerid);
new gunname1[24];
GetWeaponName(gun1,gunname1,sizeof(gunname1));
if ( PRESSED(KEY_SUBMISSION) ) //light system
{
if (IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return 1;
if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return 1;//this doesn't make sense
{
ToggleVehicleLights(newcar)//remember to end lines with ;
}
}
}
if((oldkeys & HANDBRAKE) && !(newkeys & HANDBRAKE))//player released handbrake
{
if(IsPlayerInAnyVehicle(playerid))// just check if they're a driver state
{
if(IsPlayerConnected(playerid))//this check is useless
{
new idcar = GetPlayerVehicleID(playerid);
if(gEngine[idcar] == 0)//are you sure this will equal 0? show proof!
{
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;//wouldn't need this check if you checked they were a driver instead of in a vehicle
if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
if(IsARentableCar(idcar))
{
if(HireCar[playerid] != idcar) return 1;
}
if(IsAHarvest(idcar)) return 1;
if(IsADrugHarvest(idcar)) return 1;
if(IsASweeper(idcar)) return 1;
if(CanTurnEngine[playerid] != idcar && CanTurnEngine[playerid] == 9999)
return SendClientMessage(playerid, COLOR_GREY,"* You cannot turn this car's engine!");
format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", sendername);
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);//you can create default args for stocks/functions so you don't have to type out every argument unless you want it to be something different, also a define for the radius would be smarter instead of hard coding the range everywhere
SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3);
gEngine[idcar] = 1;
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, lights, 0, 0, 0, 0, 0);
new y, m, d;
new h,mi,s;
getdate(y,m,d);
gettime(h,mi,s);
format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /engine",d,m,y,h,mi,s,sendername);
CommandLog(string);
return 1;
}
}
}
}