Function does not always walking
#1

Good morning.

I have a function that checks if a player is in that position or not, here it is:

pawn Код:
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        tempposx = (oldposx -x);
        tempposy = (oldposy -y);
        tempposz = (oldposz -z);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) return 1;
    }
    return 0;
}
However, from time to time for example the following case it does not work, and I have no idea why it does not work.

Here's how I use it:

pawn Код:
if(strcmp(subcmd, "appart", true) == 0)
        {
            for(new houseid = 0; houseid < totalhouses; houseid++)
            {
                if(PlayerToPoint(3, playerid, HouseInfo[houseid][hEntrancex], HouseInfo[houseid][hEntrancey], HouseInfo[houseid][hEntrancez]))
                {
                    if(HouseInfo[i][hAppart] == 0)
                    {
                        HouseInfo[i][hAppart] = 1;
                        UpdateHouseLabel(houseid, false);
                        UpdateHousePickup(houseid);
                    }
                    else
                    {
                        HouseInfo[i][hAppart] = 0;
                        UpdateHouseLabel(houseid, false);
                        UpdateHousePickup(houseid);
                    }
                }
            }
            return 1;
        }
++
Reply
#2

Ehhhh. Its easier to just use IsPlayerInRangeOfPoint with the range 1 or more.
Edit: ****** Be ninjaing
Reply
#3

pawn Код:
if(strcmp(subcmd, "appart", true) == 0)
        {
            SendClientMessage(playerid, COLOR_RPIT, "1");
            for(new houseid = 0; houseid < totalhouses; houseid++)
            {
                SendClientMessage(playerid, COLOR_RPIT, "2");
                if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[houseid][hEntrancex], HouseInfo[houseid][hEntrancey], HouseInfo[houseid][hEntrancez]))
                {
                    SendClientMessage(playerid, COLOR_RPIT, "3");
                    if(HouseInfo[i][hAppart] == 0) // Si c'est une baraque
                    {
                        SendClientMessage(playerid, COLOR_RPIT, "Terminus");
                        HouseInfo[i][hAppart] = 1;
                        UpdateHouseLabel(houseid, false);
                        UpdateHousePickup(houseid);
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_RPIT, "Terminus");
                        HouseInfo[i][hAppart] = 0;
                        UpdateHouseLabel(houseid, false);
                        UpdateHousePickup(houseid);
                    }
                }
            }
        }
My code hangs SendClientMessage equivalent to "1".

Why?
Reply
#4

pawn Код:
[22:25:15] 1
[22:25:17] 1
[22:25:18] 1
[22:25:23] 1
Always the same ...
Reply
#5

Код:
#define totalhouses (5000) // any number you want(is your max houses)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)