if /else system

if /else system

Postby joppiesaus » 09 Oct 2012, 09:25

i have a little command, it´s called herobrine. if you do that, herobrine spawns on you location, you will be invincible for 7.5 sec (time to run away) and herobrine starts hunting people! awsome! :twisted: but everyone does that on the same moment, so the botset system will be completely overloaded! sooo, can anyone make a system with if / else?
it should be look like this:

Code: Select all
if Commanduse = true{
Player.SendlMessage("%4herobrine is already in this level!");
}
else { command continues}

i am really a begginner, in coding, (i am 13!) so thanks for the help.

current command:
Code: Select all
// Made by: joppiesaus!
using System;
using System.Threading;
using System.IO;
namespace MCDzienny
{
   public class CmdHerobrine : Command
   {
      public override string name { get { return "herobrine"; } }
      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)
      {
            Player.GlobalMessage("%4 m i´ omngic rfo oyu ");
            Thread.Sleep(1000);
            Player.GlobalMessage("%4oyu illw eb deda");
            Thread.Sleep(1000);
            Player.GlobalMessage("%4oyu illw verne tge em!");
            Command.all.Find("invincible").Use(p, "");
            Thread.Sleep(2000);
            Command.all.Find("botadd").Use(p, "Herobrine");
            Thread.Sleep(50);
            Command.all.Find("botset").Use(p, "Herobrine hunt");
            Command.all.Find("botset").Use(p, "Herobrine kill");
            Thread.Sleep(7900);
            Command.all.Find("invincible").Use(p, "");
            Thread.Sleep(120000);
            Command.all.Find("botremove").Use(p, "all");
      // Botremove all because if more people do this command, or the lava level changes, Herobrine will despawn.
        }
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/herobrine oyu iwll eb deda!");
      }
   }
}


Thank You ;)
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: if /else system

Postby dzienny » 11 Oct 2012, 16:46

1. Create a bool variable somewhere in the class body.
Code: Select all
public class CmdHerobrine : Command
   {
        volatile bool isHerobrineSpawned = false;

        // Class body
   }


2. Then check at the beginning of the "Use" method the current state of that variable.
Code: Select all
public override void Use(Player p, string message)
      {
          if (isHerobrineSpawned)
          {
                Player.SendMessage(p, "Herobrine is already spawned.");
                return;
          }
          isHerobrineSpawned = true;

          // Method body
      }


3. Finally add a code at the end of the "Use" method that sets the variable back to 'false'.
Code: Select all
public override void Use(Player p, string message)
      {
          // Method body

          isHerobrineSpawned = false;
      }


This way if someone tires to use this command when there is already Herobrine in the game, he will get the message: "Herobrine is already spawned".
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: if /else system

Postby joppiesaus » 11 Oct 2012, 20:16

dzienny wrote:1. Create a bool variable somewhere in the class body.
Code: Select all
public class CmdHerobrine : Command
   {
        volatile bool isHerobrineSpawned = false;

        // Class body
   }


2. Then check at the beginning of the "Use" method the current state of that variable.
Code: Select all
public override void Use(Player p, string message)
      {
          if (isHerobrineSpawned)
          {
                Player.SendMessage(p, "Herobrine is already spawned.");
                return;
          }
          isHerobrineSpawned = true;

          // Method body
      }


3. Finally add a code at the end of the "Use" method that sets the variable back to 'false'.
Code: Select all
public override void Use(Player p, string message)
      {
          // Method body

          isHerobrineSpawned = false;
      }


This way if someone tires to use this command when there is already Herobrine in the game, he will get the message: "Herobrine is already spawned".

thank you! you are awsome!
however, i can't code good. now it's clear to me! so thanks for the help! :)
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 5 guests

cron