right-click cancelling

Started by gonzalezj, Wed 11/06/2003 19:45:58

Previous topic - Next topic

gonzalezj

Ok, here is my dilemma. I want to be able to cancel a character's action while they are in mid-action.

For example: A character moves towards an object with the intent of picking up the object. I want the ability to Right-Click as they are moving towards the object and make them stop moving and wait for further instruction.

It sounds easy, but I am using a MoveCharacterBlocking command which disables control to the script until the character arrives at their intended destination.

Could this be an impossible idea?

Thanks for the help guys!  :)

Scorpiorus

#1
Ah, I see what you mean. If canceling moving is the only thing you need then I would suggest the next function:


//Global script:

function BeginInteraction(int x, int y) {
 
 int PC = GetPlayerCharacter();
 MoveCharacterDirect(PC, x, y);
 while (character[PC].walking) {
   if (IsButtonDown(RIGHT)) {
     StopMoving(PC);
     return 0;
   }
   Wait(1);
 }
 return 1;
 
}


//Script header

import function BeginInteraction(int x, int y);




Now what it does:
It starts the player character to move towards the point you have specified. This position is the object co-ordinates for example. The function is blocking and it works almost like MoveCharacterBlocking() to the exclusion of that if you will press right mouse button the character stops moving. In that case the function returns 0. It returns 1 provided the character reached his destination successfully.

Now how to use it:
So you have a key. Let's pick it up. We are clicking Interaction... on objects panel and moving to the Interaction editor. Now choosing Interact object, Run Script option, edit script...

Suppose a key is the object number 0....
It's time to involve BeginInteraction() thingy.

 // script for object0: Interact object

int done; // this variable stores a value returned by BeginInteraction()

done = BeginInteraction(GetObjectX(0), GetObjectY(0)); // start moving towards to the key;

if (done == 1) {
//If interaction was not canceled (by right click)

ObjectOff(0); // remove the key from room
AddInventory(1); // add key to the inventory

}



Actuall you may do not declare done variable at all:

Example:
 // script for object0: Interact object

if (BeginInteraction(GetObjectX(0), GetObjectY(0)) == 1) { // start moving towards to the key;
//If interaction was not canceled (by right click)

ObjectOff(0); // remove the key from room
AddInventory(1); // add key to the inventory

}



Hope this helps ;)

-Cheers

gonzalezj

Appreciate the help. I modified it to suit my needs and it works perfectly.

Thanks again!

SMF spam blocked by CleanTalk