Help with range
#1

I was trying on making this command which is to give weapon to all players that are within the range of the value i give, but it gives only if the player is so near to me regardless of what value i give as range. I know the code is a mess, could anyone help find or rewrite the code, would really apreciate it
pawn Код:
new tmp[256], tmp2[256], Index, aweaponrange;
        new ammo, weap, WeapName[32], filestring[75];
        new string[128];
        tmp = strtok(params,Index);
        tmp2 = strtok(params,Index);
        aweaponrange = strval(params);

        if(isnull(params)) return
        SendClientMessage(playerid, LIGHTBLUE2, "Usage: /rangeweapon [WeaponID or WeaponName] [Ammo] [Range]");
       

        if(!strlen(tmp2) || !IsNumeric(tmp2) || strval(tmp2) <= 0 || strval(tmp2) > 99999) ammo = 500; else ammo = strval(tmp2);
        if(!IsNumeric(tmp))
        weap = GetWeaponIDFromName(tmp);
        else weap = strval(tmp);
        if(!IsValidWeapon(weap))
        return SendClientMessage(playerid,red,"ERROR: Invalid Weapon ID");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(GetDistanceBetweenPlayers(playerid,i) < 10 && Specing[i] == 0)
            {
                if(IsPlayerConnected(i))
                {
                PlayerPlaySound(i,1057,0.0,0.0,0.0);
                GivePlayerWeapon(i,weap,ammo);
                }
            }
        }
Reply
#2

Show the GetDistanceBetweenPlayers function, you could've gotten the xyz coords of the player and looped through all players to check isplayerinrangeofpoint of that one^
Reply
#3

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Show the GetDistanceBetweenPlayers function, you could've gotten the xyz coords of the player and looped through all players to check isplayerinrangeofpoint of that one^
pawn Код:
public Float:GetDistanceBetweenPlayers(p1,p2){
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
        return -1.00;}
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));}
Reply
#4

problem is probably here, u're using "10" instead of range code.
Код:
            if(GetDistanceBetweenPlayers(playerid,i) < 10 && Specing[i] == 0)
			{
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)