/shake (freeze effect)

/shake (freeze effect)

Postby Clowny » 16 Jul 2013, 01:23

Alright so here is the code I have so far for something that creates sort of a shaking movement however the freeze and unfreeze global message is ruining it and I'm pretty sure there is a way to make that silent... if there is how?
Code: Select all
//By Clowny
using System;
using System.Threading;

namespace MCDzienny
{
   public class CmdTest : Command
   {
      public override string name { get { return "shake"; } }
      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)
        {
            if (String.IsNullOrEmpty(message) || message.IndexOf(' ') != -1) { Help(p); return; }
            Player who = Player.Find(message);
            if (who == null || who.hidden)
            {
                Player.SendMessage(p, "Player could not be found.");
                return;
            }
            {
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
                Command.all.Find("freeze").Use(null, who.PublicName);
                Thread.Sleep(500);
            }
        }

      // This one controls what happens when you use /help [commandname].
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/shake ");
      }
   }
}
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /shake (freeze effect)

Postby Conor » 16 Jul 2013, 01:34

You can't take the messages out as you're directly using the /freeze command.

You can just change the Player.frozen variable instead, this should have the same affect and not require a global message.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /shake (freeze effect)

Postby Clowny » 16 Jul 2013, 01:51

So how would that look? Instead of:
Command.all.Find("freeze").Use(null, who.PublicName);

Player.Frozen.Use(null, who.PublicName);..?
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /shake (freeze effect)

Postby Conor » 16 Jul 2013, 01:56

Code: Select all
public override void Use(Player p, string message)
{
   // First find Player who and check rank...

   for (int i = 0; i < 10; i++)
   {
       who.frozen = !who.frozen;
       Thread.Sleep(500);
   }
   who.frozen = false;
}
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /shake (freeze effect)

Postby Clowny » 16 Jul 2013, 02:15

alright thank now could you give me an explanation behind this I haven't really learned it yet;
for (int i = 0; i < 10; i++)
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /shake (freeze effect)

Postby ismellike » 16 Jul 2013, 02:35

Clowny wrote:alright thank now could you give me an explanation behind this I haven't really learned it yet;
for (int i = 0; i < 10; i++)


This is pretty much math, so you can read it like a math problem.

for a number i that is equal to 0, i is less than 10, go up 1 for as long as you can and do what is on the inside.

0<10 yup
1<10 yup
3<10
4<10
5<10
6<10 etc
9<10
10 is not less than 10, it stops here

So the inside of the code would happen 9 times
If you wanted to include 10, you would change the less than symbol, <, to the less than or equal to symbol, <=
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /shake (freeze effect)

Postby Clowny » 16 Jul 2013, 02:49

Ooohh I see i is simply like a variable.. alright and is there an explanation for the i++ at the end
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /shake (freeze effect)

Postby Conor » 18 Jul 2013, 03:08

i++ means the 'loop counter' is increasing by one every time. As Ismellike said, it goes up by one each iteration, so the loop happens until i is less than 10. The loop actually occurs 10 times, not 9, as 0 is the first loop.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /shake (freeze effect)

Postby Clowny » 18 Jul 2013, 03:49

hmm alright I see well thanks for the help!
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 5 guests