Ey
Posted: 17 Feb 2014, 10:43
so, I got a problem with a command I'm making, basically I'm making it so you can equip a block that you have in your "inventory" and you'll place that block until you don't have any left. I am having problems with detecting when the player places something instead of destroying something because changing a block can mean both, and when they run out of blocks, it's supposed to remove the block from their inventory and stop placing it, however it doesn't do that, it just keeps it there with 0 blocks of that type stored, and keeps on letting them place that block. Also, it will only place 1 block of it and then it will stop
This is the code for them equipping it, I don't think anything is wrong with that
And this is where I think the error is, the Blockchange1() void.
I wouldn't be surprised if I'm having a derp moment. I would appreciate any feedback you can give me.
This is the code for them equipping it, I don't think anything is wrong with that
- Code: Select all
if(pe.equipped == item) {
Player.SendMessage(p, "That block is already equipped.");
return;
} else {
pe.equipped = item;
Player.SendMessage(p, Block.Name(item) + " equipped.");
p.Blockchange += new Player.BlockchangeEventHandler(this.Blockchange1);
}
And this is where I think the error is, the Blockchange1() void.
- Code: Select all
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
{
p.ClearBlockchange();
byte tile = type;
PlayerExtra pe = PlayerExtra.Find(p);
if(pe == null) {
pe = new PlayerExtra(p);
}
if(pe.equipped != (byte)255) {
if(tile==Block.Byte("air")) {
p.level.Blockchange(p, x, y, z, tile);
return;
}
int value;
if(pe.inventory.TryGetValue(pe.equipped, out value) == false) {
pe.inventory.Remove(pe.equipped);
pe.equipped = (byte)255;
p.Blockchange -= new Player.BlockchangeEventHandler(this.Blockchange1);
return;
} else if (value == 0) {
pe.inventory.Remove(pe.equipped);
pe.equipped = (byte)255;
p.Blockchange -= new Player.BlockchangeEventHandler(this.Blockchange1);
return;
}
p.level.Blockchange(p, x, y, z, pe.equipped);
pe.inventory.Remove(pe.equipped);
pe.inventory.Add(pe.equipped, value - 1);
Player.SendMessage(p, "Placed 1 block of " + Block.Name(pe.equipped) + ".");
}
}
I wouldn't be surprised if I'm having a derp moment. I would appreciate any feedback you can give me.