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.

#26 2016-11-28 18:46:28, last edited by drunkbnu (2016-11-28 18:49:44)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: case "add": not called when someone joins

You can get the username of the bot at e[13] when receiving "init". Add a static string outside the class.

static string botname;

Then, when receiving init, set the value of the string to the string received at e[13].

case "init":
  botname = e[13];

Offline

#27 2016-11-28 19:04:35, last edited by capasha (2016-11-28 19:05:02)

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: case "add": not called when someone joins

HG wrote:

You can get the username of the bot at e[13] when receiving "init". Add a static string outside the class.

static string botname;

Then, when receiving init, set the value of the string to the string received at e[13].

case "init":
  botname = e[13];

He should know how to add the bot username to a variable. If not, this thread will end in learning him the basics of C# and spoon feeding.

Offline

#28 2016-11-28 19:39:59, last edited by drunkbnu (2016-11-28 19:51:01)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: case "add": not called when someone joins

MartenM wrote:

https://youtu.be/ULP_XkNciaw

Made this vid a while back but this way you can get someone's name too. I have done it like this for a whole time and I would suggest doing the same if you do not know what a class is.
Basically the dictionary links the playerID and username so you can grab it later on.

An array is way easier.

static string[] players = new string[0];
case "add":
  int id = e[0];
  if (id < players.Length) Array.Resize (ref players, id + 200);
  players[id] = e[1];
  break;

Offline

#29 2016-11-28 23:18:32

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: case "add": not called when someone joins

AnatolyEE wrote:

The bot itself is only getting a username via "init". In my case how do I add the bot acount to the list?

Didn't you just say the answer yourself?
Instead of adding the bot through the "add" message, add him with the data you got in the "init" message!

Offline

#30 2016-11-29 15:37:59

Anatoly
Guest

Re: case "add": not called when someone joins

HG wrote:

You can get the username of the bot at e[13] when receiving "init". Add a static string outside the class.

static string botname;

Then, when receiving init, set the value of the string to the string received at e[13].

case "init":
  botname = e[13];

Before reading thsi i had static int BotId; doesn't matter: Why can't I just put the bot as a player in the table?

#31 2016-11-29 15:47:25

Gosha
Member
From: Russia
Joined: 2015-03-15
Posts: 6,211

Re: case "add": not called when someone joins

i use

 Player bot = new Player(m.GetInt(13), BOT);
                Players.Add(bot.Id, bot);

Offline

#32 2016-11-29 16:04:59

Anatoly
Guest

Re: case "add": not called when someone joins

Okay, but i think i would better stay at my current static field.

#33 2016-11-29 20:19:03, last edited by XxAtillaxX (2016-11-29 20:19:18)

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

Re: case "add": not called when someone joins

I spy with my little eye, a bunch of low-quality code.

This is the template I currently use, as I'm far too lazy to write a fairly simplistic bot manually every time.
I've added in a few comments because it's generally good practice when publishing code.

Template (C# 7)

signature.png
*u stinky*

Offline

Wooted by:

#34 2016-11-30 02:41:37, last edited by John (2016-11-30 02:42:38)

John
Member
Joined: 2019-01-11
Posts: 2,009

Re: case "add": not called when someone joins

ninjasupeatsninja wrote:
Emalton wrote:

<snip>

ok thank you for your explanation but dont reinvent wheels

string WorldID = "World-ID-Here";
con = client.Multiplayer.CreateJoinRoom((WorldID.ToLower().StartsWith("ow") ? WorldID.Replace("-", "") : WorldID), (WorldID.ToLower().StartsWith("bw") ? "Beta" : "Everybodyedits" ) + client.BigDB.Load("config", "config")["version"], true, null, null);

very good code that still works

I was not aware this was a pising contest; I was only trying to make it as simple as possible for one who is new to programming to understand.

You posting a line of code and not explaining it is just stupid. When you were new to programming, people on these forums explained things to you, they didn't just post massive lines of code for you to decipher. Trust me, you've asked a l o t of questions. Why do you think that's okay to do the same?

You should explain your stuff in vivid detail otherwise, you shouldn't be a teacher.

"just do this" is now how one teaches effectively.

Next time, explain yourself.



XxAtillaxX wrote:

I spy with my little eye, a bunch of low-quality code.
<snip>

I thought we're trying to help the OP, not one-up

--

I encourage everyone who will contribute to helping others, to not spoonfeed code. Help threads shouldn't be a pising contest. Write code that suits who's it should be going to.

Sure Ninja's line could be useful for more experienced programmers, but for the OP it probably looks like:

EnCt20fa1f0522398465830822c4fecc35181dfa4e6940fa1f0522398465830822c4fgTzafyqWqAJ
sPLwtPlh/R3Q+/lEw56RmHi2KegoAe4YnE1zq+i+SrSbAmoDRYKVOirtIjOJg6Y3w0ciexKCpDwKp/Ei
Yfeo/LkGayyGez3pUbCv6ESdURJ4M28hXjtFPtusXwS6ItZRDrWx/jfwqPFRn+dcEqAIy8mPlx1tauKR
41QUacZVO8nsLba65fCd0Dud21Hyaz3Y9jYB08AvElT5qiv81V/n880SAPOmF9gAqPDfzQixi1np6nLc
B7rHw1NWwNp3rFOLkQY9ywWKheKAl7Z8Km8lBIHRDaITVbZlf8L3ZIe9Pw6pqkTSZotafhlO0RiMvddr
IO25AfYLpSRG47Kes2lFdKWtiSbsMwB6JCnB0FEFv2aQQXaVgf6U09Ykx+6ocjboeluA=IwEmS

encipher.it (KEY: Emalton)



TL;DR:

  • Don't post random line of code without explaining it.

  • This shouldn't be a pising contest.

  • Try to write code so newbies can understand (if applicable)

EDIT: Word Filter :\


PW?scale=2

Offline

#35 2016-11-30 05:16:52, last edited by SirJosh3917 (2016-11-30 05:25:10)

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: case "add": not called when someone joins

oh wow i see that i got some hate uhh ok i guess ill explain it or whatever in "great depths"

string WorldID = "World-ID-Here";
con = client.Multiplayer.CreateJoinRoom((WorldID.ToLower().StartsWith("ow") ? WorldID.Replace("-", " ") : WorldID), (WorldID.ToLower().StartsWith("bw") ? "Beta" : "Everybodyedits" ) + client.BigDB.Load("config", "config")["version"], true, null, null);

This code may be confusing at first, but I'll explain it in great depths unto you.

First, we define a string called WorldID. This is so we can modify and play around with the stringm which would be the World ID.
Please keep note that the WorldID must be a valid level ID, so therefore it must start with "PW", "BW", or "OW", respectively representing a Player World, Beta World, or an Open World make OW gr8 again. Now let's start off by explaining everything bit by bit - in a literal term.

con =

con is supposed to be your variable with it's type defined as a Connection. A connection is essentially a TCP connection to one of PlayerIO's servers nearest to you. This TCP connection can send packets of data, of which PlayerIO will take in your ints and doubles and longs and strings that you throw at it, and compress it into a microscopic size, and send them over. By compressing your data, it effectively sends less bytes, which would be suitable for a 300KB/ps download speed like mine. Every byte counts!

In this piece of code, we are assigning connection to something on the right that will return a Connection, or a Connection constructor. However, the Connection class has no constructors, so therefore we must use a function so that it returns unto us a pointer to a connection stored in memory, of which that pointer will lead us to the Connection that is connected to one of PlayerIO's servers.

client.Multiplayer.CreateJoinRoom

This piece of code assumes you have a Client variable declared, and as the same with Connection, has no valid constructor, which must be accessed by the PlayerIO.Something.I.Forgot method. This client should be validated with a valid client, otherwise PlayerIO will throw it's famous PlayerIOError at your face.

PlayerIO has an internal Multiplayer class of which you can never define in your code, however the Client class has one of these, contained within a { get; set; } ( or maybe just a { get; private set; } i don't know ). This will access the Multiplayer class, and within the Multiplayer class there is a function called CreateJoinRoom which returns a Connection for us to set a pointer to for our Connection con variable. Now let's look more in depth at what happens to the parameters that we specify into it, what the function will do.

(WorldID.ToLower().StartsWith("ow") ? WorldID.Replace("-", " ") : WorldID)

This is taking WorldID, and making it all in lowers. This is so that if the user inputs "OWAA-HI-THERE", it will get turned into "owaa-hi-there", but only for the short instance that we use this lowered form of WorldId. Next we check if it StartsWith("ow"). Since the string is in it's lowered form, we will check if it equals "ow" to see if it's an Open World. Now we specify an odd ? mark in the middle. This is so we can declare a quick if statement on the fly, and use the correct form of the string on the fly. If the string starts with "ow", it will replace all  "-" with ""... wait... oh **** i coded everything wrong wow i suck gg life *suicides*... Ok I'll just correct all instances that i use "-" to "" in...
Anyways, it will replace all "-" to " ", and this is because if you use the button on the left hand corner of the screen, it will add dashes ( - ) in the World ID so it can be used in HTML links. However, the actual World ID does not use dashes, and it uses space.
Now if the world ID doesn't start with "ow", it will just use the regular World ID, no formatting needed.

(WorldID.ToLower().StartsWith("bw") ? "Beta" : "Everybodyedits" ) + client.BigDB.Load("config", "config")["version"]

Let me just explain that... like this

if (WorldID.ToLower().StartsWith("bw")) {
return "Beta";
} else {
return "Everybodyedits";
}

That's the first part. What it does is check if the World ID starts with bw, and if it does, return "Beta". Otherwise, it'll return "Everybodyedits". Next, we concat the string we got with the current version of EE.
client.BigDB is again, another class that we cannot construct but client has a {get; private set;} (?) thing in it. And within the BigDB it has a Load function, which loads a database, and then loads a table from the database. In this case, we load the database "client" and then load the table "client". This will return a dictionary<string, string> to us. Within that dictionary, there is a key called "version", which will return a string verison of EE's current version - in this case 217. Then we will combine that all together, to get a grand total of "Everybodyedits217".

After that we use some null values and the integer 0, because we don't care about those - not one bit.

~there ya happy
~sorry if i sound smart with "pointers" and "this is a variable" meh.
~also P.S. i'll put some more optimized code below to fit it on one line, and faster and what not.
~p.s.p.s. heres ur optimized code or whatever

string WorldID = "PWexample"; string _opt; con = client.Multiplayer.CreateJoinRoom( ( (_opt = WorldID.ToUpper()).StartsWith("OW") ? WorldID.Replace("-", " ") ), ( _opt.StartsWith("BW") ? "Beta" : "Everybodyedits" ) + client.BigDB.Load("config", "config")["version"], true, null, null);

Offline

#36 2016-11-30 06:33:20

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: case "add": not called when someone joins

I like it when a simple question receives advanced answers


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

Wooted by:

#37 2016-11-30 11:00:04

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

Re: case "add": not called when someone joins

Vinyl Melody wrote:

I like it when a simple question receives advanced answers

Well, it's not like there's much else to discuss other than sending init2 after sending init, might as well turn it into a contest.


signature.png
*u stinky*

Offline

Wooted by:

#38 2016-11-30 17:39:50

Anatoly
Guest

Re: case "add": not called when someone joins

Quoted post

Players[e.GetInt(0)].Username -- Get the players by e.GetInt(0) their ID

How to get their ID by their username?

#39 2016-11-30 17:47:12, last edited by capasha (2016-11-30 17:52:02)

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: case "add": not called when someone joins

AnatolyEE wrote:
Quoted post

Players[e.GetInt(0)].Username -- Get the players by e.GetInt(0) their ID

How to get their ID by their username?

Serious. I don't understand what you mean.
Do you want to get their userid from the nickname? Why would anyone want that. When the most features using userid to read from.

Anyway. Isn't this thread about "case add"? Change title to "i want help with bot programming" or something else.

Offline

#40 2016-12-01 18:25:40, last edited by Anatoly (2016-12-01 18:26:26)

Anatoly
Guest

Re: case "add": not called when someone joins

capasha wrote:

Serious. I don't understand what you mean.
Do you want to get their userid from the nickname? Why would anyone want that. When the most features using userid to read from.

You have Players[ID].Username (receive ID)
I want Players[Username].Rank = changed by username

Problem: Column supports only ids



; my 1,999 post!

#41 2016-12-01 19:42:07

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: case "add": not called when someone joins

AnatolyEE wrote:
capasha wrote:

Serious. I don't understand what you mean.
Do you want to get their userid from the nickname? Why would anyone want that. When the most features using userid to read from.

You have Players[ID].Username (receive ID)
I want Players[Username].Rank = changed by username

Problem: Column supports only ids



; my 1,999 post!

I would use LINQ or a loop.

Offline

#42 2016-12-02 13:59:48, last edited by Anatoly (2016-12-02 14:03:28)

Anatoly
Guest

Re: case "add": not called when someone joins

capasha wrote:

I would use LINQ or a loop.

I have decided to take a loop, but found, that a loop can't use a dictionary. How to use it elseways?

//Code sniplet where i get errors
int selectedUser;
foreach(int n in Players) {
	if (Players[n].Username == arg[1]) {
		selectedUser = n;
		
		Console.ForegroundColor = ConsoleColor.DarkCyan;
		Console.WriteLine("[SYSTEM] " + Players[e.GetInt(0)].Username + selectedUser +  "changed rank from " + arg[1] + " to " + arg[2]);
	};
};

(Edit:) Error:

/home/anatoly/EE/DeathMark/DeathMark/Program.cs(24,24): Error CS0030: Cannot convert type `System.Collections.Generic.KeyValuePair<int,DeathMark.Player>' to `int' (CS0030) (DeathMark)

There error is in the "int"??





(Edit:) 2003 Post count - the year im born

#43 2016-12-02 16:52:39

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: case "add": not called when someone joins

AnatolyEE wrote:
capasha wrote:

I would use LINQ or a loop.

I have decided to take a loop, but found, that a loop can't use a dictionary. How to use it elseways?

//Code sniplet where i get errors
int selectedUser;
foreach(int n in Players) {
	if (Players[n].Username == arg[1]) {
		selectedUser = n;
		
		Console.ForegroundColor = ConsoleColor.DarkCyan;
		Console.WriteLine("[SYSTEM] " + Players[e.GetInt(0)].Username + selectedUser +  "changed rank from " + arg[1] + " to " + arg[2]);
	};
};

(Edit:) Error:

/home/anatoly/EE/DeathMark/DeathMark/Program.cs(24,24): Error CS0030: Cannot convert type `System.Collections.Generic.KeyValuePair<int,DeathMark.Player>' to `int' (CS0030) (DeathMark)

There error is in the "int"??





(Edit:) 2003 Post count - the year im born

If you read the error or using google you would understand.

            string user = "username";
            foreach(KeyValuePair<int,Player> p in Players)
            {
                if (p.Value.username == user)
                {
                    Console.WriteLine(p.Value.rank);
                    break;
                }
            }

Offline

#44 2016-12-02 17:10:43

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

Re: case "add": not called when someone joins

This is no longer about bot programming.

You can find the answer to pretty much anything C# on Stack Overflow, DotNetPerls or MSDN.

It doesn't help that everyone starts debating any code that gets posted.


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

Offline

Tomahawk1480695043637978

Board footer

Powered by FluxBB

[ Started around 1732412545.9562 - Generated in 0.155 seconds, 12 queries executed - Memory usage: 1.83 MiB (Peak: 2.12 MiB) ]