Advertisement
Guest User

EQ Server

a guest
Oct 22nd, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.43 KB | None | 0 0
  1. import("modules/GO_wFileLoader");
  2.  
  3. local Player = {};
  4.  
  5. for(local i = 0; i < getMaxSlots(); ++i)
  6. {
  7.     Player[i] <- {};
  8.     Player[i].itemCount <- 0;
  9.     Player[i].item <- {};
  10.     Player[i].timeLastItem <- 0;
  11.     for(local j = 0; j < 5000; ++j) //5000 to maksymalna liczba itemów w gothicu
  12.     {
  13.         Player[i].item[j] <- {instance = "", amount = 0};
  14.     }
  15. }
  16.  
  17. function onDisconnect(playerID, reason)
  18. {
  19.     saveItems(playerID);
  20.     clearItemsTable(playerID);
  21. }
  22.  
  23. function onJoin(playerID)
  24. {
  25.     loadItems(playerID);
  26. }
  27.  
  28. function onEquipment(playerName, instance, amount)
  29. {
  30.     for(local i = 0; i < getMaxSlots(); ++i)
  31.     {
  32.         if( isConnected(i) == true && getPlayerName(i) == playerName )
  33.         {
  34.             if( Player[i].timeLastItem < getTickCount() )
  35.             {
  36.                 Player[i].itemCount = 0; //Jeśli ostatni item przesłanybył więcej niż 3000 ms temu, to licznik leci od nowa, zapobiega to powielaniu się itemów
  37.                 Player[i].timeLastItem = getTickCount() + 3000;
  38.             }
  39.             Player[i].item[Player[i].itemCount].instance = instance;
  40.             Player[i].item[Player[i].itemCount].amount = amount;
  41.             Player[i].itemCount = Player[i].itemCount + 1; //Zwiększamy liczbę itemów o 1
  42.             break;
  43.         }
  44.     }
  45. }
  46.  
  47. function saveItems(playerID)
  48. {
  49.     local itemsCount = Player[playerID].itemCount;
  50.     if( itemsCount > 0 )
  51.     {
  52.         local file = fileOpen(getPlayerName(playerID) + ".eq", "w");
  53.         if( file )
  54.         {
  55.             for(local i = 0; i < itemsCount; ++i)
  56.                 fileWrite(file, format("%s %d", Player[playerID].item[i].instance, Player[playerID].item[i].amount));
  57.                
  58.             fileClose(file);
  59.         }
  60.     }
  61. }
  62.  
  63. //Info: Gracz musi siedzieć minutę na serwerze, aby przedmioty zapisały się przy następnym wyjściu, można dać krótszy czas w skrypcie klienta
  64. function loadItems(playerID)
  65. {
  66.     local file = fileOpen(getPlayerName(playerID) + ".eq", "r");
  67.     if( file )
  68.     {
  69.         local buffer = "";
  70.         while( typeof(fileRead(file, buffer)) != "bool" ) //Bo nubzior zepsuł i w przypadku niepowodzenia zwraca false, czyli typ bool, jeśli wczytano prawdopodobnie występuje typ pusty
  71.         {
  72.             buffer = format("%s", buffer);
  73.             local args = sscanf("sd", buffer);
  74.             callClientFunc(playerID, "onEquipment", args[0], args[1]);
  75.             buffer = "";
  76.         }
  77.         fileClose(file);
  78.     }
  79. }
  80.  
  81. function clearItemsTable(playerID) //Bardzo przydatne
  82. {
  83.     Player[playerID].itemCount = 0;
  84.     for(local i = 0; i < 5000; ++i)
  85.     {
  86.         Player[playerID].item[i].instance = "";
  87.         Player[playerID].item[i].amount = 0;
  88.         Player[playerID].timeLastItem = 0;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement