Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dualnames on Sat 10/03/2007 01:24:38

Title: Usermode problem
Post by: Dualnames on Sat 10/03/2007 01:24:38
Well I want when the player selects the gun to change cursor mode to usermode1(which I call as shooting mode  since the cursor is a crosshair)
But I can't do it.
Well I used the following code:

if (player.activeinventory == igun) {
setcursormode(usermode1)
}

But when i placed it on the repeatedly execute line the obvious happened.
Well I have the following guis (an iconbar popping and an inventory gui)
and some other that pop up after shorcuts.

Help please
Title: Re: Usermode problem
Post by: Khris on Sat 10/03/2007 02:21:43
if (player.ActiveInventory==iGun) mouse.Mode=eModeUsermode1;

(from the top of my head.)
Title: Re: Usermode problem
Post by: Ashen on Sat 10/03/2007 16:04:28
What's 'the obvious'?
The obvious thing to me is, you won't be able to have any other mode than eModeUsermode1 so long as the Gun is the active item. Is that the problem? Khris' code won't do anything about that, it's just your code updated to not use the old-style SetCursorMode command. If that was your problem, READ THE MANUAL for the current versions of commands - if it gives you an 'undefined token' message, either update your code or uncheck the 'Enforce object-based scripting' option on the General settings window.

If the problem is what I said (the 'not being able to change mode' thing), what do you want to happen instead? The easiest solution I can see is:

if (mouse.Mode == eModeUseinv && player.ActiveInventory==iGun) mouse.Mode=eModeUsermode1;

Which should set it to eModeUsermode1 when you want to use the gun, but still let you use the other modes the rest of the time.

You could also maybe change the cursor graphic for the Gun item to the crosshair, and just use eModeUseinv. That'd require a little more coding, however.
Title: Re: Usermode problem
Post by: Dualnames on Sat 17/03/2007 21:55:04
Well. I made it.
I used a the isbuttondown function and figured it out.
Thanks to all
Title: Re: Usermode problem
Post by: Ashen on Sat 17/03/2007 22:07:44
Glad you've sorted it, but can I ask how exactly?
Can you post the final, working code for anyone who might need it in the future?
Title: Re: Usermode problem (Check code)
Post by: Dualnames on Wed 21/03/2007 20:59:37
Quote from: Ashen on Sat 17/03/2007 22:07:44
Glad you've sorted it, but can I ask how exactly?
Can you post the final, working code for anyone who might need it in the future?


Blast that. But ok

Here it is.

First make this function at global script

#sectionstart user// DO NOT EDIT OR REMOVE THIS LINE
function user(int parameter) {

  if (parameter == 1) {   
  if (IsButtonDown(eMouseRight)) {
     SetTimer(12,1);       
    }
   
  }
  else if (parameter == 2) { 
        if  (IsTimerExpired(12)) {       
           SetActiveInventory(13);                     
    }

  } 
 
}
#sectionend user// DO NOT EDIT OR REMOVE THIS LINE


Then import the function via script header then add to all rooms you want at the repeatedly execute the following


if (player.ActiveInventory==igun) {
        GUIOff(2);
        SetCursorMode(eModeUsermode1);
        user(1);
        user(2);
      }


This triggers when the gun is selected by the user.

Title: Re: Usermode problem
Post by: Khris on Wed 21/03/2007 21:39:25
Seriously, I'm absolutely amazed that this code does what you want.
It looks like a wobbling 5-feet Jenga tower to me.

1. You don't need the #section stuff when adding your own functions
2. The whole stuff you've posted can be done like this:
if (player.ActiveInventory==igun) {
        gui[2].Visible=false;
        mouse.Mode=eUsermode1;
        if (IsButtonDown(eMouseRight) player.ActiveInventory=inventory[13];
      }

3. You are still mixing old and new code.

How about:
if (mouse.Mode == eModeUseinv && player.ActiveInventory==iGun) mouse.ChangeModeGraphic(CROSSHAIR_SPRITE);