[Not Solved] PlayernearVehicle car for my alarm system.
#1

ok i made a simple alarm system but i can turn off the alarm in my vehicle only in the car
and when the owner car enable the alarm and he want back to the vehicle the alarm is automatic starting.
so im trying to make a faction or command, that the owner car can turn off the alarm near the car.

something like this

Код:
if(IsPlayerNearVehicle(playerid,carid) && CarInfo[carid][cOwned]==1)
can someone help me?
Reply
#2

https://sampwiki.blast.hk/wiki/GetPlayerPos
https://sampwiki.blast.hk/wiki/GetVehiclePos
And some basic math.

Or use the PlayerToPoint function:
https://sampwiki.blast.hk/wiki/Automatic_Gates
Reply
#3

i already readed it, but still i need help.
Reply
#4

It was so easy to get PlayerToPoint and do some transformations. By the way. This script is not tested.

pawn Код:
forward PlayerToVehicle(Float:radi, playerid, carid);

public PlayerToVehicle(Float:radi, playerid, carid)
{
  if(IsPlayerConnected(playerid))
    {
        new Float:x, Float:y, Float:z;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        GetVehiclePos(carid, x, y, z);
        tempposx = (oldposx -x);
        tempposy = (oldposy -y);
        tempposz = (oldposz -z);
        //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
        {
            return 1;
        }
    }
    return 0;
}
Reply
#5

This is my if

Код:
  if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1 || PlayerToVehicle(radi,playerid,carid) && CarInfo[carid][cOwned]==1)
	{
i did like this, and still when im near the vehicle and im doing the command nothing happen
and insite the vehicle its works.
Reply
#6

Try:
Код:
  if((IsPlayerInVehicle(playerid,carid) || PlayerToVehicle(radi,playerid,carid)) && CarInfo[carid][cOwned] == 1)
Reply
#7

Код:
if((IsPlayerInVehicle(playerid,carid) || PlayerToVehicle(radi,playerid,carid)) && CarInfo[carid][cOwned] == 1)
Still ... only in the vehicle its works.
Reply
#8

CAN Someone Help me?
Reply
#9

Just saw your problem. On radi, you should put the radius around your vehicle. For example 5meters.

pawn Код:
if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1 || PlayerToVehicle(5,playerid,carid) && CarInfo[carid][cOwned]==1)
Do something like this. It should work.
Reply
#10

Damn, Still only in the vehicle its works

Here is my full /turnalarm code if its willhelp:



Код:
	if (strcmp("/turnalarm", cmdtext, true, 10) == 0)
	{
  new carid;
	new getcarid;
	if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { carid = PlayerInfo[playerid][pPcarkey]; }
	else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { carid = PlayerInfo[playerid][pPcarkey2]; }
	else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { carid = PlayerInfo[playerid][pPcarkey3]; }
	else { return 1; }
	getcarid = GetPlayerVehicleID(playerid);
	GetPlayerName(playerid, playername, sizeof(playername));
	//GetVehiclePos(carid, x, y, z);
	//GetPlayerFacingAngle(playerid, a);
	//GetVehicleZAngle(carid, a);
  if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1 || PlayerToVehicle(5,playerid,carid) && CarInfo[carid][cOwned]==1)
	{
	if(PlayerInfo[playerid][pPcarkey] == 999 && PlayerInfo[playerid][pPcarkey2] == 999 & PlayerInfo[playerid][pPcarkey3])
	{
	SendClientMessage(playerid, COLOR_GREY, "You don't own a car.");
	return 1;
	}
	if(getcarid == carid)
	{
			if(Alarmed[getcarid] == 1)
			{
				if(AlarmStatus[getcarid] == 1)
	  		{
	    		AlarmStatus[getcarid] = 0;
	    		SendClientMessage(playerid, COLOR_YELLOW, "You have succefully turned your vehicle alarm OFF");
					return 1;
	 			}
   			else if(AlarmStatus[getcarid] == 0)
	  		{
	    		AlarmStatus[getcarid] = 1;
	    		SendClientMessage(playerid, COLOR_YELLOW, "You have succefully turned your vehicle alarm ON");
					return 1;
				}
		 	}
   		else
   		{
   	  	SendClientMessage(playerid, COLOR_YELLOW, "You don't own an alarm");
   	  	return 1;
  	 		}
	return 1;
 	}
 	}
 	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)