IsPlayerInRangeofPlayer
#1

Is there any possibilities to make that function IsPlayerInRangeOfPlayer.
I want to make CMD:robfromplayer(playerid,params[])
And now, if player is in range of other player, then he can rob him, if he is not then he cant.

Thanks for help!
Reply
#2

pawn Код:
CMD:robfromplayer(playerid,params[])
{
new otherplayer;
if(sscanf(params,"u",otherplayer)) return SendClientMessage(playerid,-1,"Usage: /robfromplayer [id]");
if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid,-1,"Player isn't connected...");
new Float:x,Float:y,Float:z;
GetPlayerPos(otherplayer,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,distance,x,y,z))
{
// action
}
else SendClientMessage(playerid,-1,"You are not in range to rob from this person.");
return 1;
}
EDITED.

You must have sscanf for this to work.
Reply
#3

error 017: undefined symbol "otherplayer"
error 001: expected token: ")", but found "{"

_____________________

GetPlayerPos(otherplayer,x,y,z);
Should I change otherplayer with 1? or -1?

_____________________
{
Do I have to delete that?
Reply
#4

Check again, I changed it.
Reply
#5

Thanks it worked!
but how can I give now 1200$ to robber and remove 1200$ from that who has been robbed?
Reply
#6

pawn Код:
GivePlayerMoney(playerid, 1200);
GivePlayerMoney(targetid, -1200);
Reply
#7

Quote:
Originally Posted by Cxnnor
Посмотреть сообщение
pawn Код:
GivePlayerMoney(playerid, 1200);
GivePlayerMoney(targetid, -1200);
With what I should have to change that targetid?
error 017: undefined symbol "targetid"
OtherPlayer?
Reply
#8

pawn Код:
GivePlayerMoney(playerid, 1200);
GivePlayerMoney(otherplayer, -1200);
I didn't know what you defined it as, try that
Reply
#9

It worked... But how can i make it work with strcmp.

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/robfromplayer", cmdtext, true, 10) == 0)
{
{
new otherplayer;
if(sscanf(cmdtext,"u",otherplayer)) return SendClientMessage(playerid,-1,"USE: /robfromplayer [ID]");
if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid,-1,"Player Isnt Connected");
new Float,Float:y,Float:z;
GetPlayerPos(otherplayer,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,7,x,y,z))
{
GivePlayerMoney(playerid, 1200);
GivePlayerMoney(otherplayer, -1200);
}
else SendClientMessage(playerid,-1,"You cannot rob a player from 2 miles away!!!");
return 1;
}
}
return SendClientMessage(playerid,0x33FFCC00, "Unknown Command!");
}

________

It always says : You cannot rob a player from 2 miles away!!!
Any Ideas?
Reply
#10

I know people hate it when this is said, but why use sscanf with strcmp. I don't know for sure if this is going to work, but I've cleaned up your code a lot.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/robfromplayer", cmdtext, true, 10) == 0)
    {
        new otherplayer, Float:Pos[3];
        GetPlayerPos(otherplayer, Pos[0], Pos[1], Pos[2]);
        if(sscanf(cmdtext, "u", otherplayer))
            return SendClientMessage(playerid, -1, "USE: /robfromplayer [ID]");
        if(!IsPlayerConnected(otherplayer))
            return SendClientMessage(playerid,-1,"Player Isnt Connected");
        if(!IsPlayerInRangeOfPoint(playerid, 7, Pos[0], Pos[1], Pos[2]))
            return SendClientMessage(playerid, -1, "You cannot rob a player from 2 miles away!!!");
        //
        GivePlayerMoney(playerid, 1200);
        GivePlayerMoney(otherplayer, -1200);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)