SA-MP Forums Archive
Is there a smarter way to do this ? - 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: Is there a smarter way to do this ? (/showthread.php?tid=616361)



Is there a smarter way to do this ? - NeXoR - 03.09.2016

Heya, this is from a bank system im creating, is there a way to make the for & pos var checking shorter somehow ?
PHP код:
CMD:deposit(playeridparams[])
{
    
#if REQUIRE_POSITION == 1
    
new pos;
    for(new 
0MAX_ATMsi++) if(IsPlayerInRangeOfPoint(playerid3ATMInfo[i][xPos], ATMInfo[i][yPos], ATMInfo[i][zPos])) pos 1;
    if(!
pos) return SendClientMessage(playerid, -1"You must be near an ATM to perform this command.");
    
#endif
    
return 1;




Re: Is there a smarter way to do this ? - Shinja - 03.09.2016

More optimized version and break when you get the nearest ATM, don't need to continue looping
PHP код:
IsPlayerInRangeOfAnyAtm(playeridFloat:range)
{
    for(new 
iMAX_ATMsji++) 
    {
        if(
IsPlayerInRangeOfPoint(playeridrangeATMInfo[i][xPos], ATMInfo[i][yPos], ATMInfo[i][zPos])) return true;
    }
    return 
false;




Re: Is there a smarter way to do this ? - SickAttack - 03.09.2016

I'd suggest you use the areas system that comes with the streamer plugin. It makes things like this so much easier and efficient.


Re: Is there a smarter way to do this ? - NeXoR - 03.09.2016

Quote:
Originally Posted by Shinja
Посмотреть сообщение
More optimized version and break when you get the nearest ATM, don't need to continue looping
PHP код:
IsPlayerInRangeOfAnyAtm(playeridFloat:range)
{
    for(new 
iMAX_ATMsji++) 
    {
        if(
IsPlayerInRangeOfPoint(playeridrangeATMInfo[i][xPos], ATMInfo[i][yPos], ATMInfo[i][zPos])) return true;
    }
    return 
false;

Thank you, I'll use this.

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
I'd suggest you use the areas system that comes with the streamer plugin. It makes things like this so much easier and efficient.
I'm not sure if it worths using a plugin for a simple filterscript, but thanks for the offer.


Re: Is there a smarter way to do this ? - SickAttack - 04.09.2016

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Thank you, I'll use this.



I'm not sure if it worths using a plugin for a simple filterscript, but thanks for the offer.
If you don't know about streamer, you have been hidding in a cave all your life. The majority of servers use it.

You aren't going to beat it with that loop.


Re: Is there a smarter way to do this ? - NeXoR - 04.09.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
If you don't know about streamer, you have been hidding in a cave all your life. The majority of servers use it.

You aren't going to beat it with that loop.
Well I absolutely know about streamer since I used it alot of times on my RP gamemode.
What I'm trying to say is that this is just a small bank filterscript, it doesn't worth using it.


Re: Is there a smarter way to do this ? - SickAttack - 04.09.2016

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Well I absolutely know about streamer since I used it alot of times on my RP gamemode.
What I'm trying to say is that this is just a small bank filterscript, it doesn't worth using it.
Why isn't it worth it? I say it is worth using the areas in it.


Re: Is there a smarter way to do this ? - Vince - 04.09.2016

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
    for(new iMAX_ATMsji++) 
This is actually less optimized because MAX_ATMs is already either a constant or a variable. We only use j if the number of iterations is the output of a function, as to not invoke the function with each iteration. The more you know.