Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import("modules/GO_wFileLoader");
- local Player = {};
- for(local i = 0; i < getMaxSlots(); ++i)
- {
- Player[i] <- {};
- Player[i].itemCount <- 0;
- Player[i].item <- {};
- Player[i].timeLastItem <- 0;
- for(local j = 0; j < 5000; ++j) //5000 to maksymalna liczba itemów w gothicu
- {
- Player[i].item[j] <- {instance = "", amount = 0};
- }
- }
- function onDisconnect(playerID, reason)
- {
- saveItems(playerID);
- clearItemsTable(playerID);
- }
- function onJoin(playerID)
- {
- loadItems(playerID);
- }
- function onEquipment(playerName, instance, amount)
- {
- for(local i = 0; i < getMaxSlots(); ++i)
- {
- if( isConnected(i) == true && getPlayerName(i) == playerName )
- {
- if( Player[i].timeLastItem < getTickCount() )
- {
- 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
- Player[i].timeLastItem = getTickCount() + 3000;
- }
- Player[i].item[Player[i].itemCount].instance = instance;
- Player[i].item[Player[i].itemCount].amount = amount;
- Player[i].itemCount = Player[i].itemCount + 1; //Zwiększamy liczbę itemów o 1
- break;
- }
- }
- }
- function saveItems(playerID)
- {
- local itemsCount = Player[playerID].itemCount;
- if( itemsCount > 0 )
- {
- local file = fileOpen(getPlayerName(playerID) + ".eq", "w");
- if( file )
- {
- for(local i = 0; i < itemsCount; ++i)
- fileWrite(file, format("%s %d", Player[playerID].item[i].instance, Player[playerID].item[i].amount));
- fileClose(file);
- }
- }
- }
- //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
- function loadItems(playerID)
- {
- local file = fileOpen(getPlayerName(playerID) + ".eq", "r");
- if( file )
- {
- local buffer = "";
- 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
- {
- buffer = format("%s", buffer);
- local args = sscanf("sd", buffer);
- callClientFunc(playerID, "onEquipment", args[0], args[1]);
- buffer = "";
- }
- fileClose(file);
- }
- }
- function clearItemsTable(playerID) //Bardzo przydatne
- {
- Player[playerID].itemCount = 0;
- for(local i = 0; i < 5000; ++i)
- {
- Player[playerID].item[i].instance = "";
- Player[playerID].item[i].amount = 0;
- Player[playerID].timeLastItem = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement