Position's Help
#1

So, I am trying to make it so you can do a search in one spot, but you must move at least 10 SA Units away from the last spot you searched.
However, With my code, it just skips over the positioning part. Anyone know why?



pawn Код:
CMD:search(playerid, params[])
{
    new string[128];
    new Float:x, Float:y, Float:z;
    new Float:OldPosx, Float:OldPosy, Float:OldPosz;
    GetPlayerPos(playerid, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 10.0, OldPosx, OldPosy, OldPosz))
    {
        if(Search[playerid] == 0)
        {
            format(string, sizeof(string), "* %s does a quick search of their surroundings.", GetPlayerNameEx(playerid));
            nearByMessage(playerid, COLOR_PURPLE, string);

            new randitem = Random(1,7);
            switch(randitem)
            {
                case 1:
                {
                    SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "You have found Five Dollars! ($5.00)");
                    GivePlayerCash(playerid, 5);
                }
                case 2: SendClientMessageEx(playerid, COLOR_RED, "You didn't find anything.");
                case 3:
                {
                    SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "You have found a Small Book of Matches! (4 Matches)");
                }
                case 4: SendClientMessageEx(playerid, COLOR_RED, "You didn't find anything.");
                case 5:
                {
                    SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "You have found a Large Book of Matches! (8 Matches)");
                }
                case 6: SendClientMessageEx(playerid, COLOR_RED, "You didn't find anything.");
            }
            Search[playerid] = 1;
            SetTimerEx("ClearSearch", 20000, false, "d", playerid);
            GetPlayerPos(playerid, OldPosx, OldPosy, OldPosz);
        }
        else
            return SendClientMessageEx(playerid, COLOR_RED, "You must wait 20 seconds before searching again.");
    }
    else
        return SendClientMessageEx(playerid, COLOR_RED, "You can't search in the same spot twice!");
    return 1;
}
Reply
#2

Nevermind, This can be closed.
I was an idiot and didn't realize that the line with this in it
pawn Код:
new Float:OldPosx, Float:OldPosy, Float:OldPosz;
Resets it every time, I just moved it outside of the code and it works.
Reply
#3

Just make sure these are like this.

Код:
new Float:OldPosx[MAX_PLAYERS], Float:OldPosy[MAX_PLAYERS], Float:OldPosz[MAX_PLAYERS];
Reply
#4

Or to save time and make it generally better:

pawn Код:
new Float:OldPlayerPos[MAX_PLAYERS][3];
!

Also note how I named it 'OldPlayerPos'. It's more descriptive than 'OldPos'. 'OldPos' could mean anything. Old position of what? Old position of a vehicle, an object, a player, a squirrel?
Reply
#5

Quote:
Originally Posted by MP2
Посмотреть сообщение
Or to save time and make it generally better:

pawn Код:
new Float:OldPlayerPos[MAX_PLAYERS][3];
!

Also note how I named it 'OldPlayerPos'. It's more descriptive than 'OldPos'. 'OldPos' could mean anything. Old position of what? Old position of a vehicle, an object, a player, a squirrel?
Adding player to it doesn't really make a difference if he isn't using it for anything vehicle...squirrel...or object related.

That's like adding a function called SetPlayerHealthWhilePlayerIsBeingShotSoWeCanDoSome WierdAssShitBro(playerid);
When playerid is clearly in our function

Besides that, if he wants to re-use it for a squirrel, he could because it would still be the squirrels old pos after being set (squirrel id 0 for example)

EDIT:
While I do understand your point, making variables exact isn't really needed...Specially if the mode isn't going to be released (or whatever it is). If it is going to be released, you are correct :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)