I'm not sure if this should go in ms4 tutorials or ms4 development or resources-bugfixes. If anyone wants to move it that's fine.
Anyway, I made this for my game (Rising Flames) as part of the stun/slow system, but it also stops speedhacking, so I thought I would post it here.
Basically what I am doing is making the client wait for the server to say "you moved" instead of having the client move itself. This, along with a timer check server side, removes the ability to speedhack.
[CLIENT SIDE]
in modGameLogic, sub checkmovement:
find and delete/comment out.
Code:
' Check if player has the shift key down for running
If ShiftDown Then
Player(MyIndex).Moving = MOVING_RUNNING
Else
Player(MyIndex).Moving = MOVING_WALKING
End If
We do this so if the client doesn't get the OK from the server, it isn't already moving.
also delete/comment out
Code:
Player(MyIndex).YOffset = PIC_Y
Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) - 1)
Code:
Player(MyIndex).YOffset = PIC_Y * -1
Call SetPlayerY(MyIndex, GetPlayerY(MyIndex) + 1)
Code:
Player(MyIndex).XOffset = PIC_X
Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) - 1)
and
Code:
Player(MyIndex).XOffset = PIC_X * -1
Call SetPlayerX(MyIndex, GetPlayerX(MyIndex) + 1)
We do this so that the client is no longer moving itself if it doesn't get the OK from the server.
[SERVER SIDE]
Now you may be thinking, "we didn't set up any packets clientside for the OK from the server"
That is right, because I am taking advantage of the already made code to handle other player's movement. Turns out it works without any changes for us too.
We just have to send the packet to ourselves from the server.
modPlayer, sub playermove
find and replace each
Code:
Call SendDataToMapBut(Index, GetPlayerMap(Index), packet)
in the sub
with
Code:
Call SendDataToMap(GetPlayerMap(Index), packet)
there are 4, make sure to do it for each direction
Now for the last part of this tutorial. We need to place the check serverside to stop the player from moving too fast.
first we need to add a value to the player that shows their timer.
still serverside, modTypes, type TempPlayerRec
in the type, right below
Code:
GettingMap As Byte
add
Code:
LastMove As Long
now, back in sub Playermove
under
Code:
Call SetPlayerDir(Index, Dir)
add
Code:
If TempPlayer(Index).LastMove = 0 Then TempPlayer(Index).LastMove = GetTickCount
If TempPlayer(Index).LastMove > GetTickCount Then Exit Sub
If Movement = MOVING_WALKING Then
TempPlayer(Index).LastMove = GetTickCount + 220
Else
TempPlayer(Index).LastMove = GetTickCount + 460
End If
in my game, i only have walking, so i have yet to test the running code. It should work though.
The numbers 220 and 460 are very important. In a perfect world, they would be 240 and 480, which you get by doing
the walk timer (30) times the pixels in a tile (32) divided by the movement speed (4)
30*32/4 = 240
i had to subtract 20 from it to compensate for some lag. You may have to subtract more/less depending on your lag, or change the numbers if you have a different walk/run speed or a different pic_x/pic_y.
EDIT: Forgot to mention, I tested this and it worked against cheat engine 5.4
_________________
GIAKEN wrote:
I think what I see is this happening:
Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.