Quick Question.
#1

Hello, I wana make a /rape command, In that i want that If player does /rape, it infects the closest player, but if player does /rape [id] it infects that specified player only.

How do i do that.

I have done this yet -

Код:
/*CMD:rape(playerid, params[])
{
	new rapedid;

    if  (!IsPlayerSpawned(playerid) || PlayerData[playerid][pJailTime] > 0)
	    return SendErrorMessage(playerid, "You Cannot Use This Command Right Now");
	    
	if	(PlayerData[playerid][pOnDuty])
		return SendErrorMessage(playerid, "You Cannot Use This Command Whilst On-Duty.");

	if  (sscanf(params, "u", rapedid))
	    return SendSyntaxMessage(playerid, "/rape (playerid / Name).");
*/
I've only coded till this because i got stuck in this issue.
and this my stock to get the closest player

Код:
stock GetNearestPlayerInView(playerid, Float:distance = 2.0)
{
	new
	    Float:fAngle,
		Float:fPosX,
		Float:fPosY,
		Float:fPosZ;

	GetPlayerFacingAngle(playerid, fAngle);
	GetPlayerPos(playerid, fPosX, fPosY, fPosZ);

	fPosX += distance * floatsin(-fAngle, degrees);
	fPosY += distance * floatcos(-fAngle, degrees);

	foreach (new i : Player) if (IsPlayerInRangeOfPoint(i, 5.0, fPosX, fPosY, fPosZ)) {
	    return i;
	}
	return INVALID_PLAYER_ID;
}
Reply
#2

Код:
CMD:rape(playerid, params[])
{
	new rapedid = GetClosestPlayerToPlayer(playerid);

    if  (!IsPlayerSpawned(playerid) || PlayerData[playerid][pJailTime] > 0)
	    return SendErrorMessage(playerid, "You Cannot Use This Command Right Now");
	    
	if	(PlayerData[playerid][pOnDuty])
		return SendErrorMessage(playerid, "You Cannot Use This Command Whilst On-Duty.");

	if  (sscanf(params, "u", rapedid))
	    return SendSyntaxMessage(playerid, "/rape (playerid / Name).");


forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
{
    new Float:dist = 1000.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;
        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;
}
try this
Reply
#3

I tested this with debug messages and it worked for me.

PHP код:
CMD:rape(playeridparams[])
{
    new 
rapedid;
    if  (!
IsPlayerSpawned(playerid) || PlayerData[playerid][pJailTime] > 0)
        return 
SendErrorMessage(playerid"You Cannot Use This Command Right Now");
    if    (
PlayerData[playerid][pOnDuty])
        return 
SendErrorMessage(playerid"You Cannot Use This Command Whilst On-Duty.");
    new 
closest GetNearestPlayerInView(playerid);
    if  (
sscanf(params"u"rapedid))
        
rapedid closest;
    else
        
rapedid strval(params);
    if(
rapedid == closest)
    {
        
// Rape the closest player
         //SendClientMessage(playerid, -1, "You can also use /rape <id>");
    
}
    else
    {
        
// Rape the specified player
    
}
    return 
1;
}
stock GetNearestPlayerInView(playerid)
{
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
    foreach (new 
Player)
    {
        if (
IsPlayerInRangeOfPoint(i5.0xyz))
        {
            return 
i;
        }
    }
    return 
INVALID_PLAYER_ID;

Btw, I don't think you really need to calculate the coordinates to get the nearest id.
Reply
#4

Thanks for a rough idea. I'll expand this, replying both. Thanks a lot.
Reply
#5

Its very simple
//inside the cmd
New targetid;
if(sscanf(params,"u",targetid)) { targetid = getclosestplayer; }
//other stuff
Reply
#6

No, but I also wanted player can specify the ID so I wasnt sure.
Reply
#7

This should do the job sir

PHP код:
PlayersDistanceZZ(playerid,player1 = -255) {
   if(
player1 == -255) {
     for(new 
0MAX_PLAYERSi++) {
         if(!
IsPlayerConnected(i) || == playerid) continue;
         new 
Float:X1,Float:Y1,Float:Z1;
         
GetPlayerPos(iX1Y1Z1);
         if(
IsPlayerInRangeOfPoint(playerid5.0X1Y1Z1)) {
            return 
i;
         }
     }
     return -
255;
   }
   else {
      new 
Float:X1,Float:Y1,Float:Z1;
      
GetPlayerPos(player1X1Y1Z1);
      if(
IsPlayerInRangeOfPoint(playerid5.0X1Y1Z1)) {
          return 
player1;
      }
      else {
          return -
255;
      }
   }

Usage:
PlayersDistanceZZ(playerid); // check if player is near any player if not returns -255
PlayersDistanceZZ(playerid,player1); // checks if player is near another player if not returns -255

Example:

PHP код:
CMD:rape(playeridparams[])
{
    new 
rapedid;
    if  (!
IsPlayerSpawned(playerid) || PlayerData[playerid][pJailTime] > 0)
        return 
SendErrorMessage(playerid"You Cannot Use This Command Right Now");
    if    (
PlayerData[playerid][pOnDuty])
        return 
SendErrorMessage(playerid"You Cannot Use This Command Whilst On-Duty.");
        
    new 
PDest PlayersDistanceZZ(playerid);
    if(
PDest == -255) {
       if  (
sscanf(params"u"rapedid))
           return 
SendSyntaxMessage(playerid"/rape (playerid / Name).");
           
// the job
           /*
           you now can also to check if player is near player by
           
           if(PlayersDistanceZZ(playerid, trpedid) == -255) return 1;
           */
    
}
    else { 
// if he's near any player
     // the job
    
}
        

Reply
#8

Already solved this m8, thanks tho.
Reply
#9

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
Already solved this m8, thanks tho.
Kill youz >:V
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)