SA-MP Forums Archive
SetPlayerSpeed? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetPlayerSpeed? (/showthread.php?tid=322487)



SetPlayerSpeed? - niels44 - 02.03.2012

hey guys,
i have searched for GetPlayerSpeed and SetPlayerSpeed and i found this stock for the GetPlayerSpeed:
pawn Код:
stock GetPlayerSpeed(playerid, bool:kmh) // by misco
{
  new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
but i just cant find a SetPlayerSpeed stock or function or wutever... does anyone knows where to find 1?
or if you have 1 can you pls give me?

greets niels


Re: SetPlayerSpeed? - thimo - 02.03.2012

There aint... Use SetPlayerVelocity


Re: SetPlayerSpeed? - niels44 - 02.03.2012

yes but eehm how to use that one? becuz its: SetPlayerVelocity(playerid, x, y, z);
new Speed;
but eehm if i first do GetPlayerSpeed(playerid, Speed )
and then
SetPlayerVelocity(playerid, Speed); ?? that wont work becuz its then out of bounds... becuz it has to be x, y , z.... and not 1... you know how to solve this?


Re: SetPlayerSpeed? - thimo - 02.03.2012

I think u have to put em like SetPlayerVelocity(playerid, Speed, Speed, Speed); i dont know if this works. Let me know


Re: SetPlayerSpeed? - 2KY - 02.03.2012

Experiment with setting the x and y values. (x+*, y+*) z value would only put your vehicle in the air (as far as I know, really haven't used SetPlayerVelocity much)


Re: SetPlayerSpeed? - thimo - 02.03.2012

If you want it to keep driving in one way you gotta use GetPlayerVelocity:
pawn Код:
new Float:Velocity[3];
GetPlayerVelocity(playerid, Velocity[0], Velocity[1], Velocity[2]);
And then we gotta set it but since the car or player could have slowed down a bit we gotta put some speed TO it do that like this:
pawn Код:
SetPlayerVelocity(playerid, Velocity[0] + 1.0, Velocity[1] + 1.0, Velocity[2]);



Re: SetPlayerSpeed? - niels44 - 02.03.2012

hmm ok wait i'll try it i edit this post if it works or not


Re: SetPlayerSpeed? - niels44 - 02.03.2012

pawn Код:
CMD:transform(playerid, params[])
{
    if(IsTransFormed[playerid] == 0)
    {
        SetTimer("destroyveh", 100, 0);
        new Float:Velocity[3], Float:angle, Float:x, Float:y, Float:z;
        GetPlayerFacingAngle(playerid, angle);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerVelocity(playerid, Velocity[0], Velocity[1], Velocity[2]);
        PutPlayerInVehicle(playerid, CreateVehicle(infernus, x, y, z, angle, 0, 0, 15), 0);
        IsTransFormed[playerid] = 1;
        SetPlayerVelocity(playerid, Velocity[0] + 1.0, Velocity[1] + 1.0, Velocity[2]);
        return SendClientMessage(playerid, 0x33AA33AA, "you have transformed your vehicle into a infernus");
    }
    else if(IsTransFormed[playerid] == 1)
    {
        SetTimer("destroyveh", 100, 0);
        new Float:Velocity[3], Float:angle, Float:x, Float:y, Float:z;
        GetPlayerFacingAngle(playerid, angle);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerVelocity(playerid, Velocity[0], Velocity[1], Velocity[2]);
        PutPlayerInVehicle(playerid, CreateVehicle(rancher, x, y, z, angle, 0, 0, 15), 0);
        IsTransFormed[playerid] = 2;
        SetPlayerVelocity(playerid, Velocity[0] + 1.0, Velocity[1] + 1.0, Velocity[2]);
        return SendClientMessage(playerid, 0x33AA33AA, "you have transformed your vehicle into a rancher");
    }
    else if(IsTransFormed[playerid] == 2)
    {
        SetTimer("destroyveh", 100, 0);
        new Float:Velocity[3], Float:angle, Float:x, Float:y, Float:z;
        GetPlayerFacingAngle(playerid, angle);
        GetPlayerPos(playerid, x, y, z);
        GetPlayerVelocity(playerid, Velocity[0], Velocity[1], Velocity[2]);
        PutPlayerInVehicle(playerid, CreateVehicle(hydra, x, y, z, angle, 0, 0, 15), 0);
        IsTransFormed[playerid] = 2;
        SetPlayerVelocity(playerid, Velocity[0] + 1.0, Velocity[1] + 1.0, Velocity[2]);
        return SendClientMessage(playerid, 0x33AA33AA, "you have transformed your vehicle into a hydra");
    }
    return 1;
}
forward destroyveh(playerid);
public destroyveh(playerid)
{
    DestroyVehicle(GetPlayerVehicleID(playerid));
    return 1;
}

and the new:
pawn Код:
new IsTransFormed[MAX_PLAYERS];
hmm no wait i changed some things now(updated the codes above) but now when i use /transform my old vehicle gets destroyed but i dont get my new one...?? anyone knows whats wrong in the code?

pls help


AW: Re: SetPlayerSpeed? - Nero_3D - 02.03.2012

try that

pawn Код:
CMD:transform(playerid, params[]) {
    new
        vehicleid = GetPlayerVehicleID(playerid)
    ;
    if(vehicleid) {
        new
            Float: x,
            Float: v,
            Float: v,
            Float: a
        ;
        GetVehicleZAngle(vehicleid, a);
        GetVehiclePos(vehicleid, x, y, z);
        switch(IsTransFormed[playerid]++) {
            case 0: (_: a) = CreateVehicle(infernus, x, y, z, a, 0, 0, 15);
            case 1: (_: a) = CreateVehicle(rancher, x, y, z, a, 0, 0, 15);
            default: (_: a) = CreateVehicle(hydra, x, y, z, a, 0, 0, 15);
        }
        GetVehicleVelocity(vehicleid, x, y, z);
        SetTimer("PutPlayerInTransVehicle", 0, false, "iifff", playerid, _: a, x, y, z);
        SendClientMessage(playerid, 0x33AA33AA, "You have transformed your vehicle!");
        DestroyVehicle(vehicleid);
    }
    return true;
}
pawn Код:
forward PutPlayerInTransVehicle(playerid, vehicleid, Float: x, Float: y, Float: z);
public PutPlayerInTransVehicle(playerid, vehicleid, Float: x, Float: y, Float: z) {
    PutPlayerInVehicle(playerid, vehicleid, 0);
    SetVehicleVelocity(vehicleid, x, y, z);
}
And the GetPlayerSpeed function you got is another fail
Search for one which actually uses the pythagorean


Re: SetPlayerSpeed? - niels44 - 02.03.2012

hmm ok i will try this one thnx for elp

EDIT: yeah it works... but when at the last vehicle(hydra) when i do /transform again then it spawns the hydra again... and not the infernus...

and eehm how to add more then 3? XD for case if i want to add more