SA-MP Forums Archive
[Help] Charging using SetPlayerVelocity - 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: [Help] Charging using SetPlayerVelocity (/showthread.php?tid=315821)



[Help] Charging using SetPlayerVelocity - Universal - 04.02.2012

Hey everyone,

so Im making a "leap" or "charge" function, but the thing is that I dont really know how to do this. Im not sure how to use SetPlayerVelocity, because I've never used it before...
So here's what I've tried so far:

pawn Код:
new
    Float: X2,
    Float: Y2,
                       
    Float: X,
    Float: Y,
                       
    Float: Z;
                   
// Getting current player's position and the position infront of him
GetPlayerPos(playerid, X, Y, Z);
GetXYInFrontOfPlayer(playerid, X2, Y2, 2.0);
                   
// Calculating the difference between the current possition and the position infront of the player
X = X - X2;
Y = Y - Y2;
                   
// "Charging" him towards?
SetPlayerVelocity(playerid, X, Y, 0.2);
Basically, what I need to do is to "charge" player towards him, in the direction he's facing... Any ideas?

Thanks for help, I'll +rep anyone who helps me.


Re: [Help] Charging using SetPlayerVelocity - thimo - 04.02.2012

First off all i thnik you gotta set the velocity like this: SetPlayerVeloCity(playerid, 0.2, 0.2, 0.2);
Second I have a script wich checks the speed of player infront of him when i got the thing out how i did it i will tell you
Edit:
This is to get vehicleid but since i see your post count i guess you know how to change it for anything
pawn Код:
GetVehicleInfrontID (vehid)
{
    new Float: temp = 7.0;
    new j = 0;
    for (new i = 1; i <= MAX_VEHICLES; i++)
    {
        new Float: a, Float: x1, Float: y1, Float: z1, Float: x2, Float: y2, Float: z2;
        GetVehiclePos (vehid, x1, y1, z1);
        GetVehicleZAngle (vehid, a);
        if (i != vehid)
        {
            if (GetVehiclePos (i, x2, y2, z2))
            {
                new Float: distance = floatsqroot (floatpower ((x1 - x2), 2) + floatpower ((y1 - y2), 2) + floatpower ((z1 - z2), 2));
                GetVehicleZAngle (vehid, a);

                if (distance < 300.0)
                {
                    x1 = x1 + (distance * floatsin(-a, degrees));
                    y1 = y1 + (distance * floatcos(-a, degrees));

                    distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2)));

                    if (temp > distance)
                    {
                        temp = distance;
                        j = i;
                    }
                }
            }
        }
    }
    if (temp < 7.0) return j;
    return -1;
}



Re: [Help] Charging using SetPlayerVelocity - Universal - 04.02.2012

Quote:
Originally Posted by thimo
Посмотреть сообщение
First off all i thnik you gotta set the velocity like this: SetPlayerVeloCity(playerid, 0.2, 0.2, 0.2);
Second I have a script wich checks the speed of player infront of him when i got the thing out how i did it i will tell you
Edit:
This is to get vehicleid but since i see your post count i guess you know how to change it for anything
pawn Код:
GetVehicleInfrontID (vehid)
{
    new Float: temp = 7.0;
    new j = 0;
    for (new i = 1; i <= MAX_VEHICLES; i++)
    {
        new Float: a, Float: x1, Float: y1, Float: z1, Float: x2, Float: y2, Float: z2;
        GetVehiclePos (vehid, x1, y1, z1);
        GetVehicleZAngle (vehid, a);
        if (i != vehid)
        {
            if (GetVehiclePos (i, x2, y2, z2))
            {
                new Float: distance = floatsqroot (floatpower ((x1 - x2), 2) + floatpower ((y1 - y2), 2) + floatpower ((z1 - z2), 2));
                GetVehicleZAngle (vehid, a);

                if (distance < 300.0)
                {
                    x1 = x1 + (distance * floatsin(-a, degrees));
                    y1 = y1 + (distance * floatcos(-a, degrees));

                    distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2)));

                    if (temp > distance)
                    {
                        temp = distance;
                        j = i;
                    }
                }
            }
        }
    }
    if (temp < 7.0) return j;
    return -1;
}
Ha, thanks buddy! I'll change it for my needs.
I'll give a reply on wether I succeed or not.


Re: [Help] Charging using SetPlayerVelocity - Universal - 04.02.2012

This is what I've made, but it doesnt seem to work, just charges me into some random direction.
pawn Код:
new
    Float: a,
    Float: x1,
    Float: y1,
    Float: z1,
    Float: x2,
    Float: y2,
    Float: z2,
    Float: distance;

GetPlayerPos(playerid, x1, y1, z1);
GetPlayerFacingAngle(playerid, a);
GetXYInFrontOfPlayer(playerid, x2, y2, 2.0);

//distance = floatsqroot (floatpower ((x1 - x2), 2) + floatpower ((y1 - y2), 2) + floatpower ((z1 - z2), 2));

//x1 = x1 + (distance * floatsin(-a, degrees));
//y1 = y1 + (distance * floatcos(-a, degrees));

//distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2)));

x1 = floatsqroot( floatpower( (x1 - x2), 2) );
y1 = floatsqroot( floatpower( (y1 - y2), 2) );

//x2 = x1 + (x1 * floatsin(-a, degrees));
//y2 = y1 + (y1 * floatcos(-a, degrees));

SetPlayerVelocity(playerid, x1, y1, 0.1);



Re: [Help] Charging using SetPlayerVelocity - thimo - 05.02.2012

Well atleast it works ... But wich direction it shoots you? north south east west?