Guest User

weapon save

a guest
Feb 3rd, 2012
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini> // Programmed with Dini.inc version 1.5.1
  3.  
  4. /*
  5. Weapons Saving System by Phyro - 2009
  6. Searching some technical SA-MP Tools ? visit : www.phyro.co.nr
  7. */
  8.  
  9. #define PATH "Weapons" // Folder where players data saved
  10.  
  11. forward Health();
  12.  
  13. new bool:AlreadyGiveWeapons[MAX_PLAYERS];
  14.  
  15. public OnFilterScriptInit()
  16. {
  17. printf("|------------------------------------------------|");
  18. printf("|-------- Weapons Saving System By Phyro --------|");
  19. printf("|----------- All rights reserved 2009 -----------|");
  20. printf("|------------------------------------------------|");
  21. return 1;
  22. }
  23.  
  24. public OnFilterScriptExit()
  25. {
  26. printf("|------------------------------------------------|");
  27. printf("|--------- Unload Weapons Saving System ---------|");
  28. printf("|------------------------------------------------|");
  29. return 1;
  30. }
  31.  
  32. public OnPlayerConnect(playerid)
  33. {
  34. AlreadyGiveWeapons[playerid] = false;
  35. return 1;
  36. }
  37.  
  38. public OnPlayerDisconnect(playerid, reason)
  39. {
  40. SaveWeaponsToFile(playerid);
  41. return 1;
  42. }
  43.  
  44. public Health()
  45. {
  46. for(new i; i<MAX_PLAYERS; i++)
  47. {
  48. {
  49. new Float:health;
  50. GetPlayerHealth(i, health);
  51. if(health < 20)
  52. {
  53. SaveWeaponsToFile(i);
  54. }
  55. }
  56. }
  57. return 1;
  58. }
  59.  
  60. SaveWeaponsToFile(playerid)
  61. {
  62. new i, path[50], string[128], weaponid, ammo;
  63. path = GetPlayerFormattedName(playerid);
  64. if (!dini_Exists(path)) dini_Create(path);
  65. for (i=0; i<13; i++)
  66. {
  67. GetPlayerWeaponData(playerid,i,weaponid,ammo);
  68. format(string,sizeof(string),"Weapon - %d",i);
  69. dini_IntSet(path,string,weaponid);
  70. format(string,sizeof(string),"AmmoID - %d",i);
  71. dini_IntSet(path,string,ammo == 65535 ? 0 : ammo);
  72. }
  73. }
  74.  
  75. forward LoadWeaponsToFile(playerid);
  76. public LoadWeaponsToFile(playerid)
  77. {
  78. new i, path[50], string[128], weaponid, ammo;
  79. path = GetPlayerFormattedName(playerid);
  80. ResetPlayerWeapons(playerid);
  81. for (i=0; i<13; i++)
  82. {
  83. format(string,sizeof(string),"Weapon - %d",i);
  84. weaponid = dini_Int(path,string);
  85. format(string,sizeof(string),"AmmoID - %d",i);
  86. ammo = dini_Int(path,string);
  87. GivePlayerWeapon(playerid,weaponid,ammo);
  88. }
  89. AlreadyGiveWeapons[playerid] = true;
  90. }
  91.  
  92. GetPlayerFormattedName(playerid)
  93. {
  94. new name[24], full[50];
  95. GetPlayerName(playerid,name,sizeof(name));
  96. format(full,sizeof(full),"%s/%s.txt",PATH,name);
  97. return full;
  98. }
  99.  
  100. public OnPlayerSpawn(playerid)
  101. {
  102. if (!AlreadyGiveWeapons[playerid]) SetTimerEx("LoadWeaponsToFile",250,false,"i",playerid);
  103. return 1;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment