peinneon

simple save weapon

Feb 1st, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.77 KB | None | 0 0
  1. // Simple Weapon saving system by Noobist
  2.  
  3. // Includes
  4. #include <a_samp>
  5. #include <dini>
  6.  
  7. // Defines
  8. #define FILTERSCRIPT
  9.  
  10. // Callbacks
  11. forward SaveWeapon(playerid);
  12. forward LoadWeapon(playerid);
  13. forward SaveWeaponToDini(playerid);
  14.  
  15. public OnFilterScriptInit()
  16. {
  17.     print("\n--------------------------------------");
  18.     print(" Simple Weapon Autosave System by Noobist Loaded");
  19.     print("--------------------------------------\n");
  20.     return 1;
  21. }
  22.  
  23. public OnFilterScriptExit()
  24. {
  25.     print("\n--------------------------------------");
  26.     print(" Simple Weapon Autosave System by Noobist Unloaded");
  27.     print("--------------------------------------\n");
  28.     return 1;
  29. }
  30.  
  31. stock GetPName(playerid)
  32. {
  33.     new PName[MAX_PLAYER_NAME];
  34.     GetPlayerName(playerid, PName, sizeof(PName));
  35.     return PName;
  36. }
  37.  
  38. public SaveWeapon(playerid)
  39. {
  40.     new Slot[MAX_STRING], SlotAmmo[MAX_STRING], weapon, ammo;
  41.     for(new i = 0; i < 13; i++)
  42.     {
  43.         format(Slot, sizeof(Slot), "PSlot%i", i);
  44.         format(SlotAmmo, sizeof(SlotAmmo), "PSlotAmmo%i", i);
  45.         GetPlayerWeaponData(playerid, i, weapon, ammo);
  46.         SetPVarInt(playerid, Slot, weapon);
  47.         SetPVarInt(playerid, SlotAmmo, ammo);
  48.     }
  49.     return 1;
  50. }
  51.  
  52. public LoadWeapon(playerid)
  53. {
  54.     if(GetPVarInt(playerid, "HasFile") == 0) return 0;
  55.     new Slot[MAX_STRING], SlotAmmo[MAX_STRING];
  56.     for(new i = 0; i < 13; i++)
  57.     {
  58.         format(Slot, sizeof(Slot), "PSlot%i", i);
  59.         format(SlotAmmo, sizeof(SlotAmmo), "PSlotAmmo%i", i);
  60.         GivePlayerWeapon(playerid, GetPVarInt(playerid, Slot), GetPVarInt(playerid, SlotAmmo));
  61.     }
  62.     return 1;
  63. }
  64.  
  65. public SaveWeaponToDini(playerid)
  66. {
  67.     new PFile[MAX_STRING], Slot[MAX_STRING], SlotAmmo[MAX_STRING];
  68.     format(PFile, sizeof(PFile), "Weaps\\%s.ini", GetPName(playerid));
  69.     if(!dini_Exists(PFile)) dini_Create(PFile);
  70.     for(new i = 0; i < 13; i++)
  71.     {
  72.         format(Slot, sizeof(Slot), "PSlot%i", i);
  73.         format(SlotAmmo, sizeof(SlotAmmo), "PSlotAmmo%i", i);
  74.         dini_IntSet(PFile, Slot, GetPVarInt(playerid, Slot));
  75.         dini_IntSet(PFile, SlotAmmo, GetPVarInt(playerid, SlotAmmo));
  76.     }
  77.     return 1;
  78. }
  79.  
  80. public OnPlayerConnect(playerid)
  81. {
  82.     new PFile[MAX_STRING];
  83.     format(PFile, sizeof(PFile), "Weaps\\%s.ini", GetPName(playerid));
  84.     if(dini_Exists(PFile))
  85.     {
  86.         SetPVarInt(playerid, "HasFile", 1);
  87.         new Slot[MAX_STRING], SlotAmmo[MAX_STRING];
  88.         for(new i = 0; i < 13; i++)
  89.         {
  90.                 format(Slot, sizeof(Slot), "PSlot%i", i);
  91.                 format(SlotAmmo, sizeof(SlotAmmo), "PSlotAmmo%i", i);
  92.                 SetPVarInt(playerid, Slot, dini_Int(PFile, Slot));
  93.                 SetPVarInt(playerid, SlotAmmo, dini_Int(PFile, SlotAmmo));
  94.         }
  95.     }
  96.     return 1;
  97. }
  98.  
  99. public OnPlayerDeath(playerid, killerid, reason) { SaveWeapon(playerid); }
  100. public OnPlayerSpawn(playerid) { LoadWeapon(playerid); }
  101. public OnPlayerDisconnect(playerid, reason) { SaveWeaponToDini(playerid); }
Advertisement
Add Comment
Please, Sign In to add comment