SA-MP Forums Archive
Some answers please? - 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: Some answers please? (/showthread.php?tid=635188)



Some answers please? - Dragonic - 03.06.2017

Hi, so my GM is almost done and I plan to open my server soon. When? Idk, but soon.
Since I'll be starting I'll get a normal host, not a dedicated one so I'll have to share resources with idk how many other server thus I want to make my server as light as possible.

1st) I don't use OnPlayerUpdate. Instead I use an infinite loop that is called every .5s but I have ALOT of things there, can this cause lag?

2nd) I use alot of things like that:
Код:
g_God[MAX_PLAYERS];
I guess by now I have over 10 of those. Can the massive use of those cause lag?

3rd) Apart from having something being called alot, what other things can cause lag/slow downs that I should evade?


Re: Some answers please? - Abagail - 03.06.2017

Having a timer running every .5 seconds is obviously going to reduce performance as appose to using other methods, especially if it's cluttered. What specific types of things are you doing in it?

Using a lot of variables is also something that should generally be avoided, use data enums and arrays (or utilize MySQL tricks so you don't store locally where able). Things such as g_God where it's either a 0 or 1 value could also be used as a boolean, which has two values: true and false. Simply prefix your variable with bool: (bool: g_God) in the definition and use the true/false values instead of numerics. You could also use things such as the ternary operator instead of clogging your script with if statements. For example, this becomes:

pawn Код:
format(string, sizeof string, "%s: %s", PlayerData[playerid][pPlayerName], (PlayerData[playerid][pAvailable] == true) ? ("Available") : ("False"));
This isn't the best example, things such as format and other slow functions could be replaced with more efficient functions. There's a TON of different optimization tricks in ******'s old Code Optimizations thread.

Plenty of other things could also slow down the server, including an increasing amount of players, things such as client (and also server sided) ELM and similar modifications also share resources to sync data.


Re: Some answers please? - Dragonic - 03.06.2017

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Having a timer running every .5 seconds is obviously going to reduce performance as appose to using other methods, especially if it's cluttered.
What other methods, can you give some examples?

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Using a lot of variables is also something that should generally be avoided, use data enums and arrays (or utilize MySQL tricks so you don't store locally where able). Things such as g_God where it's either a 0 or 1 value could also be used as a boolean, which has two values: true and false. Simply prefix your variable with bool: (bool: g_God) in the definition and use the true/false values instead of nunmerics.
Well I have no clue on how to use MySQL and I don't think I want to delay the release so that I can learn it and adapt the entire script because the whole server relies on storing those 1 and 0s. About boolean, I may use it if it is lighter/better than the current way I'm doing it.

Thanks anyway.


Re: Some answers please? - Abagail - 03.06.2017

Quote:
Originally Posted by Dragonic
Посмотреть сообщение
What other methods, can you give some examples?



Well I have no clue on how to use MySQL and I don't think I want to delay the release so that I can learn it and adapt the entire script because the whole server relies on storing those 1 and 0s. About boolean, I may use it if it is lighter/better than the current way I'm doing it.

Thanks anyway.
That's just a small suggestion (which depending on what you're doing may be worse, it's situational usage), it's not something needed anyway. You should use the booleans where you can, anything not storing anything other than 0 and 1 is fair game. As for timers, it's also pretty situational as to what else you could do. What types of things do you have inside of the timer?

Also, I updated my post, you may not have seen. You should check ******'s Code Optimizations thread which contains a large number of cool optimization tricks.


Re: Some answers please? - Dragonic - 03.06.2017

Quote:
Originally Posted by Abagail
Посмотреть сообщение
What types of things do you have inside of the timer?
Stuff like Hide or Show Textdraws depending on the situation, or to turn like g_God[playerid] to 1 in certain conditions. Nothing complex but there's alot of things....

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Also, I updated my post, you may not have seen. You should check ******'s Code Optimizations thread which contains a large number of cool optimization tricks.
Yes I saw it and took a quick look at it... Couldn't understand a thing. FeelsBadMan


Re: Some answers please? - Abagail - 03.06.2017

Quote:
Originally Posted by Dragonic
Посмотреть сообщение
Stuff like Hide or Show Textdraws depending on the situation, or to turn like g_God[playerid] to 1 in certain conditions. Nothing complex but there's alot of things....



Yes I saw it and took a quick look at it... Couldn't understand a thing. FeelsBadMan
What specific conditions are you changing the status of the players god mode? I suspect it can be ported to a callback most likely.