Serious Problem I need help with (keys) -
jakejohnsonusa - 24.11.2012
Ok I have been having serious problems with keys in my GM.
The problem is is that it doesn't work right, If I'm in a car it uses the Default onfoot key EVEN though I'm in a car (and somtimes it doesn't even work at all! This is very frustrating. I am a newer scripter so I have no idea what could be wrong
PLEASE help me. I usually Rep those who can help me (for those who care).
Thanks: jakejohnsonusa
Here is an example of a key command I am having problems with:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new string[128];
new sendername[MAX_PLAYER_NAME];
new pveh = GetVehicleModel(GetPlayerVehicleID(playerid));
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;
{
ToggleVehicleLights(newcar)
}
}
}
if (newkeys & HANDBRAKE )
{
if(IsPlayerInAnyVehicle(playerid))
{
if(IsPlayerConnected(playerid))
{
new idcar = GetPlayerVehicleID(playerid);
if(gEngine[idcar] == 0)
{
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
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);
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;
}
}
}
}
**In this case it doesn't always start with the Handbrake in vehicle key (space), but it usually works with the Aim Key (right click)**
Note: I DON't Need the link to GetPlayerKeys I've read that!
Re: Serious Problem I need help with (keys) -
cessil - 24.11.2012
pawn Код:
if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return 1;
{
ToggleVehicleLights(newcar)
}
not sure what you're trying to do here, you have a return, then you have open brackets, once you return then the function ends
Re: Serious Problem I need help with (keys) -
jakejohnsonusa - 24.11.2012
Actually that part works (that's the light system on and off), it's the handbrake key part that doesn't. The handbrake one turns the engine on and off, but it doesn't seem to work right... Somtimes it works with space, somtimes it works with the aim key, and somtimes it doesn't work at all... I can't seem to find what's wrong.
I've tried if (newkeys & HANDBRAKE ) , if(PRESSED(KEY_HANDBRAKE)) , and if (newkeys == KEY_HANDBRAKE)
Re: Serious Problem I need help with (keys) -
cessil - 24.11.2012
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;
}
}
}
}
Re: Serious Problem I need help with (keys) -
jakejohnsonusa - 24.11.2012
So I added:
pawn Код:
if((oldkeys & HANDBRAKE) && !(newkeys & HANDBRAKE))
and I get:
Код:
error 017: undefined symbol "HANDBRAKE"
Would it be KEY_HANDBRAKE?
Re: Serious Problem I need help with (keys) -
cessil - 24.11.2012
well that HANDBRAKE was from your script, so you should know what it should be
Re: Serious Problem I need help with (keys) -
jakejohnsonusa - 24.11.2012
Ok so I did KEY_HANDBRAKE, since I'm in a car that should be the space bar... but for some reason it's the out of car key (Right Click / KEY_AIM). When I use /engine (does the same thing but it's a cmd) and then turn it on and off the space bar
then will turn it on. So I still have the same problem.
Re: Serious Problem I need help with (keys) -
jakejohnsonusa - 24.11.2012
I found the answer. To anyone who ever has this problem again read this:
https://sampforum.blast.hk/showthread.php?tid=195664
The problem often times is TogglePlayerControllable is off, it's been a bug in SA-MP from what I can see for 2 years. Would be great if the bug could be fixed in the next version/update of SA-MP
-jakejohnsonusa