Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using PlayerIOClient;
- using System.Threading;
- using EEPhysics;
- namespace !NAMESPACE_NAME!
- {
- public class Player
- {
- public int ID { get; private set; }
- public string Name { get; private set; }
- public PhysicsPlayer Physics { get { return Program.physicsWorld.Players[ID]; } }
- public double X { get { return Physics.X; } }
- public double Y { get { return Physics.Y; } }
- public bool GodMode { get { return Physics.InGodMode; } }
- public int Coins { get { return Physics.Coins; } }
- public int BlueCoins { get { return Physics.BlueCoins; } }
- public Player(int id, string name)
- {
- ID = id;
- Name = name;
- }
- }
- public class Program
- {
- public static Client client;
- public static Connection conn;
- public static PhysicsWorld physicsWorld = new PhysicsWorld();
- public static Dictionary<int, Player> players = new Dictionary<int, Player>();
- public static int botID;
- public static bool finished = false;
- static void Main(string[] args)
- {
- client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "email", "password");
- conn = client.Multiplayer.JoinRoom("World ID", null);
- conn.OnMessage += onMessage;
- conn.OnDisconnect += delegate(object o, string reason) { };
- conn.Send("init");
- while (!finished)
- Thread.Sleep(1);
- #region Example code
- // Will track random player's x and y with background blocks and detect when it hits to dots.
- Thread.Sleep(2500); // Wait a bit for add messages.
- int randomId;
- int[] ids = players.Keys.ToArray();
- // prefer other players than the bot itself
- if (ids.Length > 1)
- {
- int r = new Random().Next(players.Keys.Count - 1);
- randomId = ids[r];
- if (ids[r] == botID)
- randomId = ids[r + 1];
- }
- else
- randomId = ids[0];
- if (randomId != botID)
- Console.WriteLine("Tracking " + players[randomId].Name);
- else
- Console.WriteLine("Tracking the bot itself");
- players[randomId].Physics.AddBlockEvent(4, delegate(PlayerEventArgs e)
- {
- Console.WriteLine("# " + e.Player.Name + " hit blockID 4 (gravity dot) at [" + e.BlockX + ", " + e.BlockY + "]!");
- });
- while (players.ContainsKey(randomId))
- {
- Player player = players[randomId];
- conn.Send(physicsWorld.WorldKey, 1, (int)Math.Round(player.X / 16), (int)Math.Round(player.Y / 16), 505);
- Thread.Sleep(35);
- }
- #endregion
- }
- public static void onMessage(object o, Message m)
- {
- physicsWorld.HandleMessage(m);
- switch (m.Type)
- {
- case "init":
- {
- Player bot = new Player(m.GetInt(6), m.GetString(12));
- players.Add(bot.ID, bot);
- botID = bot.ID;
- conn.Send("init2");
- finished = true;
- }
- break;
- case "add":
- {
- Player p = new Player(m.GetInt(0), m.GetString(1));
- players.Add(p.ID, p);
- }
- break;
- case "left":
- {
- if (players.ContainsKey(m.GetInt(0)))
- {
- players.Remove(m.GetInt(0));
- }
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement