SA-MP Forums Archive
Function does not always walking - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Function does not always walking (/showthread.php?tid=517192)



Function does not always walking - TheSy - 03.06.2014

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;
        }
++


Re: Function does not always walking - KevinPRINCE - 03.06.2014

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


Re: Function does not always walking - TheSy - 03.06.2014

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?


Re: Function does not always walking - TheSy - 03.06.2014

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


Re: Function does not always walking - KevinPRINCE - 03.06.2014

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