Question
#1

How can I make a script or feature that allows to get the players location, such as /trace, I tired using getplayerpos but It didn't work, the main point is to send a client message of the location of the player who will be traced.
Can any one help me with that ? >.
Reply
#2

as dcmd:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
 dcmd(trace, 5, cmdtext);
 return 1;
}
Код:
dcmd_trace(playerid, params[])
{
 if(!strlen(params)){
  SendClientMessage(playerid, YOURCOLOR, "/trace [id]");
  return 1;
 }
 new pid = strval(params);
 if(!IsPlayerConnected(pid)){
  SendClientMessage(playerid, YOURCOLOR, "Player is not connected");
  return 1;
 }else{
  new string[256], name[MAX_PLAYER_NAME], Float:x, Float:y, Float:z;
  GetPlayerName(pid, name, sizeof(name));
  GetPlayerPos(pid, x, y, z);
  format(string, sizeof(string), "%s's position: %f, %f, %f", name, x, y, z);
  SendClientMessage(playerid, YOURCOLOR, string);
  }
 }
 return 1;
}
Just wrote that fast so I don't know if I made any mistake, just try it and reply whether it worked or not
Reply
#3

[php]
PHP код:
wn(86) :  error 017undefined symbol "dcmd"
C:\Documents and Settings\My Documents\Downloads\)\filterscripts\Tracefeature.pwn(246) : warning 203symbol is never used"dcmd_trace" 
this is how I put the script:
pawn Код:
#pragma tabsize 0
public OnPlayerCommandText(playerid, cmdtext[])
{
    line 86: dcmd(trace, 5, cmdtext);
     return 1;

    }
   
    dcmd_trace(playerid, params[])
{
 if(!strlen(params)){
  SendClientMessage(playerid, YOURCOLOR, "/trace [id]");
  return 1;
 }
 new pid = strval(params);
 if(!IsPlayerConnected(pid)){
  SendClientMessage(playerid, YOURCOLOR, "Player is not connected");
  return 1;
 }else{
  new string[256], name[MAX_PLAYER_NAME], Float:x, Float:y, Float:z;
  GetPlayerName(pid, name, sizeof(name));
  GetPlayerPos(pid, x, y, z);
  format(string, sizeof(string), "%s's position: %f, %f, %f", name, x, y, z);
  SendClientMessage(playerid, YOURCOLOR, string);
  }
 }
this is who I defined the dcmd:
PHP код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 
Reply
#4

this should work actually... :

Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1


public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(trace, 5, cmdtext);
	return 0;
}

dcmd_trace(playerid, params[])
{
 if(!strlen(params)){
  SendClientMessage(playerid, YOURCOLOR, "/trace [id]");
  return 1;
 }
 new pid = strval(params);
 if(!IsPlayerConnected(pid)){
  SendClientMessage(playerid, YOURCOLOR, "Player is not connected");
  return 1;
 }else{
  new string[256], name[MAX_PLAYER_NAME], Float:x, Float:y, Float:z;
  GetPlayerName(pid, name, sizeof(name));
  GetPlayerPos(pid, x, y, z);
  format(string, sizeof(string), "%s's position: %f, %f, %f", name, x, y, z);
  SendClientMessage(playerid, YOURCOLOR, string);
  }
 }
 return 1;
}
Reply
#5

A string size of 256 is a bit of a waste of resources, as far as I can see it only needs to be 72, and if you use %.0f in the format you only need about 60.

I doubt the average player would be interested in knowing a players position to 5 decimal places.
Reply
#6

I just wrote this up... I didn't count for the length of the text...
Reply
#7

Quote:
Originally Posted by Rachael
Посмотреть сообщение
I doubt the average player would be interested in knowing a players position to 5 decimal places.
ikr, I recommend using floatround
Reply
#8

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
ikr, I recommend using floatround
indeed actually.. haven't thought of this...

instead of:
Код:
format(string, sizeof(string), "%s's position: %f, %f, %f", name, x, y, z);
add:

Код:
floatround(x, floatround_round);
floatround(y, floatround_round);
floatround(z, floatround_round);
format(string, sizeof(string), "%s's positions: %.0f, %.0f, %.0f", name, x, y, z);
Reply
#9

It works, first of all I'm so thankful, second of all, when I trace someone, it prints the result as:
test's positions: 301, 412, 510.
Is there any way to change it into a name ? for example if the player is at the Grove street, the script will show that he is at Grove street.
Reply
#10

Quote:
Originally Posted by Scriptissue
Посмотреть сообщение
It works, first of all I'm so thankful, second of all, when I trace someone, it prints the result as:
test's positions: 301, 412, 510.
Is there any way to change it into a name ? for example if the player is at the Grove street, the script will show that he is at Grove street.
Use the zones include?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)