How to do this command (+REP)? - 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: How to do this command (+REP)? (
/showthread.php?tid=649878)
[SOLVED]How to do this command (+REP)? -
spyro9696 - 16.02.2018
Hello, I use that code for Super Break on vehicles (by pressing Space twice), and the vehicle stops immediately.
Possibly, can you help me to create the command
to activate / deactivate it in ZCMD?
Код:
new bool:PressedBreak[MAX_PLAYERS], BreakCD[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
{
if(newkeys & KEY_HANDBRAKE)
{
new count = GetTickCount();
if((count - BreakCD[playerid]) >= 500)
{
BreakCD[playerid] = count;
PressedBreak[playerid] = false;
}
else PressedBreak[playerid] = true;
if(PressedBreak[playerid])
{
PressedBreak[playerid] = false;
new veh = GetPlayerVehicleID(playerid);
new Float:x, Float:y, Float:z;
GetVehiclePos(veh, x, y, z);
SetVehiclePos(veh, x, y, z);
}
}
}
return 1;
}
Re: How to do this command (+REP)? -
Crayder - 16.02.2018
First off, you're over complicating everything... lol
pawn Код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new BreakCD[MAX_PLAYERS], bool:CanSuperBreak[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(CanSuperBreak[playerid] && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(PRESSED(KEY_HANDBRAKE))
{
new count = GetTickCount(), veh = GetPlayerVehicleID(playerid);
if((count - BreakCD[playerid]) < 500)
{
SetVehicleAngularVelocity(veh, 0.0, 0.0, 0.0);
SetVehicleVelocity(veh, 0.0, 0.0, 0.0);
}
BreakCD[playerid] = count
}
}
return 1;
}
CMD:togsb(playerid, params[])
{
new str[128];
CanSuperBreak[playerid] = !CanSuperBreak[playerid];
format(str, sizeof str, "You toggled super breaks %s", CanSuperBreak[playerid] ? ("{00FF00}On") : ("{FF0000}Off"));
SendClientMessage(playerid, 0xFFFF00FF, str);
return 1;
}
So what I did was simplify your driver check with GetPlayerState, add a better check for the handbreak key, and used velocity to stop the vehicle instead of position. I added the command to show you how simple it is to toggle it, but of course you probably want to add your own spin to it.
Re: How to do this command (+REP)? -
spyro9696 - 16.02.2018
Ok, but the command to re-activate it?
Re: How to do this command (+REP)? -
spyro9696 - 16.02.2018
Ah no sorry, it's good. Thanks! +REP