public GetClosestPlayerToPlayer(playerid)
{
new Float:dist = 500.0;
new targetid = INVALID_PLAYER_ID;
new Float:x1,Float:y1,Float:z1;
new Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
for(new i=0;i<MAX_PLAYERS;i++)
{
if(i == playerid) continue;
if(pInfo[i][Team] != pInfo[playerid][Team]) continue;
if(GetVehicleModel(GetPlayerVehicleID(i) != 511) || GetVehicleModel(GetPlayerVehicleID(i) != 476)) continue;
GetPlayerPos(i,x2,y2,z2);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
if(tmpdis < dist)
{
dist = tmpdis;
targetid = i;
}
}
return targetid;
}
if(pInfo[i][Team] != pInfo[playerid][Team]) continue;
if(pInfo[i][Team] == pInfo[playerid][Team]) continue;
if(pInfo[i][Team] == pInfo[playerid][Team]) continue;
public CheckPlayersInRangeOfAA(playerid)
{
new
near = GetClosestPlayerToPlayer(playerid),
Float:NearPos[3],
Float:x,Float:y,Float:z,
string[128];
if(pInfo[playerid][Team] != pInfo[near][Team]) /* If their teams dont match, aka not same team*/
{
GetPlayerPos(near,NearPos[0],NearPos[1],NearPos[2]); /* Getting that player position that we are going to shoot */
if(IsPlayerInRangeOfPoint(playerid,200,x,y,z)) /* Checking if playerid is in of Near */
{
GetPlayerPos(playerid,x,y,z); /* Getting player positions to create object that we are going to move*/
AAC = CreateObject(18647,x,y,z,0,0,0,0); /* Creating the object */
SetObjectToFaceCords(AAC, NearPos[0],NearPos[1],NearPos[2]); /* Setting the object to face other player*/
MoveObject(AAC,NearPos[0],NearPos[1],NearPos[2],100); /* moving the object */
format(string,sizeof(string),"Send a rocket towards %s",GetName(near));
}
}
return true;
}
if(i == playerid || !IsPlayerConnected(i) || pInfo[i][Team] == pInfo[playerid][Team] || vmodel == 511 || vmodel == 476) continue;
Yes thanks but I want to check if the player is ONLY in the beagle rustler
|
public GetClosestPlayerToPlayer(playerid)
{
new targetid = INVALID_PLAYER_ID;
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new Float:closestdist = 999.0, Float:Dis, i; i<MAX_PLAYERS; i++) // You should use foreach or GetPlayerPoolSize
{
vmodel = GetVehicleModel(GetPlayerVehicleID(i));
if(i == playerid || !IsPlayerConnected(i) || pInfo[i][Team] == pInfo[playerid][Team] || vmodel != 511 || vmodel != 476) continue;
Dis = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(Dis < closestdist)
{
closestdist = Dis;
targetid = i;
}
}
return targetid;
}
public CheckPlayersInRangeOfAA(playerid)
{
new id = GetClosestPlayerToPlayer(playerid),
Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if(id != INVALID_PLAYER_ID && IsPlayerInRangeOfPoint(id, 200, x, y, z))
{
AAC = CreateObject(18647,x,y,z,0,0,0,0);
GetPlayerPos(id, x, y, z);
SetObjectToFaceCords(AAC, x, y, z);
MoveObject(AAC,x, y, z, 100);
new string[128];
format(string,sizeof(string),"Send a rocket towards %s",GetName(id));
}
return true;
}
public CheckPlayersInRangeOfAA(playerid)
{
new id = INVALID_PLAYER_ID,
Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new Float:closestdist = 200.0, Float:Dis, vmodel, i; i<MAX_PLAYERS; i++) // You should use foreach or GetPlayerPoolSize
{
vmodel = GetVehicleModel(GetPlayerVehicleID(i));
if(i == playerid || !IsPlayerConnected(i) || pInfo[i][Team] == pInfo[playerid][Team] || vmodel != 511 || vmodel != 476) continue;
//If he's not in a Rustler/Beagle we're not checking him
Dis = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(Dis < closestdist)
{
closestdist = Dis;
id = i;
}
}
if(id != INVALID_PLAYER_ID)
{
AAC = CreateObject(18647,x,y,z,0,0,0,0);
GetPlayerPos(id, x, y, z);
SetObjectToFaceCords(AAC, x, y, z);
MoveObject(AAC,x, y, z, 100);
new string[128];
format(string,sizeof(string),"Send a rocket towards %s",GetName(id));
}
return true;
}
What are you trying to do and why doesn't it work ?
This should check if somebody's on a rustler and closer then 200 GTA unit then create something and make it go toward the player |
format(string,sizeof(string),"Sent a rocket towards %s",GetName(id));
if(id != INVALID_PLAYER_ID)
{
AAC = CreateObject(18647,x,y,z,0,0,0,0);
GetPlayerPos(id, x, y, z);
SetObjectToFaceCords(AAC, x, y, z);
MoveObject(AAC,x, y, z, 100);
new string[128];
format(string,sizeof(string),"Sent a rocket towards %s",GetName(id));
}