Need help with some code to make a game

Need help with some code to make a game

Postby Leeizazombie » 10 Jul 2013, 15:02

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?
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Need help with some code to make a game

Postby ismellike » 10 Jul 2013, 15:25

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;
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Need help with some code to make a game

Postby Leeizazombie » 10 Jul 2013, 15:43

Ahh nice, it will take me some time :P thanks!
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Need help with some code to make a game

Postby Leeizazombie » 10 Jul 2013, 17:29

Can you please make me an example command? I'm mixing things up a bit :/
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Need help with some code to make a game

Postby Warren1001 » 10 Jul 2013, 18:15

Code: Select all
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;
}
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: Need help with some code to make a game

Postby ismellike » 10 Jul 2013, 18:20

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.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Need help with some code to make a game

Postby Leeizazombie » 11 Jul 2013, 01:59

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 :P
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.


Return to Help

Who is online

Users browsing this forum: No registered users and 7 guests

cron