I want to be able to set up the "+" and "-" keys to increase or decrease a characters walk speed.
how would I go about doing this im sure I have to put it in the global script
This should work
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeyPlus)
{
cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1);
}
if (keycode == eKeyHyphen)
{
cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1, cEgo.WalkSpeedY -1);
}
}
There's a problem with that, because AFAIK there's a limitation in AGS that says you can't set the walkspeed of a character while he is walking.
I don't know of an easy way to make it to work... you can do it so that only if the character is not moving his walkspeed will change by changing ethan's code like this:
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeyPlus && !cEgo.Moving)
{
cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1);
}
if (keycode == eKeyHyphen && !cEgo.Moving)
{
cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1, cEgo.WalkSpeedY -1);
}
}
Another thing you can do (but it can be quite irritating for the user) is to stop the character from moving and then change it's walkspeed, like this:
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeyPlus)
{
cEgo.StopMoving();
cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1);
}
if (keycode == eKeyHyphen)
{
cEgo.StopMoving();
cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1, cEgo.WalkSpeedY -1);
}
}
I never knew that, is there a way to get what the current x and y coordinates are that the character is walking to. If so you could add that in right after the change in speed and the pause would be hardly noticeable if it is noticeable at all.
I can't seem to find anything though.
EDIT: Try this:
First add this into the on left mouse click section of the global script
if (mouse.Mode == eModeWalkto)
{
variable = mouse.x
variable2 = mouse.y
}
Then add to the original change speed script
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeyPlus)
{
cEgo.StopMoving();
cEgo.SetWalkSpeed(cEgo.WalkSpeedX + 1, cEgo.WalkSpeedY + 1);
cEgo.Walk(Variable, Variable2);
}
if (keycode == eKeyHyphen)
{
cEgo.StopMoving();
cEgo.SetWalkSpeed(cEgo.WalkSpeedX - 1, cEgo.WalkSpeedY -1);
cEgo.Walk(Variable,Variable2);
}
}
As long as a mouse click caused the initial movement this should work just fine.
Not that I know of...
You can write an extender method for walk that will save the target x&y and then use it, but you'll have to remember using it in the entire game, and it can get complicated...
I fixed it so that the character stops moving to avoid the not allowed while walking error
but now there is another problem if you press + or - to many times and slow it down to much or speed it up to much
there is a limit to this as well and it will crash the game when exceded is there a way to make it stop before that point
This should work for the minus.
if (keycode == eKeyHyphen && cEgo.WalkSpeedX != 1)
I don't think there is a maximum walk speed but if you want to set it it would work the same way
Quote from: Ethan Damschroder on Mon 15/02/2010 20:58:56
This should work for the minus.
if (keycode == eKeyHyphen && cEgo.WalkSpeedX != 1)
I don't think there is a maximum walk speed but if you want to set it it would work the same way
do I put this in the same script? and other then the cego name does it need be edit any ?
Just replace it with the
if (keycode == eKeyHyphen)
in the previous script...