Multiple Player Characters in... a complicated way...

Started by DoorKnobHandle, Thu 27/01/2005 11:36:23

Previous topic - Next topic

DoorKnobHandle

Hey guys,

i am working on a player/selection system that works like in classic stragetgy games (The Command&Conquer Series, StarCraft and tons of other famous games. What I mean by that is the following: I have two characters in my example, they represent two soldiers - SOLDIERA and SOLDIERB. Ok, now, SOLDIER is the player char from the beginning. when i do a right click it only moves the current player character. no trouble so far. but the other half with the left click is way harder.

This is my approach (in the onmouseclick function):

Code: ags

function on_mouse_click(int button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button==LEFT) 
  {
	
	SetCursorMode (0);
	int i = 0;

	  if (GetCursorMode () == 0) 
	  {
	    if (GetCharacterAt (mouse.x, mouse.y) != -1)
	    {
		Display ("LEFT MOUSE BUTTON CLICKED ON A CHARACTER...");
		if (mouse.x < character[i].x && mouse.x > (character[i].x + 18) && 
			mouse.y > (character[i].y + 14) && mouse.y < (character[i].y - 11) && 
			i <= (NUM_CHARS - 1))
		{
			  i = i + 1;
		}
		else 
		{
			SetPlayerCharacter (i);
			
		}
	     }
	
	
	   }
	
  }
  else
  {
	MoveCharacter (GetPlayerCharacter (), mouse.x, mouse.y );
  }
}



What happens with this piece of code is that I can move my player char SOLDIERA allright, when I click on a player and only if I hit a actual player (SOLDIERA or SOLDIERB), the debug displaymessage comes up correctly, but nomatter what player I hit it always says in the console: New Player Character: Character 0 (That is Character A). So I cannot really switch.

Anybody any adwise or something? Anybody ever did this before?

Thanks for reading all this.

Simonsez128

Hi

So if I understand you correctly you wanna change the player character to another character you click on? That shouldn't be too complicated to accomplish. You could easily do this with running a script when interacting with a character you set up. It would just require a SetPlayerCharacter command like in your script.

The problem with your script is probably that you increase i only if you click beside a character. Is that correct? If so, then you contradict your previous if-statement. Why don't you just set i to GetPlayerAt (mouse.x, mouse.y);  and then call SetPlayerCharacter(i); ?

That would be the easiest solution I can think of if I am understanding what you want to accomplish.

So long.

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

DoorKnobHandle

#2
Thank you so much, thats true. man I was just to tired to have thought of that on myown.

I just saw that COmmando game in the game announcement area and that is honestly almost exactly what I wanted to do... well anyways. its prolly gonna turn out different anyways.


!!! EDIT: !!!

I still have problems with it. I dont want to do that running script for every character because I am planning on using a bigger amount of controllable characters.

Now I got it so far that you can change perfectly to SOLDIERB but then you cant go back for some reason!?!

Heres my version now:

Code: ags

else if (button==LEFT) 
Ã,  {
	i = 1;
	

	Ã,  if (GetCursorMode () == 0) 	// IF LEFT CLICK...
	Ã,  {
	Ã,  Ã,  if (GetCharacterAt (mouse.x, mouse.y) != -1) // IF OVER A CHARACTER...
	Ã,  Ã,  {
		while (i <= NUM_CHARS) // WHILE I IS SMALLER OR THE NUMBER OF CHARACTERS TOTAL...
		{
			if (mouse.x > character[i].x && mouse.x < (character[i].x + 18) &&	
			Ã,  Ã,  mouse.y < character[i].y && mouse.y > (character[i].y - 25)) 	
			{
				
				SetPlayerCharacter (i);
				// update selector sprite
				FollowCharacterEx (SELECTOR, GetPlayerCharacter(), FOLLOW_EXACTLY, 1);
				i = 1;
			}
			else 						
			{ 
				i = i + 1;				
				if ( i == NUM_CHARS + 1 )
				{
					
				}
			}
		}

	Ã,  Ã,  Ã, }
	 
	
	}
	 
	
Ã,  }




Man I really thought this would be easier. The hard part is that I try to keep it still usable for the use with more than two or three or five guys...

I'd appreciate any more help!







EDIT:

I finally solved... that took me 5 hours or so... wow I thought Id be easy but no way.
I can post the solution her eif someones interested...

SMF spam blocked by CleanTalk