Saving Characters Original Shield and Weapon
Hello everyone, I've got some problems when saving the original weapon and shield when a user logs out.
I'll show you what's happening and what I've tried to fix it.
First I got this global variable:
Code:
public class client extends Player implements Runnable {
Code:
/* code is deleted here to make it clean for RaGEZONE */
public int originalWeapon = -1;
public int originalShield = -1;
Then the originalShield gets changed as soon as I start fishing:
Code:
public boolean fishing() {
if (playerLevel[playerFishing] >= fishing[1]) {
if (freeSlots() > 0) {
if (fishing[0] == 1) {
ManipulateDirection();
originalShield = playerEquipment[playerShield];
originalWeapon = playerEquipment[playerWeapon];
playerEquipment[playerShield] = fishing[6]; // This is the code that changes it.
playerEquipment[playerWeapon] = -1; // fishing[6] is the ID of, in my case, a fishing net.
setAnimation(fishing[7]);
fishing[0] = 2;
sendMessage("You started fishing with your "+GetItemName(fishing[6])+"...");
}
int Rnd = ((99 - fishing[1]) - (playerLevel[playerFishing] - fishing[1]));
if (Rnd <= 1) {
Rnd = 2;
}
if (fishing[0] == 2 && misc.random2(Rnd) == 1) {
boolean DoFish = true;
if (fishing[5] > -1) {
if (IsItemInBag(fishing[5]) == false) {
DoFish = false;
sendMessage("You have run out of "+GetItemName(fishing[5])+".");
playerEquipment[playerWeapon] = originalWeapon;
playerEquipment[playerShield] = originalShield;
originalWeapon = -1;
originalShield = -1;
resetAnimation();
resetFI();
} else {
deleteItem(fishing[5], GetItemSlot(fishing[5]), 1);
}
}
if (DoFish == true) {
if (fishing[8] > 0) {
GetRandomFish();
}
setAnimation(fishing[7]);
addItem(fishing[4], 1);
addSkillXP((fishing[2]), playerFishing);
sendMessage("You caught a "+GetItemName(fishing[4]).toLowerCase()+".");
}
}
} else {
sendMessage("You don't have enough space, please store some items.");
if (fishing[0] > 0) {
playerEquipment[playerWeapon] = originalWeapon;
playerEquipment[playerShield] = originalShield;
originalWeapon = -1;
originalShield = -1;
resetAnimation();
}
resetFI();
}
} else {
sendMessage("You'll need "+fishing[1]+" "+statName[playerFishing]+" to fish here.");
resetFI();
return false;
}
return true;
}
Then when a user logs out it changes the 'playerEquipment[playerShield]' to the ID of the fishing net, but it should change it to the ID of the originalShield. So I've tried the following:
Code:
public boolean savechar() {
Code:
BufferedWriter characterfile = null;
if(originalWeapon != -1) {
playerEquipment[playerWeapon] = originalWeapon;
}
if(originalShield != -1) {
playerEquipment[playerShield] = originalShield;
}
try {
characterfile = new BufferedWriter(new FileWriter("./characters/"+playerName+".txt"));
/*ACCOUNT etc.... etc.... etc....*/
How do I change the weapon and shield back to original while you log out during fishing?
Thanks in Advance,
DaMaGeX
Re: Saving Characters Original Shield and Weapon
Does your attempt not work, what happens when you try that code?
Re: Saving Characters Original Shield and Weapon
It still saves the fishingnet to the userfile, is there any var_dump function in java?
So I can check both variables in the server cmd terminal.
I think debugging will help me alot.
I'm a php programmer btw.