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(playerid, params[])
{
#if REQUIRE_POSITION == 1
new pos;
for(new i = 0; i < MAX_ATMs; i++) if(IsPlayerInRangeOfPoint(playerid, 3, ATMInfo[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(playerid, Float:range)
{
for(new i, j = MAX_ATMs; i < j; i++)
{
if(IsPlayerInRangeOfPoint(playerid, range, ATMInfo[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(playerid, Float:range)
{
for(new i, j = MAX_ATMs; i < j; i++)
{
if(IsPlayerInRangeOfPoint(playerid, range, ATMInfo[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 i, j = MAX_ATMs; i < j; i++)
|
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.