Police pullover
#1

Hey guys, i made a code that should tell the closest player to pull over, however it doesn't work, can you guys see any errors?
PHP код:
CMD:pu(playeridparams[])
{
    new 
vehicleid;
    
vehicleid GetClosestVehiclePolice(playerid);
    for (new 
checkwantedpullcheckwantedpull MAX_PLAYERScheckwantedpull++)
    if(
gTeam[playerid] == POLICE)
    {
    if(
IsPlayerInVehicle(checkwantedpullvehicleid) && GetPlayerWantedLevel(checkwantedpull) >= 1)
     {
        
GameTextForPlayer(checkwantedpull,"~b~ POLICE REQUEST~n~~r~PULL OVER",6000,5);
        
SendClientMessage(playeridCOLOR_BLUE"Pull over request sent.");
     }
    }
    return 
1;

It uses a stock which detects the nearest vehicle.
Reply
#2

not a wrighter but just stoped in to say if you get it working it would be sweet good luck with it
Reply
#3

Can you post the GetClosestVehiclePolice stock, please?
Reply
#4

Quote:
Originally Posted by Eric
Посмотреть сообщение
Can you post the GetClosestVehiclePolice stock, please?
Hey eric, Stu has gone to bed... so i'll post our stock on his behalf.

Код:
stock GetClosestVehiclePolice(playerid)
	{
	#pragma unused playerid
	new Float:x, Float:y, Float:z;
	new Float:dist, Float:closedist=50, closeveh;
	for(new i=1; i < MAX_VEHICLES; i++)
	{
	if(GetVehiclePos(i, x, y, z))
	{
	dist = GetPlayerDistanceFromPoint(playerid, x, y, z);

	if(dist < closedist)
	{
	closedist = dist;
	closeveh = i;
	}
	}
}
	return closeveh;
}
Reply
#5

Can anybody help me with this?
Reply
#6

eric is working on it from what it looks like just check back in a day hes goos he helped me with a script good luck bro
Reply
#7

Try this:

Add these stocks;

pawn Код:
stock GetDistancePlayerVeh(playerid, veh) {

    new
        Float:Floats[7];

    GetPlayerPos(playerid, Floats[0], Floats[1], Floats[2]);
    GetVehiclePos(veh, Floats[3], Floats[4], Floats[5]);
    Floats[6] = floatsqroot((Floats[3]-Floats[0])*(Floats[3]-Floats[0])+(Floats[4]-Floats[1])*(Floats[4]-Floats[1])+(Floats[5]-Floats[2])*(Floats[5]-Floats[2]));

    return floatround(Floats[6]);
}

stock GetClosestVehicle(playerid, exception = INVALID_VEHICLE_ID) {
    new
        Float:Distance,
        target = -1;

    for(new v; v < MAX_VEHICLES; v++) if(doesVehicleExist(v)) {
        if(v != exception && (target < 0 || Distance > GetDistancePlayerVeh(playerid, v))) {
            target = v;
            Distance = GetDistancePlayerVeh(playerid, v);
        }
    }
    return target;
}

stock doesVehicleExist(const vehicleid) {
    if(GetVehicleModel(vehicleid) >= 400) {
        return 1;
    }
    return 0;
}

stock IsPlayerInRangeOfVehicle(playerid, vehicleid, Float: radius) {

    new
        Float:Floats[3];

    GetVehiclePos(vehicleid, Floats[0], Floats[1], Floats[2]);
    return IsPlayerInRangeOfPoint(playerid, radius, Floats[0], Floats[1], Floats[2]);
}
Try using this command after adding the above stocks.

pawn Код:
CMD:pu(playerid, params[])
{

    new vehicleid = GetClosestVehicle(playerid);
    for (new checkwantedpull; checkwantedpull < MAX_PLAYERS; checkwantedpull++)

    if(gTeam[playerid] == POLICE) {
        if(IsPlayerInRangeOfVehicle(playerid, vehicleid, 15.0) {
            if(IsPlayerInVehicle(checkwantedpull, vehicleid) && GetPlayerWantedLevel(checkwantedpull) >= 1) {
                GameTextForPlayer(checkwantedpull,"~b~ POLICE REQUEST~n~~r~PULL OVER",6000,5);
                SendClientMessage(playerid, COLOR_BLUE, "Pull over request sent.");
            }
            else SendClientMessage(playerid, COLOR_GREY, "That player is not wanted!");
        }
        else SendClientMessage(playerid, COLOR_GREY, "You are too far away from that vehicle!");
    }
    return 1;
}
Those stocks were taken from my script so it may need a bit of tweaking. We'll see.
Reply
#8

@Eric, your codes will absolutly not work, it will always return the vehicle of the playerid ( for the closest vehicle). I'll try something, tell me if it works.
pawn Код:
stock GetClosestVehiclePolice(playerid)
{
    new Float:x, Float:y, Float:z;
    new Float:dist, Float:closedist=50, closeveh, found = 0;
    for(new i=1; i < MAX_VEHICLES; i++)
    {
        if(GetVehiclePos(i, x, y, z) && i != GetPlayerVehicleID(playerid))
        {
            dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
            if(dist < closedist)
            {
                    found = 1;
                closedist = dist;
                closeveh = i;
            }
        }
        }
    if(found == 1) return closeveh;
        return 0;
}
I'm not sure about the command. It's the original one, but you missed a bracket.
pawn Код:
CMD:pu(playerid, params[])
{

    new vehicleid;
    vehicleid = GetClosestVehiclePolice(playerid);
        if(vehicleid == 0) return SendClientMessage(playerid, -1, "There is no near vehicle");
    for (new checkwantedpull; checkwantedpull < MAX_PLAYERS; checkwantedpull++)
        {

        if(gTeam[playerid] == POLICE)
        {
            if(IsPlayerInVehicle(checkwantedpull, vehicleid) && GetPlayerWantedLevel(checkwantedpull) >= 1)
                {
            GameTextForPlayer(checkwantedpull,"~b~ POLICE REQUEST~n~~r~PULL OVER",6000,5);
            SendClientMessage(playerid, COLOR_BLUE, "Pull over request sent.");
                }
            }
        }
        return 1;
}
Reply
#9

Quote:
Originally Posted by lelemaster
Посмотреть сообщение
@Eric, your codes will absolutly not work, it will always return the vehicle of the playerid ( for the closest vehicle). I'll try something, tell me if it works.
pawn Код:
stock GetClosestVehiclePolice(playerid)
{
    new Float:x, Float:y, Float:z;
    new Float:dist, Float:closedist=50, closeveh, found = 0;
    for(new i=1; i < MAX_VEHICLES; i++)
    {
        if(GetVehiclePos(i, x, y, z) && i != GetPlayerVehicleID(playerid))
        {
            dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
            if(dist < closedist)
            {
                    found = 1;
                closedist = dist;
                closeveh = i;
            }
        }
        }
    if(found == 1) return closeveh;
        return 0;
}
I'm not sure about the command. It's the original one, but you missed a bracket.
pawn Код:
CMD:pu(playerid, params[])
{

    new vehicleid;
    vehicleid = GetClosestVehiclePolice(playerid);
    for (new checkwantedpull; checkwantedpull < MAX_PLAYERS; checkwantedpull++)
        {

        if(gTeam[playerid] == POLICE)
        {
            if(IsPlayerInVehicle(checkwantedpull, vehicleid) && GetPlayerWantedLevel(checkwantedpull) >= 1)
                {
            GameTextForPlayer(checkwantedpull,"~b~ POLICE REQUEST~n~~r~PULL OVER",6000,5);
            SendClientMessage(playerid, COLOR_BLUE, "Pull over request sent.");
                }
            }
        }
        return 1;
}
The stock works fine, I use it in my own script.
Are you sure you read it right?
Reply
#10

Take those codes, I fixed and tested them. It will work.
pawn Код:
stock GetClosestVehiclePolice(playerid)
{
    new Float:x, Float:y, Float:z;
    new Float:dist, Float:closedist=50, closeveh, found = 0;
    for(new i=1; i < MAX_VEHICLES; i++)
    {
        if(GetVehiclePos(i, x, y, z) && i != GetPlayerVehicleID(playerid))
        {
            dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
            if(dist < closedist)
            {
                found = 1;
                closedist = dist;
                closeveh = i;
            }
        }
    }
    if(found == 1) return closeveh;
    return 0;
}
CMD:pu(playerid, params[])
{
    new vehicleid;
    vehicleid = GetClosestVehiclePolice(playerid);
    if(vehicleid == 0) return SendClientMessage(playerid, -1, "There is no near vehicle.");
    if(!IsPlayerInAnyVehicle(playerid)) return  SendClientMessage(playerid, -1, "You are not in any vehicle.");
    if(PlayerInfo[playerid][pFaction] == 1)
    {
        for (new checkwantedpull = 0; checkwantedpull < MAX_PLAYERS; checkwantedpull++)
        {
            if(GetPlayerVehicleSeat(checkwantedpull) == 0 && IsPlayerInVehicle(checkwantedpull, vehicleid) && GetPlayerWantedLevel(checkwantedpull) >= 1)
            {
                GameTextForPlayer(checkwantedpull,"~b~ POLICE REQUEST~n~~r~PULL OVER",6000,5);
                SendClientMessage(playerid, COLOR_BLUE, "Pull over request sent.");
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)