Quick Question. -
Ritzy2K - 03.05.2016
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;
}
Re: Quick Question. -
ReD_HunTeR - 03.05.2016
Код:
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
Re: Quick Question. -
Sjn - 03.05.2016
I tested this with debug messages and it worked for me.
PHP код:
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.");
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:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
foreach (new i : Player)
{
if (IsPlayerInRangeOfPoint(i, 5.0, x, y, z))
{
return i;
}
}
return INVALID_PLAYER_ID;
}
Btw, I don't think you really need to calculate the coordinates to get the nearest id.
Re: Quick Question. -
Ritzy2K - 03.05.2016
Thanks for a rough idea. I'll expand this, replying both. Thanks a lot.
Re: Quick Question. -
xTURBOx - 03.05.2016
Its very simple
//inside the cmd
New targetid;
if(sscanf(params,"u",targetid)) { targetid = getclosestplayer; }
//other stuff
Re: Quick Question. -
Ritzy2K - 03.05.2016
No, but I also wanted player can specify the ID so I wasnt sure.
Re: Quick Question. -
jlalt - 03.05.2016
This should do the job sir
PHP код:
PlayersDistanceZZ(playerid,player1 = -255) {
if(player1 == -255) {
for(new i = 0; i < MAX_PLAYERS; i++) {
if(!IsPlayerConnected(i) || i == playerid) continue;
new Float:X1,Float:Y1,Float:Z1;
GetPlayerPos(i, X1, Y1, Z1);
if(IsPlayerInRangeOfPoint(playerid, 5.0, X1, Y1, Z1)) {
return i;
}
}
return -255;
}
else {
new Float:X1,Float:Y1,Float:Z1;
GetPlayerPos(player1, X1, Y1, Z1);
if(IsPlayerInRangeOfPoint(playerid, 5.0, X1, Y1, Z1)) {
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(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.");
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
}
}
Re: Quick Question. -
Ritzy2K - 03.05.2016
Already solved this m8, thanks tho.
Re: Quick Question. -
jlalt - 03.05.2016
Quote:
Originally Posted by [ND]xXZeusXx.
Already solved this m8, thanks tho.
|
Kill youz >:V