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.
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
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
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
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
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?
i use
Player bot = new Player(m.GetInt(13), BOT);
Players.Add(bot.Id, bot);
Offline
Okay, but i think i would better stay at my current static field.
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.
*u stinky*
Offline
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.
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 :\
Offline
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
I like it when a simple question receives advanced answers
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)
Very inactive, maybe in the future, idk.
Offline
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.
*u stinky*
Offline
Players[e.GetInt(0)].Username -- Get the players by e.GetInt(0) their ID
How to get their ID by their username?
▼Quoted postPlayers[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
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!
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 usernameProblem: Column supports only ids
; my 1,999 post!
I would use LINQ or a loop.
Offline
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
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
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
[ Started around 1732404634.7463 - Generated in 0.172 seconds, 12 queries executed - Memory usage: 1.83 MiB (Peak: 2.12 MiB) ]