public OnPlayerUpdate(playerid) { if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) { new Float:vx,Float:vy,Float:vz; GetPlayerVelocity(playerid,vx,vy,vz); SetPlayerVelocity(playerid,vx*0.5,vy*0.5,vz*0.5); } return 1; }
public OnPlayerUpdate(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
new Float:VPOS[3];
GetPlayerVelocity(playerid, VPOS[0], VPOS[1], VPOS[2]);
SetPlayerVelocity(playerid, VPOS[0]-0.5, VPOS[1]-0.5, VPOS[2]-0.5);
}
return 1;
}
Well i change something.
PHP код:
|
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
if(newkeys & KEY_WALK) && (newkeys & KEY_SPRINT))
{
new Float:VPOS[3];
GetPlayerVelocity(playerid, VPOS[0], VPOS[1], VPOS[2]);
SetPlayerVelocity(playerid, VPOS[0]*0.5, VPOS[1]*0.5, VPOS[2]*0.5);
}
}
return 1;
}
#define SPEED_MUL 0.1 #define MAX_Z_VEL 0.02 public OnPlayerUpdate(playerid) { if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) { new keys, ud, lr; GetPlayerKeys(playerid, keys, ud, lr); if((ud != 0 || lr != 0) && !(keys & KEY_JUMP)) { new Float:v0[3]; GetPlayerVelocity(playerid, v0[0], v0[1], v0[2]); if(v0[2] >= -MAX_Z_VEL && v0[2] <= MAX_Z_VEL) SetPlayerVelocity(playerid, v0[0] * SPEED_MUL, v0[1] * SPEED_MUL, v0[2] * SPEED_MUL); } } }
Oh i see!
![]() PHP код:
|
In OnPlayerUpdate you need to check for the up/down and left/right keys, however that makes it even more slow.
To prevent making you not able to fall you also have to check the z velocity (adjust MAX_Z_VEL). It might be a bit buggy when jumping, holding jump makes it work. This works for me, even when sprinting and walking. On a server with a high ping it could be very laggy tho. Код:
#define SPEED_MUL 0.1 #define MAX_Z_VEL 0.02 public OnPlayerUpdate(playerid) { if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) { new keys, ud, lr; GetPlayerKeys(playerid, keys, ud, lr); if((ud != 0 || lr != 0) && !(keys & KEY_JUMP)) { new Float:v0[3]; GetPlayerVelocity(playerid, v0[0], v0[1], v0[2]); if(v0[2] >= -MAX_Z_VEL && v0[2] <= MAX_Z_VEL) SetPlayerVelocity(playerid, v0[0] * SPEED_MUL, v0[1] * SPEED_MUL, v0[2] * SPEED_MUL); } } } |
And by the way, dont touch Z velocity, just skip it, if player is falling down than it could "slower" his fall and jumping from top of the building and surviving will become possible...I guess you dont want that...
|
Instead of checking for keys i would get velocity and than check if its BELOW that i want to be the fastest possible, if its is, just return/continue, if not than multiply with 0.75 or 0.8 (75 or 80% of current speed, that should slower the player)
One more way that comes to mind is scanning for keys and play RUN animations since you can set delta (animation speed). And by the way, dont touch Z velocity, just skip it, if player is falling down than it could "slower" his fall and jumping from top of the building and surviving will become possible...I guess you dont want that... |