[Doubt] Check if the player is walking or running?

Open discussion forum. For topics that do not fit anywhere else.

Moderator: POL Developer

Post Reply
DerexScript
New User
Posts: 24
Joined: Thu Jan 12, 2017 7:19 am

[Doubt] Check if the player is walking or running?

Post by DerexScript »

Hello .. Good evening.

I'm making a system that I need to check to see if the character is walking or running.

What would be the best way to do this?
Is there a PoL function for this?
If possible could someone show an example?

Grateful for the attention
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: [Doubt] Check if the player is walking or running?

Post by RusseL »

Define Walking and Running?
How fast must character walk, to run? :D
DerexScript
New User
Posts: 24
Joined: Thu Jan 12, 2017 7:19 am

Re: [Doubt] Check if the player is walking or running?

Post by DerexScript »

i'm trying to create a magery script for cast spells walking, but if the character runs the spell will be distubed, and fails... so the question is, what function make this work?
thanks a lot.

If you are walking = allow action !.
If you're running = deny action!
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: [Doubt] Check if the player is walking or running?

Post by CWO »

Walking/Running is just a cosmetic thing that is done client side based on how fast someone is moving. You could hook the movement packet and count how many steps someone is moving per second to see if they're walking or running but the slightest amount of connection lag would make this completely inaccurate since this is a difference of about 2 steps on foot and about 5 on a mount not to mention, hooking this packet can very easily lag your shard badly due to the amount of times it's handled.
Nando
POL Developer
Posts: 282
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: [Doubt] Check if the player is walking or running?

Post by Nando »

Running is not only cosmetic, it also affects the movecost (check movecost.cfg).

POL knows when a character is running, but there's currently no easy way to access the movement mode via script. The client sends the packet 0x02 (move request) to move or turn in a certain direction. The directions go from 0x00 to 0x07 when walking, 0x80 to 0x87 when running. So you can check if (direction & 0x80) > 0, then the character is running.

As CWO said, the packethook for the move request should be as short as possible, otherwise your shard's performance will suffer.

One way I could think of, is that the spell sets a "#CastingSpell" property and the packethook removes it. Like so:

Code: Select all

//pseudo-code
if ((direction & 0x80)>0 and chr has cprop("#castingspell"))
    erase_prop("#castingspell");
endif
return 0; // let POL do its work on the packet
On the spell, check if #castingspell is still there on a fixed delay. One important caveat is that moving and turning are the same packet. The difference is whether the character is facing the direction of movement or not.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: [Doubt] Check if the player is walking or running?

Post by Yukiko »

The only way I can think to do this, and this is just off the top of my head, is that if you know how many steps per second is the walking pace and how many steps is the running pace you could save a players location at the start of casting and after each repetition of the animation check the distance the player has traveled and if the distance traveled versus the time of the previously saved location indicates they were running then cancel the spell. This could be done in the start_spell script if you are using a current POL version. You would have to take into account several factors, one of which is if the player is mounted or not because of course the mounted speed is faster than unmounted. You can read the game cock to get the timing. You will probably have to do a bit of testing to get the timing right.

I don't think this would cause undo server lag unless you have a large amount of players casting spells.

Keep in mind this is my thinking on how it could be done. As anyone who has been here a long time will tell you, my ideas sometimes aren't well thought out :)
DerexScript
New User
Posts: 24
Joined: Thu Jan 12, 2017 7:19 am

Re: [Doubt] Check if the player is walking or running?

Post by DerexScript »

Nando wrote: Thu Mar 16, 2017 11:53 pm Running is not only cosmetic, it also affects the movecost (check movecost.cfg).

POL knows when a character is running, but there's currently no easy way to access the movement mode via script. The client sends the packet 0x02 (move request) to move or turn in a certain direction. The directions go from 0x00 to 0x07 when walking, 0x80 to 0x87 when running. So you can check if (direction & 0x80) > 0, then the character is running.

As CWO said, the packethook for the move request should be as short as possible, otherwise your shard's performance will suffer.

One way I could think of, is that the spell sets a "#CastingSpell" property and the packethook removes it. Like so:

Code: Select all

//pseudo-code
if ((direction & 0x80)>0 and chr has cprop("#castingspell"))
    erase_prop("#castingspell");
endif
return 0; // let POL do its work on the packet
On the spell, check if #castingspell is still there on a fixed delay. One important caveat is that moving and turning are the same packet. The difference is whether the character is facing the direction of movement or not.
Thanks for the help.
I researched a lot in the forum, and I did not find anything related that could help me!
So I opened the razor, and started analyzing the packet's.
And whenever I walked a packet appeared 0x02
So I went to the packet's documentation page. And I saw that there, it differentiates if the character is walking or running.
If you are walking the packages that you will receive are these.
0x00 to 0x07
If you're running
0x80 to 0x87
And I saw that solved my problem.
The only thing that left me worried was the performance issue!
Anyway thank you very much for the help!
Yukiko wrote: Thu Mar 16, 2017 11:56 pm The only way I can think to do this, and this is just off the top of my head, is that if you know how many steps per second is the walking pace and how many steps is the running pace you could save a players location at the start of casting and after each repetition of the animation check the distance the player has traveled and if the distance traveled versus the time of the previously saved location indicates they were running then cancel the spell. This could be done in the start_spell script if you are using a current POL version. You would have to take into account several factors, one of which is if the player is mounted or not because of course the mounted speed is faster than unmounted. You can read the game cock to get the timing. You will probably have to do a bit of testing to get the timing right.

I don't think this would cause undo server lag unless you have a large amount of players casting spells.

Keep in mind this is my thinking on how it could be done. As anyone who has been here a long time will tell you, my ideas sometimes aren't well thought out :)
Our friend "CWO", mentioned a similar idea.
The only problem with this is the question of possible contingencies. As lag.
As the "CWO" itself has already mentioned!



Conclusion:
I'll use packethook to check if my character is walking or running.
If this causes instability I will be forced to do time verification, x tiles traversed.


Thank you all for wanting to help me.
If you need anything, look for me!
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: [Doubt] Check if the player is walking or running?

Post by Yukiko »

CWO mentioned hooking the movement packet which would take into account EVERY character moving in game. That might cause lag. My idea only runs in the casting script which would mean only those players casting would be monitored. As I said it might still cause lag when you have a large number of players casting but it would be limited only to players casting spells instead of all characters moving. I'm not even sure if you could get the timing right anyway but you could try it and see if it works. I may even test it out. You have a good idea if it can be worked out.
Post Reply