28.07.2009, 07:01
Try this
pawn Code:
forward GetClosestPlayer(p1); //at the top of script
forward Float:GetDistanceBetweenPlayers(p1,p2);
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
pawn Code:
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5) //pretty much anywhere aslong as it's outside other callbacks
{
if(IsPlayerConnected(playerid))
{
new Float:posx, Float:posy, Float:posz;
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerPos(i, posx, posy, posz);
tempposx = (oldposx -posx);
tempposy = (oldposy -posy);
tempposz = (oldposz -posz);
if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
{
SendClientMessage(i, col1, string);
}
else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
{
SendClientMessage(i, col2, string);
}
else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
{
SendClientMessage(i, col3, string);
}
else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
{
SendClientMessage(i, col4, string);
}
else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
SendClientMessage(i, col5, string);
}
}
else
{
SendClientMessage(i, col1, string);
}
}
}
return 1;
}
pawn Code:
public GetClosestPlayer(p1)
{
new x,Float:dis,Float:dis2,player;
player = -1;
dis = 99999.99;
for (x=0;x<MAX_PLAYERS;x++)
{
if(IsPlayerConnected(x))
{
if(x != p1)
{
dis2 = GetDistanceBetweenPlayers(x,p1);
if(dis2 < dis && dis2 != -1.00)
{
dis = dis2;
player = x;
}
}
}
}
return player;
}
pawn Code:
public Float:GetDistanceBetweenPlayers(p1,p2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
{
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
new giveplayername[MAX_PLAYER_NAME];
new sendername[MAX_PLAYER_NAME];
new string[128];
if(strcmp("/rob", cmdtext, true, 10) == 0)
{
if(IsPlayerConnected(playerid))
{
if(IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, COLOR_GREY, "You cannot rob someone while being in a Car!");
return 1;
}
new victim = GetClosestPlayer(playerid);
if(IsPlayerConnected(victim))
{
if(GetDistanceBetweenPlayers(playerid,victim) < 5)
{
if(IsPlayerInAnyVehicle(victim))
{
SendClientMessage(playerid, COLOR_GREY, "You cannot rob someone who is in a car!");
return 1;
}
GetPlayerName(victim, giveplayername, sizeof(giveplayername));
GetPlayerName(playerid, sendername, sizeof(sendername));
new randt = random(4)+1;
if(randt == 1)
{
format(string, sizeof(string), "* %s shoots with his Tazer at %s, but missed.", sendername ,giveplayername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
else
{
format(string, sizeof(string), "* You were robbed by %s.", sendername);
SendClientMessage(victim, COLOR_WHITE, string);
format(string, sizeof(string), "* You robbed %s and stole $$s.", giveplayername, GetPlayerMoney(victim));
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "* %s puts his hand into %s 's pocket and steals his money.", sendername ,giveplayername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
GameTextForPlayer(victim, "~r~Robbed", 2500, 3);
GivePlayerMoney(playerid, GetPlayerMoney(victim));
ResetPlayerMoney(victim, 0);
}
else
{
SendClientMessage(playerid, COLOR_GREY, " No-one near you!");
return 1;
}
}
}
}
return 1;
}
return 0;
}