SA-MP Forums Archive
[Not Solved] PlayernearVehicle car for my alarm system. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Not Solved] PlayernearVehicle car for my alarm system. (/showthread.php?tid=90448)



[Not Solved] PlayernearVehicle car for my alarm system. - Ben147 - 08.08.2009

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?


Re: PlayernearVehicle car for my alarm system. - Woet - 08.08.2009

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


Re: PlayernearVehicle car for my alarm system. - Ben147 - 08.08.2009

i already readed it, but still i need help.


Re: PlayernearVehicle car for my alarm system. - Dark_Kostas - 08.08.2009

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;
}



Re: PlayernearVehicle car for my alarm system. - Ben147 - 08.08.2009

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.



Re: PlayernearVehicle car for my alarm system. - ev0lution - 08.08.2009

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



Re: PlayernearVehicle car for my alarm system. - Ben147 - 08.08.2009

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


Re: PlayernearVehicle car for my alarm system. - Ben147 - 08.08.2009

CAN Someone Help me?


Re: PlayernearVehicle car for my alarm system. - Dark_Kostas - 10.08.2009

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.


Re: PlayernearVehicle car for my alarm system. - Ben147 - 10.08.2009

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;
 	}
 	}
 	}