Improve this slow setplayerspeed
#1

I want reduce player speed on foot using UsePlayerPedAnims();

Someneone could help me?

It's not work fine
Код:
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;
}
Reply
#2

Well i change something.

PHP код:
public OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        new 
Float:VPOS[3];
        
GetPlayerVelocity(playeridVPOS[0], VPOS[1], VPOS[2]);
             
SetPlayerVelocity(playeridVPOS[0]-0.5VPOS[1]-0.5VPOS[2]-0.5);
    }
    return 
1;

"-" means subtract. Also i almost change the whole code
Reply
#3

Quote:
Originally Posted by MicroKyrr
Посмотреть сообщение
Well i change something.

PHP код:
public OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        new 
Float:VPOS[3];
        
GetPlayerVelocity(playeridVPOS[0], VPOS[1], VPOS[2]);
             
SetPlayerVelocity(playeridVPOS[0]-0.5VPOS[1]-0.5VPOS[2]-0.5);
    }
    return 
1;

"-" means subtract. Also i almost change the whole code
So errmmm, what happens when we stand still? :S
Reply
#4

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
So errmmm, what happens when we stand still? :S
Oh i see!
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        if(
newkeys KEY_WALK) && (newkeys KEY_SPRINT))
        {
            new 
Float:VPOS[3];
            
GetPlayerVelocity(playeridVPOS[0], VPOS[1], VPOS[2]);
            
SetPlayerVelocity(playeridVPOS[0]*0.5VPOS[1]*0.5VPOS[2]*0.5);
        }
    }
    return 
1;

Reply
#5

Velocity should probably only be multiplied or divided. Specifying arbitrary values is, well, arbitrary.
Reply
#6

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);
		}
	}
}
Reply
#7

Quote:
Originally Posted by MicroKyrr
Посмотреть сообщение
Oh i see!
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        if(
newkeys KEY_WALK) && (newkeys KEY_SPRINT))
        {
            new 
Float:VPOS[3];
            
GetPlayerVelocity(playeridVPOS[0], VPOS[1], VPOS[2]);
            
SetPlayerVelocity(playeridVPOS[0]*0.5VPOS[1]*0.5VPOS[2]*0.5);
        }
    }
    return 
1;

its not work, dont change nothing :S

Quote:
Originally Posted by NaS
Посмотреть сообщение
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);
		}
	}
}
try to fall and jump
and even mode of running is not fluid
Reply
#8

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...
Reply
#9

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
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...
I'm actually going to be chucking this into a test script for messing with lol.
Reply
#10

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
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...
Exemple code pls
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)