Pos problem - 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: Pos problem (
/showthread.php?tid=581412)
Pos problem -
ShoortyFl - 12.07.2015
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];
Re: Pos problem -
Virtual1ty - 12.07.2015
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!
Re: Pos problem -
Threshold - 13.07.2015
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