help with implementing a two command only system

Started by , Thu 15/05/2003 03:43:33

Previous topic - Next topic

Kejoxen

its baking my head trying to think of the exact wording that i want. but basically i want to implement the command system used by revolution software for bass and broken sword, you know left click to look right click to pick up and or use, i know its scripting but i cant think where to start.

cornjob

It's very simple. First back up your game in case you screw it up. Then go to your global script. Find the function called "on_mouse_click". Remove (or comment out) everything inside the function brackets and replace with:

if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
 }
else if (button==LEFT) {ProcessClick(mouse.x, mouse.y, MODE_LOOK);}
else if (button==RIGHT) {ProcessClick(mouse.x, mouse.y, MODE_USE);}

That should work. The just make sure you only use use and look interactions. Let me know if this doesn't work.

Kejoxen

its seems like a good start but i cant get the character to walk to a null point in the room, just wander around basically. also i dont know how to assign a simple arrow cursor instead of the sierra ones the cursor menu gives no option for that, it doesnt seem clear how the cursor are assigned at all.  

kejoxen

ok i know what i mean.

basically i want to have a the player right click on an area if its an object that can be used it will be used, so say a tv in a room the player will turn it on, if the left click they will look at the object, ie "its a tv, 157 channels and nothing on" ok, if the object/hotspot cannot be used then the character will walk to that area unless obvisouly if its not in a walkable area.

the same will go for the inventory so by right clicking on an inventory item that item will be selected for use within the room, left clicking will get a description.

is there a list of scrpiting commands anywhere? if i had a look at the options i might be able to work it out by myself.  

Gilbert

Yes, you may look at the manual, there is a section called "Text script functions" dedicated to the text script functions. Of course, you may also check out the relating info/tutorial parts of things you want to know (GUI, interactions, etc).

cornjob

Oh yeah, I forgot about walking. You could use the unhandled_event function to run a ProcessClick(mouse.x, mouse.y, MODE_WALK) when the player clicks in use mode on either a) nothing or b) a hotspot with no use interaction. You'll have to look in the manual to figure out how to use unhandled_event.
As for changing the cursor to an arrow, just change the cursor graphic. It no longer matters what cursor mode you're in, so you can use any one. And yes, definitely read the manual. Good luck.

kejoxen

thanks for the help guys i am almost there, i still have a few problems, yes i have read the manual but i only started this thing two days ago so you cant expect me to pick everything up at once, and if you didnt want to help me you wouldnt check this forum right?

the relevant piece of script looks like this now.

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) {ProcessClick(mouse.x, mouse.y, MODE_LOOK);}
   
   else if (button==RIGHT) {ProcessClick(mouse.x, mouse.y, MODE_USE);}

 }

function unhandled_event(int button) {
   if (IsGamePaused() ==1) {}
   
   
   else if (button==RIGHT) {ProcessClick(mouse.x, mouse.y, MODE_WALK);}


the help file says that unhandled_event will not work if the player clicks on nothing so i set up my walkable area as a hotspot as well with no interactions but this made no difference. what happens is that the character will walk to an item that is clicked on but not walk about inside a hotspot, also i am unable to selected item from the inventory to use in the room i tried setting un an unhandled_event for the left button using MODE_USEINV but this just caused my game to crash any ideas on what direction to go would be great.

Scorpiorus

Quotei still have a few problems, yes i have read the manual but i only started this thing two days ago so you cant expect me to pick everything up at once
The best way to study is just to keep trying. ;)

Quote
function unhandled_event(int button) {
  if (IsGamePaused() ==1) {}
 
 
  else if (button==RIGHT) {ProcessClick(mouse.x, mouse.y, MODE_WALK);}
Such function won't work because it has to has two parameters: unhandled_event(int what, int type).
And the first parameter doesn't represent a button. See manual for details.


Ok, now to your problem.
Quotebasically i want to have a the player right click on an area if its an object that can be used it will be used, so say a tv in a room the player will turn it on, if the left click they will look at the object, ie "its a tv, 157 channels and nothing on" ok, if the object/hotspot cannot be used then the character will walk to that area unless obvisouly if its not in a walkable area.
Actually to implement it you do not need unhandled_event() function. To accomplish this you have to write a special process click function instead:

//Global script:

function ProcessClickSpecial(int x, int y, int cursor_mode, int default_mode) {
  if (IsInteractionAvailable(x, y, cursor_mode)) ProcessClick(x, y, cursor_mode);
  else ProcessClick(x, y, default_mode);
}

What does it do? When you call it it checks whether the interaction at specified co-ordinates is available. If it is then it process with cursor_mode, if not then with default_mode.

The function is ready and all we need now is to tune on_mouse_click() one:

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) {
    ProcessClickSpecial(mouse.x, mouse.y, MODE_LOOK, MODE_WALK);
 }  
 else if (button==RIGHT) {
    ProcessClickSpecial(mouse.x, mouse.y, MODE_USE, MODE_WALK);
 }
}

You see when there is an interaction then the frist mode is used. Otherwise the second.


As about inventory clicks what should happen when the player has choosen the item from the inventory?
Does the cursor represent the item then? How you suppose to return the cursor to normal state?

-Cheers

kejoxen

thanks for your help, everything works as it should so far and i think i am getting my head around the scripting,

ok as for the inventory,

as i am using the right button as use, the i suppose a right click on an inventory item should select it, left click while the item is active will unselect and right clicking with the item selected will attempted to use that item at the point of the click.

a left click on an inventory item will look at the item also.


Scorpiorus

Quotethink i am getting my head around the scripting
Glad to hear. it's really not difficult to script things in AGS.

Quoteas i am using the right button as use, the i suppose a right click on an inventory item should select it, left click while the item is active will unselect and right clicking with the item selected will attempted to use that item at the point of the click.

a left click on an inventory item will look at the item also.
Okey, first of all you want a different way of handling the inventory clicks than AGS processes internally. So you need to go to the game options and check Handle inventory clicks in script. This way you'll be able to handle them for yourself. If you look in the manual about that option than you'll find that with that mode turned on the on_mouse_click() function may recieve two additional values: LEFTINV and RIGHTINV. These values are passed in when you perform left/right clicks over the inventory window (to be more precise over the inventory items). Thereby LEFTINV should cause to look at the inventory item whereas the RIGHTINV should select it. The game.inv_activated variable maybe used along with LEFTINV/RIGHTINV to determine what inventory item player has clicked on.
As about unselection item or using it on some object the usual LEFT/RIGHT values need to be used as well. Ok, a bit of changes to on_mouse_click() then:


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) {
    // if player has an item then unselect:
    if (character[GetPlayerCharacter()].activeinv != -1) SetActiveInventory(-1);
    // otherwise process look or walk:
    else ProcessClickSpecial(mouse.x, mouse.y, MODE_LOOK, MODE_WALK);
 }  
 else if (button==RIGHT) {
    // if player has an item then try to use it:
    if (character[GetPlayerCharacter()].activeinv != -1)
         ProcessClickSpecial(mouse.x, mouse.y, MODE_USEINV,  MODE_WALK);
    // otherwise just interact as usual:
    else ProcessClickSpecial(mouse.x, mouse.y, MODE_USE,     MODE_WALK);
 }

 // handling inventory clicks: (Handle inventory clicks in script must be on!)
 else if (button==RIGHTINV) { //for right inv. click:
    // select the item  player has clicked on
    SetActiveInventory(game.inv_activated);
 }
 else if (button==LEFTINV) { //for left inv. click:
    // run look at inventory interaction
    RunInventoryInteraction (game.inv_activated, MODE_LOOK);
 }

}


Oh, there is SetInvDimensions (int width, int height) function which may help to optimize inventory item's slot area. Very useful to play with a bit as it actually sets the size of each inventory slot. Sometimes it's difficult to select an item because it's sprite size less than the slot size. See manual for details on that function.



ok. that's all for now. ask any questions you have and btw welcome to AGS forums. ;)

-Cheers

kejoxen

thankyou, it works exactly as i needed.

i always liked the virtual theatre interface for bass and broken sword, i know it limits you options as far as having amusing lines of dialogue when you try to talk to a tomato in your invertory or push the jar of vaseline you just picked up but its so much easier and neater.

thanx

Germen1

Ok, I'm making a game with the same interface as kejoxen, and I follow the same steps, but with this script I cannot use the inventory item between them. What can I do?


PD: Excuse me if my english isn't very good: I'm spanish.

SMF spam blocked by CleanTalk