Need help with some code to make a game
Posted:
10 Jul 2013, 15:02
by Leeizazombie
Okay so I plan to make a game based with a timer, for example, the timer starts and every few seconds it says you are hungry... is it possible to make it that when the player breaks a block, say: shroom_red, and it restarts the timer? aslo how do I make the code "kill" the player?
Re: Need help with some code to make a game
Posted:
10 Jul 2013, 15:25
by ismellike
You will have to use the System.Timers library, then experiment with the following.
- Code: Select all
Timer timer = new Timer(1000); //1 second timer
public override void Init()
{
timer.Elapsed+= new ElapsedEventHandler (Elapsed);
}
void Elapsed(object sender, ElapsedEventArgs e)
{
Player.players.ForEach(p=>
{
p.health-=1;
if(p.health==0)
{
//however you want to kill him
p.health=100;
}
// make messages when his health is like at 50, 25, etc
}
}
now if you want the player to get some health when he breaks a mushroom, you would something like this:
- Code: Select all
p.Blockchange+=new Player.BlockchangeEventHandler(p_Blockchange);
void p_Blockchange(Player p, ushort x,ushort y, ushort z, byte type)
{
if(p.level.GetTile(x,y,z)==Block.redmushroom)
p.health+=5;
}
Re: Need help with some code to make a game
Posted:
10 Jul 2013, 15:43
by Leeizazombie
Ahh nice, it will take me some time
thanks!
Re: Need help with some code to make a game
Posted:
10 Jul 2013, 17:29
by Leeizazombie
Can you please make me an example command? I'm mixing things up a bit :/
Re: Need help with some code to make a game
Posted:
10 Jul 2013, 18:20
by ismellike
Putting in Init won't work since Player p does not exist there.
You can try putting it in the Use and then make a command block for players to join.
Re: Need help with some code to make a game
Posted:
11 Jul 2013, 01:59
by Leeizazombie
Okay so when I used
- Code: Select all
using System;
namespace MCDzienny
{
public class CmdSurvive : Command
{
public override string name { get { return "survive"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
public override void Init()
{
p.Blockchange+=new Player.BlockchangeEventHandler(p_Blockchange);
}
//(below the public override use (Player p, string message))
void p_Blockchange(Player p, ushort x,ushort y, ushort z, byte type)
{
if(p.level.GetTile(x,y,z)==Block.redmushroom)
p.health+=5;
}
public override void Help(Player p)
{
Player.SendMessage(p, "/survive - Does stuff. Example command.");
}
}
}
It shows this
- Code: Select all
-------------------------
Error CS1002
Message: ; expected
Line: 12
so I added the ; to it like:
- Code: Select all
public override void Use(Player p, string message);
then it says
- Code: Select all
-------------------------
Error CS0501
Message: 'MCDzienny.CmdSurvive.Use(MCDzienny.Player, string)' must declare a body because it is not marked abstract, extern, or partial
Line: 12
When I remove line 12
- Code: Select all
-------------------------
Error CS0534
Message: 'MCDzienny.CmdSurvive' does not implement inherited abstract member 'MCDzienny.Command.Use(MCDzienny.Player, string)'
Line: 5
Like I saaid, im new at this