Local - Functions
Create a debug log for a better overview
Before we start going into multiplayer i recommend to create a debug log where you can show all kinds of messages to keep an overview of what happens in your game.
To do this create a new project add a TextBox object place it in your layout and set it's type to Textarea.
Create a Function object, go to your Event sheet and add a new event. Pick the Function object from the list and add a On function event. Name it "Debug". Now create a new action inside of it. Pick the TextBox object and add it's Set text action. Into the textline enter the following: trim(Self.Text & newline & Function.Param(0)). That adds new text below the existing one in the textbox. Finally add a Scroll to bottom action. Your event should look like this.
Create a "CreatePlayer" function
We create a general function to create a player object according to the programming law "don't repeat yourself". For this add a new On function event and call it "CreatePlayer". This function receives 5 values. The gotoX, gotoY, shootX and shootY positions and the Players unique id (ActorNr). First we add the Systems Create Object action, add the Player and set as X-Position Function.Param(0) which simply grabs the first value in the parameter list given to this function. For Y use Function.Param(1). Next set player objects instance variable values. We wanna set the shootX and shootY values. Those can be found in the Parameter list at position 2 and 3. Go ahead and set these values now. Now we want to set our id for the player object. This is also an instance variable so do the same as before but use position 4 from the Parameter list.
When the player object is created we can simply set our gotoX and gotoY to the actual position of the object by using Self.X and Self.Y. Finally to differ our local player from the others we want to colorize our player to pink. Our player object consists of two different frames. First = black color, Second = pink color. Depending on if the given unique id in the parameter equals our local id we set the color to pink otherwise to black. For this we use this expression: Player.id = Photon.MyActorNr ? 1 : 0
Create a "ResetRound" function
This function is really simple. We simply reset our global variables here, clear the WalkShootDictionary and remove all marker objects to allow the player to set new positions again.
Done! We are ready to start through and get right into creating the next gen mmor.. wait. Let's keep it simple for now ;)