[FilterScript] Fireball script
#1

Back when I was a total noob at any coding whatshowever, I used to be really addicted to Naruto and Avatar: TLA. Thanks to that, I got Limex to write this code for me. It's pretty simple but still really awesome and I haven't seen alot of people do this kind of thing.

Notes:
- Aim and click will cause you to shoot a fireball towards your target's last position
- Small cooldown which prevents usage and should fix server performance issues

[ame]http://www.youtube.com/watch?v=BK7p5WafeRE&[/ame]

pawn Код:
#include <a_samp>
#include <zcmd>

#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

stock IsPlayerAiming(playerid, aimid)
{
        new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
        GetPlayerPos(playerid, X1, Y1, Z1);
        GetPlayerPos(aimid, X2, Y2, Z2);
        new Float:Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
        if(Distance < 100)
        {
                new Float:A;
                GetPlayerFacingAngle(playerid, A);
                X1 += (Distance * floatsin(-A, degrees));
                Y1 += (Distance * floatcos(-A, degrees));
                Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
                if(Distance < 0.5)
                {
                    return true;
                }
        }
        return false;
}

stock IsPlayerLookingAtPlayer(player1, player2) { // Simon edited by Carlton
        if (!IsPlayerConnected(player1) || !IsPlayerConnected(player2)) return 0;
        if(player1 == player2) return 0;
        new
                Float: distance,
                Float: vectorX,
                Float: vectorY,
                Float: vectorZ,
                Float: plyrPos[2][3],
                Float: projPos[3];
        GetPlayerCameraFrontVector(player1, vectorX, vectorY, vectorZ);
        GetPlayerCameraPos(player1, plyrPos[0][0], plyrPos[0][1], plyrPos[0][2]);
        GetPlayerPos(player2, plyrPos[1][0], plyrPos[1][1], plyrPos[1][2]);
        #define SQUARE(%1)  ((%1)*(%1))
        distance = floatsqroot(
        SQUARE(plyrPos[1][0]-plyrPos[0][0]) + SQUARE(plyrPos[1][1]-plyrPos[0][1]) + SQUARE(plyrPos[1][2]-plyrPos[0][2]));
        projPos[0] = plyrPos[0][0] + vectorX * distance;
        projPos[1] = plyrPos[0][1] + vectorY * distance;
        projPos[2] = plyrPos[0][2] + vectorZ * distance;
        return ((SQUARE(plyrPos[1][0]-projPos[0]) + SQUARE(plyrPos[1][1]-projPos[1]) + SQUARE(plyrPos[1][2]-projPos[2])) <= SQUARE(distance / 6));
        #undef SQUARE
}

CMD:fireballs(playerid, params[])
{
    if( !GetPVarInt(playerid, "FIREBALLS") ) SetPVarInt(playerid, "FIREBALLS", 1), SendClientMessage(playerid, -1, "Fireballs turned on.");
    else SetPVarInt(playerid, "FIREBALLS", 0), SendClientMessage(playerid, -1, "Fireballs turned off.");
    return 1;

}

public OnObjectMoved(objectid)
{

    for( new i = 0; i < MAX_PLAYERS; i++)
    {
        if( objectid == GetPVarInt(i, "FIREOBJID") )
        {

            DestroyObject( GetPVarInt(i, "FIREOBJID") );
            DeletePVar(i, "FIREOBJID");
            CreateExplosion( GetPVarFloat(i, "FIREBALLX"), GetPVarFloat(i, "FIREBALLY"), GetPVarFloat(i, "FIREBALLZ"), 11, 7.5);

        }
    }

}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPVarInt(playerid, "FIREBALLS") && PRESSED(KEY_FIRE))
    {
        new Float:posX, Float:posY, Float:posZ;
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            GetPlayerPos(i,posX,posY,posZ);
            if (i == playerid) continue;
            if(IsPlayerLookingAtPlayer(playerid, i) && IsPlayerAiming(playerid, i) && !IsPlayerInAnyVehicle(playerid) && !IsPlayerInAnyVehicle(i))
            {
                if( GetPVarInt(playerid, "FIREOBJID") != 0 ) return SendClientMessage(playerid, -1, "1 at a time!");

                new str[100];
                new nom[32];
                GetPlayerName(i, nom, 32);
                format(str, 100, "You fireballed %s.", nom);
                SendClientMessage(playerid, -1, str);
                new Float:px, Float:py, Float:pz;
                GetPlayerPos(playerid, px, py, pz);
                SetPVarInt(playerid, "FIREOBJID", CreateObject(18688, px, py, pz-1.35, 0, 0, 0, 500.0));
                GetPlayerPos(i, px, py, pz);
                SetPVarFloat(playerid, "FIREBALLX", px);
                SetPVarFloat(playerid, "FIREBALLY", py);
                SetPVarFloat(playerid, "FIREBALLZ", pz);
                MoveObject(GetPVarInt(playerid, "FIREOBJID"), px, py, pz-1.5, 15);
            }
        }
    }
    return 1;
}
If Limex wants this to be removed then he can PM me and I will gladly delete the thread although I doubt he'll have issues with it. Also credits to Nourdin for testing this script with me.

have fun
Reply
#2

Good job ,nice one
Reply
#3

Nice one.
Reply
#4

Good One, i use a Script Like this as a Minigame on my Server
Reply
#5

Nice job man. This looks awesome.
Reply
#6

Lovely.
Reply
#7

Wow good job.
Reply
#8

Awesome
Reply
#9

Nice job +REP
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)