Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Strings
- // bad usage
- public OnPlayerConnect(playerid)
- {
- new str[500], name[MAX_PLAYERS_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- format(str, sizeof(str), "*%s has joined", name);
- SendClientMessage(playerid, -1, str);
- return 1;
- }
- // right usage
- public OnPlayerConnect(playerid)
- {
- new str[80];
- format(str, sizeof(str), "*%s has joined", GetName(playerid));
- SendClientMessage(playerid, -1, str);
- return 1;
- }
- // this in last lines of you script
- stock GetName(playerid)
- {
- new szName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, szName, sizeof(szName));
- return szName;
- }
- // with that u saves the name strings cells and also usage of CPU
- // explain this:
- // every time you call for GetPlayerName the server search for definition of it so he will search on samp-server.exe
- // for native and will amx_function things
- // better make one stock than use this native every time also there just one string better than a string with 24 cells for every uses
- // exemple
- // normal : in script with 1k line: GetPlayerName used 15 times so 15 x 24 = 360 cells added (average of 360 kb)
- // optimized : in script with 1k line: GetPlayerName used 15 times with using stock so 1 x 24 = 24 cells (average of 24 kb)
- // results: 224 cells/kb optimized :D
- //------------------------------------------------------------------------------------
- // Command Optimizing
- // Better use zcmd or Pawn:CMD DO NOT USE STRCMP for commads
- // bad usage of cmd
- CMD:test(playerid, params[])
- {
- if(IsAdmin[playerid] == 1)
- {
- // codes ----
- }
- else
- {
- // send mesage you aren't admin
- }
- return 1;
- }
- // right usage
- CMD:test(playerid, params[])
- {
- if(IsAdmin[playerid] == 0) return //send message you aren't admin
- // codes
- return 1;
- }
- // and with that u cmd optimized better than server read one line better than read all the cmd for one line
- // also that with give less lines than before
- //------------------------------------------------------------------------------------
- // functions
- // bad usage
- public onPlayerInDerby(playerid)
- {
- if(PlayerInDerby[playerid] == 1)
- {
- if(IsPlayerAdmin(playerid))
- {
- // codes
- }
- }
- else return 1;
- return 1;
- }
- // optimized
- public onPlayerInDerby(playerid)
- {
- if(PlayerInDerby[playerid] == 0) return 1;
- if(!IsPlayerAdmin(playerid)) return 1;
- // codes
- return 1;
- }
- // less lines and low cpu usage :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement