[HELP] Knocked out when shot
#1

Does anyone knows how to make something that if you get hit by a weapon you get knocked out when you've got half health? That the player will do a certain animation and will get
Код:
TogglePlayerControllable(playerid, 0);
I hope anyone got a suggestion or a hint how to make that.
Reply
#2

Make a timer thats all you need a timer....
Reply
#3

Have a timer that loops and make it loop through all the players and check to see if anyone's health is below 50.0.
If it is then apply the animation and freeze them.
Reply
#4

They only need to get knocked out when they got shot, not when they got 50.0 health.
Reply
#5

pawn Код:
public OnPlayerKeyStateChange ( playerid, newkeys, oldkeys )
{
    if ( PRESSED ( KEY_FIRE ) )
    {
        if ( GetPlayerWeapon ( playerid ) != 0 )
        {
            foreach(Player, i)
            {
                if ( IsPlayerAimingAtPlayer( playerid, i ) )
                {
                    if ( i != playerid )
                    {
                        new Float:pHP;
                        GetPlayerHealth ( playerid, pHP);
                        if ( pHP < 50.0 )
                        {
                            //Apply animation.
                            TogglePlayerControllable ( i, 0 );
                        }
                    }
                }
            }
        }
    }
    return 1;
}

Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {

    new Float:TGTDistance;

    TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));

    new Float:tmpX, Float:tmpY, Float:tmpZ;

    tmpX = FrX * TGTDistance + CamX;
    tmpY = FrY * TGTDistance + CamY;
    tmpZ = FrZ * TGTDistance + CamZ;

    return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}

stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{

    new Float:DX, Float:DY;
    new Float:angle;

    DX = floatabs(floatsub(x2,X));
    DY = floatabs(floatsub(y2,Y));

    if (DY == 0.0 || DX == 0.0)
    {
        if(DY == 0 && DX > 0) angle = 0.0;
        else if(DY == 0 && DX < 0) angle = 180.0;
        else if(DY > 0 && DX == 0) angle = 90.0;
        else if(DY < 0 && DX == 0) angle = 270.0;
        else if(DY == 0 && DX == 0) angle = 0.0;
    }
    else
    {
        angle = atan(DX/DY);
        if(X > x2 && Y <= y2) angle += 90.0;
        else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
        else if(X < x2 && Y >= y2) angle -= 90.0;
        else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
    }
    return floatadd(angle, 90.0);
}

stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance)
{
    x += (distance * floatsin(-angle, degrees));
    y += (distance * floatcos(-angle, degrees));
}

stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius)
{
    new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
    GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
    GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);

    new Float:vertical, Float:horizontal;

    switch (GetPlayerWeapon(playerid)) {
       case 34,35,36: {
       if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
       return false;
       }
       case 30,31: {vertical = 4.0; horizontal = -1.6;}
       case 33: {vertical = 2.7; horizontal = -1.0;}
       default: {vertical = 6.0; horizontal = -2.2;}
    }

    new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
    new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
    GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));

    if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
    return false;
}

stock IsPlayerAimingAtPlayer(playerid, targetplayerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(targetplayerid, x, y, z);
    return IsPlayerAimingAt(playerid, x, y, z, 1.1);
}
NOT TESTED
Requires foreach.

Credits to niCe for the stock functions and ****** for foreach.
Reply
#6

How can I make a FS of this?
Reply
#7

What is your next question? Can somebody script it for me?

I mean, c'mon he gave you EVERYTHING. If you can't figure it out now, then I suggest reading up on the wiki and pawn_language.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)