onplayerkeystatechange
#1

Heey all,
I want to make if a player press 2 in car they can arrest players and it work if a player dont drive,so they dont give gas and then they can arrest a player.
But how can i make if a player drive he can arrest a player?
Code:
Code:
if (newkeys == KEY_SUBMISSION && GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid))
 	{
		new ID = GetClosestPlayerToPlayer(playerid);
		dcmd_arrestkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
		dcmd_ticketkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
		if(GetPlayerWantedLevel(ID)==0 && GetDistanceBetweenPlayers(playerid,ID) > 4)
		{
			SendClientMessage(playerid,COLOR_RED,"No Suspect In Range!");
		}
		return 1;
	}
Thanks admigo
Reply
#2

pawn Code:
if(!IsPlayerInAnyVehicle(ID))//Is not driving any vehicle
Reply
#3

Fixed it thanks:P
But now i have other problem with it.
I made a key for selling car at shipyard but i dont get the error messages.
Example:if you are not in car and press the key you dont get error and if your in car you dont get error that you need to be in checkpoint:S
Code:
Code:
if (newkeys == KEY_SUBMISSION/* && IsPlayerInAnyVehicle(playerid)*/)
 	{
		if(gTeam[playerid]==TEAM_COP  && GetPlayerState(playerid)==PLAYER_STATE_DRIVER )
		{
			new ID = GetClosestPlayerToPlayer(playerid);
			dcmd_arrestkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
			dcmd_ticketkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
			if(GetPlayerWantedLevel(ID)==0 && GetDistanceBetweenPlayers(playerid,ID) > 4)
			{
				SendClientMessage(playerid,COLOR_RED,"No Suspect In Range!");
				return 1;
			}
			return 1;
		}
		if(gTeam[playerid]!=TEAM_COP && gTeam[playerid]!=TEAM_SECRETAGENT)
		{
			dcmd_sellcarkey(playerid, IntToStr(playerid));
			if(!IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)
			{
			    SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle if you want to sell one.");
			    return 1;
			}
			if(getCheckpointType(playerid) != CP_ShipYard)
			{
				SendClientMessage(playerid,COLOR_RED,"You can only sell the car at the Shipyard!");
				return 1;
			}
			return 1;
		}
		return 1;
	}
Pls help
Reply
#4

pawn Code:
if(gTeam[playerid]!=TEAM_COP && gTeam[playerid]!=TEAM_SECRETAGENT)
        {
            if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
            {
                SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle if you want to sell one.");
                return 1;
            }
            if(getCheckpointType(playerid) != CP_ShipYard)
            {
                SendClientMessage(playerid,COLOR_RED,"You can only sell the car at the Shipyard!");
                return 1;
            }
            dcmd_sellcarkey(playerid, IntToStr(playerid));
            return 1;
        }
        return 1;
    }
Reply
#5

Why if i press behind button(mmb) i get the error:You must be in a vehicle if you want to sell one.Its needs to be if you press 2. And when i am in vehicle and i press 2 i dont get error that i need to be in cp.
Code:
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK && PlayerToPoint(1.0, playerid, -1619.1694,689.5911,7.1875)) //SFPD Shutter Inside
	{
  		if(gTeam[playerid] != TEAM_COP)
		{
			SendClientMessage(playerid,COLOR_RED,"Access Denied");
			return 1;
		}
		SetPlayerPos(playerid, -1619.1694,689.5911,7.1875);
		SetPlayerFacingAngle(playerid, 269.9927);
		LoopingAnim(playerid, "HEIST9", "Use_SwipeCard", 3.0, 0, 0, 0, 0, 0);
		if(SFPDShutterOpen == 0)
		{
			MoveObject(SFPDShutter, -1620.61669922,688.17712402,12.80728531, 4);
			SendClientMessage(playerid, COLOR_DODGERBLUE, "Access Granted");
			SFPDShutterOpen =1;
			return 1;
		}
		if(SFPDShutterOpen == 1)
		{
			MoveObject(SFPDShutter, -1620.61669922,688.17712402,7.80728531, 4);
			SFPDShutterOpen =0;
			return 1;
		}
		return 1;
	}
	if (newkeys == KEY_SUBMISSION/* && IsPlayerInAnyVehicle(playerid)*/)
 	{
		if(gTeam[playerid]==TEAM_COP  && GetPlayerState(playerid)==PLAYER_STATE_DRIVER )
		{
			new ID = GetClosestPlayerToPlayer(playerid);
			dcmd_arrestkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
			dcmd_ticketkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
			if(GetPlayerWantedLevel(ID)==0 && GetDistanceBetweenPlayers(playerid,ID) > 4)
			{
				SendClientMessage(playerid,COLOR_RED,"No Suspect In Range!");
				return 1;
			}
			return 1;
		}
		if(gTeam[playerid]!=TEAM_COP && gTeam[playerid]!=TEAM_SECRETAGENT)
        {
            if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
            {
                SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle if you want to sell one.");
                return 1;
            }
            if(getCheckpointType(playerid) != CP_ShipYard)
            {
                SendClientMessage(playerid,COLOR_RED,"You can only sell the car at the Shipyard!");
                return 1;
            }
            dcmd_sellcarkey(playerid, IntToStr(playerid));
            return 1;
        }
		return 1;
	}

	if (newkeys == KEY_FIRE)
 	{
		TextDrawHideForPlayer(playerid,TextDraw1);
		TextDrawHideForPlayer(playerid,TextDraw2);
		TextDrawHideForPlayer(playerid,TextDraw3);
		TextDrawHideForPlayer(playerid,TextDraw4);
		TextDrawHideForPlayer(playerid,TextDraw5);
		TextDrawHideForPlayer(playerid,TextDraw6);
		TextDrawHideForPlayer(playerid,TextDraw7);
		return 1;
	}
 	if(newkeys == KEY_LOOK_BEHIND)
	{
		new ID = GetClosestPlayerToPlayer(playerid);
		dcmd_arrestkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
		dcmd_ticketkey(playerid, IntToStr(GetClosestPlayerToPlayer(playerid)));
		if(GetPlayerWantedLevel(ID)==0 && GetDistanceBetweenPlayers(playerid,ID) > 4)
		{
			SendClientMessage(playerid,COLOR_RED,"No Suspect In Range!");
			return 1;
		}
		return 1;
	}
	if(newkeys & KEY_SECONDARY_ATTACK && PlayerToPoint(1.0, playerid, -1622.1335,687.1992,7.1875)) //SFPD Shutter Outside
	{
		if(gTeam[playerid] != TEAM_COP)
		{
			SendClientMessage(playerid,COLOR_RED,"Access Denied");
			return 1;
		}
		SetPlayerPos(playerid, -1622.1335,687.1992,7.1875);
		SetPlayerFacingAngle(playerid, 0.2336);
		LoopingAnim(playerid, "HEIST9", "Use_SwipeCard", 3.0, 0, 0, 0, 0, 0);
		if(SFPDShutterOpen == 0)
		{
			MoveObject(SFPDShutter, -1620.61669922,688.17712402,12.80728531, 4);
			SendClientMessage(playerid, COLOR_DODGERBLUE, "Access Granted");
			SFPDShutterOpen =1;
			return 1;
		}
		if(SFPDShutterOpen == 1)
		{
			MoveObject(SFPDShutter, -1620.61669922,688.17712402,7.80728531, 4);
			SFPDShutterOpen =0;
			return 1;
		}
		return 1;
	}
	return 1;
}
Can you pls help me? I dont know whats wrong.
Reply
#6

Hello, I am trying same code but i have one Error ..
Can you help Please error 017: undefined symbol "IntToStr" .

... Solved ...

#include <dutils>

DOWNLAOD IT FROM http://dracoblue.net/download/dutils-110/30/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)