Hi Amigos,
Ive got a new one for you all...let me explain what Im trying to accomplish, and what i tried to do...and how I failed miserably and deserve a brutal beating (preferably with a wet cod).
Ok, what I want to do is have another mouse mode which is Run. Ive got the mouse cursor mode set at ID13. It is set to "standard mode". ScriptID is eModeRun. I thought that to get this, all I have to do is in my rep_exec, check if my mode is set to the Run mode, get the left-click position of my mouse...change the animation speed + view...and then go to that x,y position.
Now, here is what I tried (without success):
In my rep_exec:
if (mouse.Mode==eModeRun)
{
cEgo.StopMoving();
cEgo.SetWalkSpeed(4, 4);
cEgo.ChangeView(7);
cEgo.Walk(mouse.x, mouse.y);
// ProcessClick(mouse.x, mouse.y,eModeWalkto);
// player.Walk(mouse.x, mouse.y, eBlock);
}
I commented out the final two lines cause Im not sure which to use, and how. I know I have to "process" the x + y coordinates of my mouse, and save it somewhere...and then tell AGS to make my character "run" to that spot, but Im not entirely sure how to do this.
Right now, with what I have, the character moves to where my mouse is, not where I click...so when I move the mouse, it follows the mouse cursor (doesnt process the click!)...oh, also, if I choose "eblock", while the character moves I get my wait cursor (which I understand why), but I dont want this...so when I click "noblock", then the character doesnt even move at all!
I looked for "run cursor", "running mode", "cursor running mode", etc...in the threads without luck...although Im sure someone will say "dude, this has been answered a gazillion times over!"
:P
----EDIT---
Hey, I tried this, it works...but is it a "good way" of doing what I want to achieve?
The only thing is now my view mode stays at 23...how would I make it go back to my normal walk view when Im no longer in run mode?
if ((mouse.Mode==eModeRun)&& (mouse.IsButtonDown(eMouseLeft)))
{
cEgo.MovementLinkedToAnimation = false;
cEgo.StopMoving();
cEgo.SetWalkSpeed(20, 20);
cEgo.ChangeView(23);
cEgo.Walk(mouse.x, mouse.y, eNoBlock);
cEgo.MovementLinkedToAnimation = true;
}
Also though, with this code I get bugs when I use the cursor with gui's, etc...so Im not sure if I should place it in the rep_exec?
You need a bool! The problem with your first try is that it gets called every game loop
bool Running;
repeatedly_execute(){
If (mouse.Mode == eModeRun){
if (Running == false){
cEgo.StopMoving();
cEgo.SetWalkSpeed(4, 4);
cEgo.ChangeView(7);
cEgo.Walk(mouse.x, mouse.y)
Running = true;
}
}
}
It would probably be better to put this in the mouse event handler in the global script.
Hi guys,
I placed this here (look at end of the script):
function on_mouse_click(MouseButton 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 == eMouseLeft)
{
ProcessClick(mouse.x, mouse.y, mouse.Mode );
}
else if (button == eMouseRight || button == eMouseWheelSouth)
{
// right-click our mouse-wheel down, so cycle cursor
mouse.SelectNextMode();
}
else if (button == eMouseMiddle)
{
// Middle-button-click, default make character walk to clicked area (a little shortcut)
// Could have been just "player.Walk(mouse.x,mouse.y)", but it's best to
// leave our options open - what if you have a special script triggered
// on "walking" mode?
ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
else if (button == eMouseWheelNorth)
{
// Mouse-wheel up, cycle cursors
// If mode isn't WALK, set the previous mode (notice usage of numbers instead
// of eNums, when it suits us)...
if (mouse.Mode>0) mouse.Mode=mouse.Mode-1;
else
{
// ...but if it is WALK mode...
if (player.ActiveInventory!=null)
{
//...and the player has a selected inventory item, set mouse mode to UseInv.
mouse.Mode=eModeUseinv;
}
else
{
// If they don't, however, just set it to mode TALK (change this line if you add more cursor modes)
mouse.Mode=eModeQuestion;
}
}
}
if ((mouse.Mode==eModeRun)&& (mouse.IsButtonDown(eMouseLeft)))
{
cEgo.MovementLinkedToAnimation = false;
cEgo.StopMoving();
cEgo.SetWalkSpeed(20, 20);
cEgo.ChangeView(23);
cEgo.Walk(mouse.x, mouse.y, eNoBlock);
cEgo.MovementLinkedToAnimation = true;
}
}
Everything works fine...but I tried the "bool" thing, couldnt get it to work. Once I use the run mode, my character runs successfully to the spot I clicked...but when I try to use the normal walk mode, it uses the same view + speed I set for the run.
How do tell AGS to revert back to the proper view + speed for the walkto mode once I no longer use the run mode?
---EDIT---
Ok well in the function on_mouse_click I added this at the end after my run mode:
if ((mouse.Mode==eModeWalkto)&& (mouse.IsButtonDown(eMouseLeft)))
{
cEgo.MovementLinkedToAnimation = true;
cEgo.StopMoving();
cEgo.SetWalkSpeed(4, 4);
cEgo.ChangeView(7);
cEgo.Walk(mouse.x, mouse.y, eNoBlock);
}
It works, as in...when I run, he runs to the spot with proper view + proper speed...and when I click on walk afterwards...it gives me the #7 view at a 4,4 speed...
However, I think this might be an unattractive/too complicated way of achieving what I want. Im sure there is a "better way"...
Plus, lets assume thats an "ok" way to do it, instead of plugging values like (4,4) or (7)...how can I query those values that are set in the properties windows directly? Somthin' like (getdefaultspeed.x, getdefaultspeed.y), know what I mean?
Tested code:
// inside on_mouse_click
else if (button == eMouseLeft) {
int mm = mouse.Mode;
if (mm == eModeWalkto && player.WalkSpeedX == 20) {
// switch to walk speed
player.StopMoving();
player.ChangeView(7);
player.SetWalkSpeed(4, 4);
}
else if (mm == eModeRun) {
mm = eModeWalkto;
if (player.WalkSpeedX == 4) {
// switch to run speed
player.StopMoving();
player.ChangeView(23);
player.SetWalkSpeed(20, 20);
}
}
ProcessClick(mouse.x, mouse.y, mm);
}
Hi KhrisMUC,
Nice. This is elegant! I had to remove the && player.WalkSpeedX == 20) part for the mm == eModeWalkto to get it to work. Why is that? (Just want to understand whats going on under the hood, so to speak).
else if (button == eMouseLeft)
{
int mm = mouse.Mode;
if (mm == eModeWalkto)
{
// switch to walk speed
player.StopMoving();
player.ChangeView(7);
player.SetWalkSpeed(4, 4);
}
else if (mm == eModeRun)
{
mm = eModeWalkto;
if (player.WalkSpeedX == 4)
{
// switch to run speed
player.StopMoving();
player.ChangeView(23);
player.SetWalkSpeed(20, 20);
}
}
ProcessClick(mouse.x, mouse.y, mm);
Ps: If you dont mind me saying...you guys are good. Real good.
:D
So it works!
I tried to interfere as less as possible with the standard click processing.
The game is only supposed to call player.StopMoving() if it's necessary; with your change it's called at every walk click. I guess is doesn't matter, I'm wondering why you had to remove the check though.
My guess is that the walk speed is 0 when the character is standing... that's why the code didn't work in the scenario of trying to walk from a standing position. You need to do the same thing as in the running code section:
int mm = mouse.Mode;
if (mm == eModeWalkto)
{
if (player.WalkSpeedX == 20)
{
// switch to walk speed
player.StopMoving();
player.ChangeView(7);
player.SetWalkSpeed(4, 4);
}
}
No, the walk speed isn't 0 while standing. It's just a displacement variable, not the current speed.