IMPORTANT - PLEASE READ
I recently looked through part 1 and realised that I had missed out part of an event. I apologise for this completely - and for those of you who read part one, here is the completed event that needs editing. For an explanation on this event, look back at part 1. Really sorry for the trouble

+ MooClick: Player - On Message
+ P_OnMessage_GetSubchannel( MooClick ) = 0
+ Value A of Other Player = PCU_GetID( MooClick )
- String Parser: Set source string to P_OnMessage_GetText$( MooClick )
- Set X position of Other Player to Val( listGetAt$( String Parser, 1 ) )
- Set Y position of Other Player to Val( listGetAt$( String Parser, 2 ) )
- Set value B of other player to Val( listGetAt$( String Parser, 3 ) )
- Set value C of other player to Val( listGetAt$( String Parser, 4 ) )

Find the condition MooClick: Player - On Message which you made in part one, and add the last two events (set value B and C to elements 3 and 4). Shouldn't be a problem - although if you're still confused and can't find the above condition, post in the comments below. Thanks.

-----------------------------------------------

Introduction
This is part two of three articles which are aimed to help you at creating your first MooClick game. If you haven't read part 1 yet, then you must do so before reading this article - http://www.create-games.com/article.asp?id=1591

In part 1, we created a basic game which allowed us to send positions of objects and connect to a hosted server (as well as allowing yourself to host a server). In this article, we shall cover custom movements and things such as using the ID to identify different uses (e.g. nametags).


What do ya need?
Basically you'll just need the game you made in part 1, as we're going to finish it you see! As these articles are so long, its likely that I've made some mistakes - if so, just post them in the comments and I'll sort them out for you.


Custom Movement
If your making a game, it's VERY likely you will need movement. But, different movements can affect your game and cause lag if not coded efficiently. Here I'm going to tell you how to make a normal movement engine which has virtually no lag (every now and again players may jump depending on pings in server - that's normal). Oh, and this system was actually given to me by Phizzy - just thought I'd give him some credit.

In part one, you made some funky detectors for your player. Well Done! Firstly, we need to set the positions of the detectors to your player. I assume you know how to do this..

+ Always
- Set position of Up Detector to (0,-9) of Your Player
- Set position of Down detector...
- Set position of left detector...
- Set position of right detector...
- Make detectors invisible

Obviously the positions will vary to mind if you have different sized players .etc.

+ Repeat while left arrow is pressed
+ Left detector ISNT overlapping backdrop
- Set value A of Your Player to -1

+ Repeat while right arrow is pressed
+ Right detector ISNT overlapping backdrop
- Set value A of Your Player to 1

This will be more explainable later - but notice that Value A of your player covers the X directions. Therefore we'll use value B to cover our Y directions.

+ Repeat while up arrow is pressed
+ Up detector ISNT overlapping backdrop
- Set value B of Your Player to -1

+ Repeat while down arrow is pressed
+ Down detector ISNT overlapping backdrop
- Set value B of Your Player to 1

Now things may get a little confusing here on, I'll try to explain best I can though.

+ Your Player: Value A different to Value C
- Your Player: Set value C to Value A
- MooClick: Channel - Str$( X( Your Player ) ) + , + Str$( Y( Your Player ) ) + , + Str$( Alterable Value A( Your Player ) ) + , + Str$( Alterable Value B( Your Player ) ) on subchannel 0

Basically if Value A is different to Value C, then we send our positions. By default, Value C is 0 - therefore if we move left and right, Value A gets set to 1 or -1 - making it different to value C. If the values are different, then we send our positions and set value C to value A (so they are the same again). This is virtually a lag free system, as it only sends our positions when needed too. We also send alterable values A and B which show the players direction and position gap - if you remember, we set these to -1, 1 when pressing keys. If you read part 1, you will know that these are the 3rd and 4th elements - and when retrieved, they are set to values B and C of the other player (remember - value A is already being used for the other player's MOO ID).

+ Your Player: Value B different to Value D
- Your Player: Set value D to Value B
- MooClick: Channel - Send Str$( X( Your Player ) ) + , + Str$( Y( Your Player ) ) on subchannel 0

Exactly the same as above - but this time we use value B for Y positions, and compare it to value D. Hope I haven't confused you here.

+ Your Player: Value A different to 0
- Set x position to (X position) + Value A

+ Your Player: Value B different to 0
- Set Y position to (Y position) + Value B

If you press an arrow key, then values A and B set to 1 or -1, making them different to 0. If the values are 0, that means your not moving. This basically says that if values A or B are different to 0, then set X pos to A and Y Pos to B. Or, if your pressing a key, making your player move.

+ Other Player: Value B different to 0
- Set x position to (X position) + Value B

+ Other Player: Value C different to 0
- Set Y position to (Y position) + Value C

This basically makes the player move with almost no lag. If you remember, when a key is pressed - value A and B are set to either 1 or -1. We then send these via string parser (elements 3 and 4) and they a retrieved to another player and set to value B and C. Hope that makes sense, if not just ask me in the comments.


+ (NEGATE) Repeat while Left key is pressed
- Your Player: Set value A to 0

+ (NEGATE) Repeat while Right key is pressed
- Your Player: Set value A to 0

+ (NEGATE) Repeat while Up key is pressed
- Your Player: Set value B to 0

+ (NEGATE) Repeat while Down key is pressed
- Your Player: Set value B to 0

Basically, if the player is pressing no keys - don't make the player's object move. Remember, setting to 0 means the player doesn't move.


Phew - hard part over with..
That's basically your game coded. You must know though, that routers and firewalls can often block port 1203 - meaning you can host, but people cannot join your game. If you have this problem, use google to sort it out for you. You must allow Port 1203 TCP (maybe also 1203 UDP - but I don't think so). As you can tell, I also made a mistake in part 1 (see note above) and so it maybe likely there is a mistake in this one. If so, tell me in comments. Writing these articles is hard and my hands get tired - so sorry if there are mistakes!




Name Tags
This is actually very simple - and considering you understood everything above, I have no doubt that you will know/understand how to do this. Basically, we're going to use text blitter to display players name tags. We need to retrieve player's names when they join the game, or if they are already apart of the game.

+ Start of level
- Text Blitter: Destroy


+ Mooclick: User - On user joined
+ Value A of Other Player = PCU_GetID( MooClick )
- Create text blitter object
- Text blitter: Change text to PCU_GetName$( MooClick )


+ Mooclick: User - On user is here
+ Value A of Other Player = PCU_GetID( MooClick )
- Create text blitter object
- Text blitter: Change text to PCU_GetName$( MooClick )


Firstly we destroy all text blitter objects at start of level so they do not get in the way. Then, if a user joins, we compared value A to a player ID and then change the text blitter text to the name of the player with that ID. We then do exactly the same if a player is already here.


+ Text$( Text Blitter ) = PCU_GetName$( MooClick )
- Text blitter: Set position at (-24,-20) from Other Player


Basically, we compared the name of a player to the text of the text blitter object. If they are the same, then we position the text blitter to that player. You can use events to align the text blitter in order to align it in the correct position each time - but that does not involve MooClick, therefore I will not go over it.


+ MooClick: User - On user left
+ Value A of Other Player = PCU_GetID( MooClick )
+ Text$( Text Blitter ) = PCU_GetName$( MooClick )
- Text Blitter: Destroy

When a user leaves, we compare the player IDs and text blitter names and then destroy the text blitter object that is needed to be destroyed. (In other words, we destroy the text blitter object of the player which has left).


Challenge type thing!
If you have read both parts 1 and 2, you will know how to send data and messages across subchannels and such. If so, then you'll know it's rather easy! So as some kind of small challenge type thing, I want you to try and create a fully working chat system for your players. Online games would be rather boring without a chat afterall - you could also include things such as admin commands or player commands. Give it a go. If you struggle, do not worry - I will be covering chat systems and more in part 3. Part 3 will also be the final part - and there will be an example file available for you to download if you have any problems.


In Part 3
- Creating a fully functional chat system with commands
- Creating a lobby and server list using PHP and MySQL
- Saving and retrieving online scores for players using PHP and MySQL