PDA

View Full Version : Optimization


Micko123
27/04/2016, 11:13 AM
Can anyone explain me optimization of script. What is best way to optimize script?? Sry if this is noobish but i am newbie :D

CalvinC
27/04/2016, 11:35 AM
Optimization includes tweaking and changing things to make them faster or take up less memory.
There's lots of small things you can optimize, the 4 i would encourage most are:

Decrease string sizes as much as possible, or atleast make sure when using SCM that they're not beyond 128.

Use includes like zcmd/ycmd (not dcmd) for faster commands, and foreach for faster player loops.

Redefine "MAX_PLAYERS" to the actual max player slots you have set on your server right after #include <a_samp>
An example of how to set it to 100 players:
#undef MAX_PLAYERS
#define MAX_PLAYERS 100

Don't save players when they disconnect, save them instantly when their things are changed that needs to be saved.
Otherwise the server hangs when players disconnect.

Micko123
27/04/2016, 12:05 PM
WOW thank you for this :) Helped me a lot

Lumanov
27/04/2016, 04:11 PM
#undef MAX_PLAYERS
#define MAX_PLAYERS 100

Better this way:

#undef MAX_PLAYERS
const MAX_PLAYERS = 100;

Micko123
27/04/2016, 04:13 PM
Why? (sry for asking but i dont want to copy paste i want to learn.) Why const? I don't get it..