Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-01-12 19:27:40, last edited by Xrecion (2016-01-12 19:29:22)

Xrecion
Member
Joined: 2015-04-26
Posts: 16

How to do it that when someone will press SPACE...

How to do it that when someone will  press  SPACE my bot will _____ *HIM*  ?! ( - When bool == false -> my bot will ____ *HIM* ... )
So... how to do that my bot will know who have pressed space ?! >.<
I don't know to use int UserID :/ - pls explain this me :C

** Sorry for my English **

VZC2789.png

Offline

#2 2016-01-12 20:27:18, last edited by 912468 (2016-01-12 20:35:05)

912468
Member
Joined: 2015-02-21
Posts: 212
Website

Re: How to do it that when someone will press SPACE...

You can use the following code to know if someone pressed space:

private void onMessage(object sender, PlayerIOClient.Message m)
{
    if (m.Type == "m")
    {
        if (m.GetInt(4) == -52) //Player pressed space
        {
            //Do Something
        }
    }
}

The userID is a number you get when someone joins the world and you can use it to get there name. You can store these values in a dictionary:

public Dictionary<int, string> players = new Dictionary<int, string>();

You can add the ID and name of the player in the "add" message in onMessage:

private void onMessage(object sender, PlayerIOClient.Message m)
{
if (m.Type == "add")
{
    players.add(m.GetInt(0), m.GetString(1));    //This will add the ID and name of the player to the dictionary
}

if (m.Type == "m")
{
    string playerName = players[m.GetInt(0)]; //Use this to get the name of the player by his ID

    if (m.GetInt(4) == -52) //When the player pressed space
    {
        con.Send("say", "Hello, " + playerName);
    }
}

EDIT: You can watch this video if you want more information on how to get the username of a player. In this topic there are also some other great tutorials.


vF0MA5o.png

Offline

#3 2016-01-12 20:32:30, last edited by Tomahawk (2016-01-12 20:40:41)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

Re: How to do it that when someone will press SPACE...

Some of the packet types on Capasha's site are out of date. The "m" message is now:

  • [0] <Integer> UserID

  • [1] <Double> PlayerPosX

  • [2] <Double> PlayerPosY

  • [3] <Double> SpeedX

  • [4] <Double> SpeedY

  • [5] <Integer> ModifierX

  • [6] <Integer> ModifierY

  • [7] <Integer> Horizontal

  • [8] <Integer> Vertical

  • [9] <Integer> Coins

  • [10] <Boolean> SpaceDown

  • [11] <Boolean> SpaceJustDown

As its name suggests, m[11] tells you if the player has just pressed space. m[10] will be true if, for instance, a player is already holding space and then presses an arrow key.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#4 2016-01-12 20:42:12

Xrecion
Member
Joined: 2015-04-26
Posts: 16

Re: How to do it that when someone will press SPACE...

.

912468 Ty !! <3

Tomahawk - That's i know but i don't knew how using UserID and ... //forums.everybodyedits.com/img/smilies/big_smile But Thx !

Offline

#5 2016-01-12 20:49:57, last edited by XxAtillaxX (2016-01-12 20:54:28)

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: How to do it that when someone will press SPACE...

Tomahawk wrote:

Some of the packet types on Capasha's site are out of date. The "m" message is now:

  • [0] <Integer> UserID

  • [1] <Double> PlayerPosX

  • [2] <Double> PlayerPosY

  • [3] <Double> SpeedX

  • [4] <Double> SpeedY

  • [5] <Integer> ModifierX

  • [6] <Integer> ModifierY

  • [7] <Integer> Horizontal

  • [8] <Integer> Vertical

  • [9] <Integer> Coins

  • [10] <Boolean> SpaceDown

  • [11] <Boolean> SpaceJustDown

As its name suggests, m[11] tells you if the player has just pressed space. m[10] will be true if, for instance, a player is already holding space and then presses an arrow key.

No, it's actually:

  • [0] <Int32> UserId

  • [1] <Double> X

  • [2] <Double> Y

  • [3] <Double> SpeedX

  • [4] <Double> SpeedY

  • [5] <Double> ModifierX

  • [6] <Double> ModifierY

  • [7] <Int32> Horizontal

  • [8] <Int32> Vertical

  • [9] <Boolean> SpaceDown

  • [10] <Boolean> SpaceJustDown

Here's some code I just wrote up for it.

        static List<Player> Players;
        static void Main(string[] args)
        {
            var client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "guest", "guest", null);
            var con = client.Multiplayer.CreateJoinRoom("WorldId", "EverybodyEdits" + client.BigDB.Load("config", "config")["version"], true, null, null);

            con.OnMessage += delegate (object sender, Message m)
            {
                switch (m.Type)
                {
                    case "m":
                        if (!Players.Any(p => p.UserId == (int)m[0]))
                            break;

                        var jumping = ((double)m[4] != 0 && (bool)m[9]); // single jump: ((double)m[4] != 0 && false == ((bool)m[9] ^ (bool)m[10]));
                        var player = Players.First(p => p.UserId == (int)m[0]);
                        
                        Console.WriteLine($"{player.Username} is { ((jumping) ? "jumping" : "not jumping") }");
                        break;
                    case "add":
                        Players.Add(new Player() { UserId = (int)m[0], Username = (string)m[1] });
                        break;
                    case "init":
                        Players = new List<Player>();
                        con.Send("init2");
                        break;
                }
            };
            con.Send("init");

            Console.ReadLine();
        }
        class Player
        {
            public string Username { get; set; }
            public int UserId { get; set; }
        }

signature.png
*u stinky*

Offline

Wooted by:
XxAtillaxX1452628197575177

Board footer

Powered by FluxBB

[ Started around 1732751955.6394 - Generated in 0.112 seconds, 10 queries executed - Memory usage: 1.48 MiB (Peak: 1.62 MiB) ]