Optimization
#1

Hi,


So this is my first GM, that I'm trying to improve everyday, but I'm still a beginner and I wanted to know what could I optimize in my GM, to make it faster/better. I used this: https://sampforum.blast.hk/showthread.php?tid=485633
as a base for my mysql system.
If you have the time to help me, please explain me why should I change X to X and what will it change.



Pastbin: http://pastebin.com/KwsTWLjv

If I'm not allowed to post this here(even if it's a request for script help), just tell me, I will remove this.


Thank you !


Ps: If you think this hasn't it place here, tell me
Reply
#2

There is a thread 'Looking for scripters/helpers? Post here'. It at the top most of this board and you missed it in your sight.
Reply
#3

You are using too big variables, don't use a 256 variable where you can use 128 variable, and study rbits that is something really good and it can optimize your script very good.
Reply
#4

Thank you Venom,
I read this tutorial: https://sampforum.blast.hk/showthread.php?tid=55261

So I should put all my string to 128 ? I will do it

Could you please explain me what "rbits" is ?

Thank you


@ACI I'm not searching someone to script for me. I'm just asking for "tips" or something to optimize my Gamemode.
Reply
#5

Don't make all strings to 128, make them depending on how big the string is or it will not give all characters.

- Use foreach for loops
- Use y commands or zcmd
- If you will use onplayerupdate, use Cessil's limiting method in his anticheat tips.
- Serversided weapons
- Keep timer amount at minimum and rather use gettime()
- Avoid using too many loops and make them work on minimum usage.
- Keep variable amounts at minimum and avoid using duplicate ones.
Reply
#6

Thank you !

-Foreach is for loop that need "IsPlayerConnected" right ?
-I'm using zCMD atm.
-Could you please explain me what do you mean by "Serversided weapons" ?
-Actually I don't know how to use gettime well. So I'm using Timers, is there a big difference ?

Thank you !
Reply
#7

There are lots of things you can do to optimize your script.
Use switch instead of if...else
Quote:

if(reason == 0) { raison = "Coup de Poing."; }
else if(reason == 1) { raison = "Poing Amйricain"; }
else if(reason == 2) { raison = "Club de Golf"; }
else if(reason == 3)

And here
Quote:

if(hittype==BULLET_HIT_PETROL_TANK)// Quand on tire sur le reservoir d'essence
{

and lots of other places where you have RHS constants.

Use >> and << for division and multiplication of numbers by powers of 2.
number & (divisor - 1) for powers of 2 will give the remainder - this is faster!
Use static and avoid useless initializations of variables in functions.

Some places where you have used format can be done using strcat easily which is faster.

Use proper arrays with proper size.You are wasting so many cells.Why do you need to make a string 256 cells big when the max input/output limit of client message is 128?

Refer these links:
https://sampforum.blast.hk/showthread.php?tid=216730
https://sampforum.blast.hk/showthread.php?tid=57018
Reply
#8

Thank you,


I did what you told me to do for the switch instead of reason, I don't understand what do you mean by this:

Код:
Use >> and << for division and multiplication of numbers by powers of 2.
number & (divisor - 1) for powers of 2 will give the remainder - this is faster!

Use static and avoid useless initializations of variables in functions.
"Use proper arrays with proper size.You are wasting so many cells."
How can I how many cells I need please ? Is there a tool that can do it or something like that ?


Thank you !
Reply
#9

Quote:
Originally Posted by anou1
Посмотреть сообщение
Thank you,


I did what you told me to do for the switch instead of reason, I don't understand what do you mean by this:

Код:
Use >> and << for division and multiplication of numbers by powers of 2.
number & (divisor - 1) for powers of 2 will give the remainder - this is faster!

Use static and avoid useless initializations of variables in functions.
"Use proper arrays with proper size.You are wasting so many cells."
How can I how many cells I need please ? Is there a tool that can do it or something like that ?


Thank you !
Serversided weapons are not an optimizattion really, you may find more info at the anticheat tips topic by Cessil.

gettime() = variable;

Can be used for command timers or to check if a player has exceeded a time to wait. For example, to allow the player to pickup a pickup every X seconds.
Reply
#10

Forget about >> and <<.Those are bitwise operators.

About the arrays:
You need to do it while you write code.
For example
Quote:

new str[256];
format(str,sizeof(str),"%s is a dog",playername);
SendClientMessage(playerid,COLOR,str);

In that code you'd just need a string to hold player name,the remaining text and one /0.
That equals MAX_PLAYER_NAME + 9 + 1.You'd need just 34 cells and the remaining 256-34=222 cells go waste.That is equivalent to 222*4 = 888 bytes waste of memory!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)