Advertisement
Guest User

weapon save

a guest
Feb 3rd, 2012
704
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. Email : mottiokla@gmail.com
  8. */
  9.  
  10. #define PATH "Weapons" // Folder where players data saved
  11.  
  12. forward Health();
  13.  
  14. new bool:AlreadyGiveWeapons[MAX_PLAYERS];
  15.  
  16. public OnFilterScriptInit()
  17. {
  18. printf("|------------------------------------------------|");
  19. printf("|-------- Weapons Saving System By Phyro --------|");
  20. printf("|----------- All rights reserved 2009 -----------|");
  21. printf("|------------------------------------------------|");
  22. return 1;
  23. }
  24.  
  25. public OnFilterScriptExit()
  26. {
  27. printf("|------------------------------------------------|");
  28. printf("|--------- Unload Weapons Saving System ---------|");
  29. printf("|------------------------------------------------|");
  30. return 1;
  31. }
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35. AlreadyGiveWeapons[playerid] = false;
  36. return 1;
  37. }
  38.  
  39. public OnPlayerDisconnect(playerid, reason)
  40. {
  41. SaveWeaponsToFile(playerid);
  42. return 1;
  43. }
  44.  
  45. public Health()
  46. {
  47. for(new i; i<MAX_PLAYERS; i++)
  48. {
  49. {
  50. new Float:health;
  51. GetPlayerHealth(i, health);
  52. if(health < 20)
  53. {
  54. SaveWeaponsToFile(i);
  55. }
  56. }
  57. }
  58. return 1;
  59. }
  60.  
  61. SaveWeaponsToFile(playerid)
  62. {
  63. new i, path[50], string[128], weaponid, ammo;
  64. path = GetPlayerFormattedName(playerid);
  65. if (!dini_Exists(path)) dini_Create(path);
  66. for (i=0; i<13; i++)
  67. {
  68. GetPlayerWeaponData(playerid,i,weaponid,ammo);
  69. format(string,sizeof(string),"Weapon - %d",i);
  70. dini_IntSet(path,string,weaponid);
  71. format(string,sizeof(string),"AmmoID - %d",i);
  72. dini_IntSet(path,string,ammo == 65535 ? 0 : ammo);
  73. }
  74. }
  75.  
  76. forward LoadWeaponsToFile(playerid);
  77. public LoadWeaponsToFile(playerid)
  78. {
  79. new i, path[50], string[128], weaponid, ammo;
  80. path = GetPlayerFormattedName(playerid);
  81. ResetPlayerWeapons(playerid);
  82. for (i=0; i<13; i++)
  83. {
  84. format(string,sizeof(string),"Weapon - %d",i);
  85. weaponid = dini_Int(path,string);
  86. format(string,sizeof(string),"AmmoID - %d",i);
  87. ammo = dini_Int(path,string);
  88. GivePlayerWeapon(playerid,weaponid,ammo);
  89. }
  90. AlreadyGiveWeapons[playerid] = true;
  91. }
  92.  
  93. GetPlayerFormattedName(playerid)
  94. {
  95. new name[24], full[50];
  96. GetPlayerName(playerid,name,sizeof(name));
  97. format(full,sizeof(full),"%s/%s.txt",PATH,name);
  98. return full;
  99. }
  100.  
  101. public OnPlayerSpawn(playerid)
  102. {
  103. if (!AlreadyGiveWeapons[playerid]) SetTimerEx("LoadWeaponsToFile",250,false,"i",playerid);
  104. return 1;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement