Pos problem
#1

So i've create a system for something and it's not working, i mean everything works, loading/saving but when i type this command, it sayst that im not near that place, and i think i did everything ok:

pawn Код:
CMD:kiosk(playerid, params[])
{
    for(new i; i < sizeof(KioskInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, KioskInfo[i][PozX], KioskInfo[i][PozY], KioskInfo[i][PozZ]))
        {
            SPD(playerid, DIALOG_TRAFIKA, DIALOG_STYLE_LIST, "Kiosk", "Telefon ($150)\nCoca-Cola ($10)\nFanta ($10)\nSprite ($10)\nSendvic ($10)\nHamburger ($10)\nChips ($10)\nSmoki ($10)\nPivo ($13)", "Kupi", "Izlaz");
        }
        else return SCM(playerid, TOMATO, "[RPF] {FFFFFF}Niste u blizini kioska.");
    }
    return 1;
}
enumator:

pawn Код:
enum kiosk
{
    Float:PozX,
    Float:PozY,
    Float:PozZ
}
new KioskInfo[MAX_TRAFIKA][kiosk];
Reply
#2

It's because you are looping through all the kiosks, so naturally you won't be close to at least one of them and hence the message.
I would suggest you do it this way: run a normal loop like you did, make a new variable and store the id of the kiosk that player is at (id = i, from the iterator). Then outside of the loop do your thing, and if id is "-1" (you first initialise it to "-1") then the player is not near any kiosk.
Or you could put a continue; for the "else" statement and send your warning message outside the loop. But that's a messier way for me.
Play with it, good luck!
Reply
#3

pawn Код:
CMD:kiosk(playerid, params[])
{
    new bool:found = false;
    for(new i; i < sizeof(KioskInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, KioskInfo[i][PozX], KioskInfo[i][PozY], KioskInfo[i][PozZ]))
        {
            SPD(playerid, DIALOG_TRAFIKA, DIALOG_STYLE_LIST, "Kiosk", "Telefon ($150)\nCoca-Cola ($10)\nFanta ($10)\nSprite ($10)\nSendvic ($10)\nHamburger ($10)\nChips ($10)\nSmoki ($10)\nPivo ($13)", "Kupi", "Izlaz");
            found = true;
            break;
        }
    }
    if(!found) SCM(playerid, TOMATO, "[RPF] {FFFFFF}Niste u blizini kioska.");
    return 1;
}
Or another alternative is:
pawn Код:
CMD:kiosk(playerid, params[])
{
    for(new i; i < sizeof(KioskInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, KioskInfo[i][PozX], KioskInfo[i][PozY], KioskInfo[i][PozZ]))
            return SPD(playerid, DIALOG_TRAFIKA, DIALOG_STYLE_LIST, "Kiosk", "Telefon ($150)\nCoca-Cola ($10)\nFanta ($10)\nSprite ($10)\nSendvic ($10)\nHamburger ($10)\nChips ($10)\nSmoki ($10)\nPivo ($13)", "Kupi", "Izlaz");
    }
    SCM(playerid, TOMATO, "[RPF] {FFFFFF}Niste u blizini kioska.");
    return 1;
}
The only time you should use return is when you want to end a block of code and stop it from continuing. Or when you want a function to return a certain value.

https://sampwiki.blast.hk/wiki/Control_Structures#return
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)