Advertisement
LVPYassine

Untitled

Jan 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1.  
  2. // Strings
  3.  
  4. // bad usage
  5.  
  6. public OnPlayerConnect(playerid)
  7. {
  8. new str[500], name[MAX_PLAYERS_NAME];
  9. GetPlayerName(playerid, name, sizeof(name));
  10. format(str, sizeof(str), "*%s has joined", name);
  11. SendClientMessage(playerid, -1, str);
  12. return 1;
  13. }
  14.  
  15. // right usage
  16.  
  17. public OnPlayerConnect(playerid)
  18. {
  19. new str[80];
  20. format(str, sizeof(str), "*%s has joined", GetName(playerid));
  21. SendClientMessage(playerid, -1, str);
  22. return 1;
  23. }
  24.  
  25. // this in last lines of you script
  26. stock GetName(playerid)
  27. {
  28. new szName[MAX_PLAYER_NAME];
  29. GetPlayerName(playerid, szName, sizeof(szName));
  30. return szName;
  31. }
  32.  
  33. // with that u saves the name strings cells and also usage of CPU
  34.  
  35. // explain this:
  36.  
  37. // every time you call for GetPlayerName the server search for definition of it so he will search on samp-server.exe
  38. // for native and will amx_function things
  39. // 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
  40. // exemple
  41. // normal : in script with 1k line: GetPlayerName used 15 times so 15 x 24 = 360 cells added (average of 360 kb)
  42. // optimized : in script with 1k line: GetPlayerName used 15 times with using stock so 1 x 24 = 24 cells (average of 24 kb)
  43. // results: 224 cells/kb optimized :D
  44.  
  45.  
  46. //------------------------------------------------------------------------------------
  47. // Command Optimizing
  48.  
  49. // Better use zcmd or Pawn:CMD DO NOT USE STRCMP for commads
  50. // bad usage of cmd
  51.  
  52. CMD:test(playerid, params[])
  53. {
  54. if(IsAdmin[playerid] == 1)
  55. {
  56. // codes ----
  57. }
  58. else
  59. {
  60. // send mesage you aren't admin
  61. }
  62. return 1;
  63. }
  64.  
  65. // right usage
  66.  
  67. CMD:test(playerid, params[])
  68. {
  69. if(IsAdmin[playerid] == 0) return //send message you aren't admin
  70. // codes
  71. return 1;
  72. }
  73.  
  74. // and with that u cmd optimized better than server read one line better than read all the cmd for one line
  75.  
  76. // also that with give less lines than before
  77.  
  78. //------------------------------------------------------------------------------------
  79. // functions
  80.  
  81.  
  82. // bad usage
  83.  
  84. public onPlayerInDerby(playerid)
  85. {
  86. if(PlayerInDerby[playerid] == 1)
  87. {
  88. if(IsPlayerAdmin(playerid))
  89. {
  90. // codes
  91. }
  92. }
  93. else return 1;
  94. return 1;
  95. }
  96.  
  97. // optimized
  98.  
  99. public onPlayerInDerby(playerid)
  100. {
  101. if(PlayerInDerby[playerid] == 0) return 1;
  102. if(!IsPlayerAdmin(playerid)) return 1;
  103. // codes
  104. return 1;
  105. }
  106.  
  107. // less lines and low cpu usage :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement