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.
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 **
Offline
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.
Offline
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
.
912468 Ty !! <3
Tomahawk - That's i know but i don't knew how using UserID and ... But Thx !
Offline
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; }
}
*u stinky*
Offline
[ Started around 1732438917.008 - Generated in 0.064 seconds, 13 queries executed - Memory usage: 1.49 MiB (Peak: 1.62 MiB) ]