Help with getdistance
#1

I need help with GetDistanceBetweenPlayers.

This is my /break command, and I can type /break [ID] and I can break them from anywhere, doesn't matter where they are and how far, I can break them. I'm not sure why my GetDistanceBetweenPlayers is not working. Is there a function i need to add to my script?

This is all i have

#define GetDistanceBetweenPlayers


Код:
if(strcmp(cmd, "/break", true) == 0) {
  if(IsSpawned[playerid] == 0) {
	SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
  return 1;
  }
  if(InDerby[playerid] == 1) {
  SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
  return 1;
  }
  if(gTeam[playerid] != TEAM_MECHANIC) {
  SendClientMessage(playerid,COLOR_ERROR,"You are not a Car Mechanic");
  return 1;
  }
  if(fixedcarrecent[playerid] >=1) {
  SendClientMessage(playerid,COLOR_ERROR,"Command used recently. Please wait");
  return 1;
  }
  tmp = strtok(cmdtext, idx);
  if(!strlen(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /break (id)");
  return 1;
  }
  giveplayerid = strval(tmp);
  if(!IsNumeric(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /break (id) ID Must be a number");
  return 1;
  }
  if(!IsPlayerConnected(giveplayerid)) {
  format(szstring, sizeof(szstring), "ID (%d) is not an active player", giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }

  if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 3) {
  format(szstring, sizeof(szstring), "(%d) Is not close enough. You cannot pour sand into that players vehicle engine",giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }
  GetPlayerName(playerid,mname, 24);
	GetPlayerName(giveplayerid, pname, 24);
	if(!IsPlayerInAnyVehicle(giveplayerid)) {
  format(szstring, sizeof(szstring), "%s(%d) is not in any vehicle",pname,giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }

  if(GetPlayerState(giveplayerid) == PLAYER_STATE_DRIVER) {
  if(GetVehicleModel(GetPlayerVehicleID(giveplayerid)) == 481) {
  SendClientMessage(playerid, COLOR_ERROR, "That vehicle does not have any engine, you cannot use this command on that vehicle (BMX Bike)");
  return 1;
  }
  new tobreak = GetPlayerVehicleID(giveplayerid);

  oscore = GetPlayerScore(playerid);
  SandInEngine[tobreak] =1;
  SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Sand In Engine_|");
	format(szstring, sizeof(szstring), "Mechanic %s(%d) has filled your vehicle engine with sand. GET OUT",mname,playerid);
  SendClientMessage(giveplayerid,COLOR_DODGERBLUE, szstring);
  SendClientMessage(playerid, 0xA9A9A9AA, "|_Sand In Engine_|");
  format(szstring, sizeof(szstring), "You have filled %s(%d)'s vehicle engine with sand", pname,giveplayerid);
  SendClientMessage(playerid,COLOR_DODGERBLUE, szstring);
  new plwl = GetPlayerWantedLevel(playerid);
	SetPlayerWantedLevel(playerid, plwl +1 );
	commitedcrimerecently[playerid] +=60;
	fixedcarrecent[playerid] =60;
	SetPlayerScore(playerid, oscore +1);
  for(new i=0;i<MAX_PLAYERS;i++)
	{
	 if(IsPlayerConnected(i))
	 {
	 if(LawEnforcementRadio[i] == 1)
	 {
    new current_zone;
    current_zone = player_zone[playerid];
    format(szstring, sizeof(szstring), "DISPATCH: (CRIME IN PROGRESS) SUSPECT: %s(%d) CRIME: Criminal Damage LOCATION: %s",mname,playerid,zones[current_zone][zone_name]);
    SendClientMessage(i,COLOR_ROYALBLUE, szstring);
    }
	 }
	 }
  new pcol = GetPlayerColor(playerid);
	plwl = GetPlayerWantedLevel(playerid);
	SendClientMessage(playerid, 0xA9A9A9AA, "|_Crime Commited_|");
	format(szstring, sizeof(szstring), "(CRIMINAL DAMAGE) Wanted Level %d",plwl);
	SendClientMessage(playerid,pcol,szstring);
  }
  else{
  format(szstring, sizeof(szstring), "%s(%d) is not the driver of the vehicle",pname,giveplayerid);
  SendClientMessage(giveplayerid,COLOR_DODGERBLUE, szstring);
  }
  return 1;
  }
Reply
#2

Remove the define.

pawn Код:
stock GetDistanceBetweenPlayers(playerid,playerid2) //By Slick (Edited by Sacky)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(playerid2,x2,y2,z2);
    tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
    return floatround(tmpdis);
}
Reply
#3

Quote:
Originally Posted by //exora
Remove the define.

pawn Код:
stock GetDistanceBetweenPlayers(playerid,playerid2) //By Slick (Edited by Sacky)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(playerid2,x2,y2,z2);
    tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
    return floatround(tmpdis);
}
Thank you very much, is my problem going to be fixed because i added that in? or do i have to edit my code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)