How to do this command (+REP)?
#1

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;
}
Reply
#2

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.
Reply
#3

Ok, but the command to re-activate it?
Reply
#4

Ah no sorry, it's good. Thanks! +REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)