Blitz3D Newbies: How to create your own WoW killer! Part 2
by Afr0

Aaaight guys! It's time for the second part of my wondrous tutorial;)



In this part, we are going to cover, as I told you, how to utilize the name and id fields of the player type properly.



First, we'll start out with our server code the way we left it:




The first thing we'll have to do is to make sure that all the proper player fields are filled out both at the client and the server side. We've already filled out the stream field at the serverside, but we also need to fill out the id and name fields. To do this, we'll read a string from the client stream. So after the line that goes "p\stream = strStream", add this:


The ReadString command takes, as you can see, only one parameter, which is the stream that the function is going to read from. Obviously though, we can't just read air, so we'll have to send a string containing the player's name from the client to the server. This will be taken care of later.

To fill out the id field of the player type on both the server and the client side, we'll have to make ourselves an id mechanism! :P To do this, stick this at the top of the server code:


and then stick this somewhere inside the "If strStream" check:


What this does is (obviously) to increase the number that is held by the id variable each time a new client joins. This will (with a little more work) allow us to identify our clients! :D

Now we will have to add this number to the playertype and send it to the client who just connected:


Now we are able to identify each player type by it's id, and by it's name if we want to, even though this is not reccomended, because strings take up a lot of space compared to ints when you send them through a wire. And now, on to the client side code;) This is what we have so far:


For now, we won't worry about the mainloop, but rather, about what's going to be ON TOP of the main loop;) For starters, let's include the types.bb files (if you haven't already, get your playertype out of your server code and place it in a separate file, while making sure to include the file in your server code) and create a new instance of the player type right after the "CreateClient("127.0.0.1",8080)" line:


Now you're probably wondering "Don't we need a nickname to send to the server?" And you are absolutely right;) So, after the stuff that you just added, add this:


This will display the string "Nickname: " to the player, and will then wait for input. Once the player has written his nickname and pressed enter, the nickname will be stored in the name$ variable. This will, obviously, enable us to send the name to the server and recieve our unique id:


That's it! This concludes this part of what will (as I have discovered) become a rather lengthy tutorial. Just to make sure that everything is proceeding correctly though, you can add this to the clientside code right after you've stored the player's name in the player type and have recieved the player's id:


Also, you can add this to the serverside code, somewhere in the "If strStream" check:


And you can add this after you've filled out the name and id fields:


In the next part of this too good to be true tutorial, we will cover the following: - How to create a dynamic messagehandling system in the server and the client.


For a printable copy of this article, please click HERE.


This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.