Is there a smarter way to do this ?
#1

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;

Reply
#2

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;

Reply
#3

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

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)