
#include <amxmod>
#include <amxmisc>
#include <Vexd_Utilities>

//natives from fw module (fireworks module)
native is_entity(Index);

set_rendering(index,fx=kRenderFxNone, r=255,g=255,b=255, render=kRenderNormal,a
mount=16) {
        new Float:rendercolor[3]
        rendercolor[0] = float(r)
        rendercolor[1] = float(g)
        rendercolor[2] = float(b)
        Entvars_Set_Int(index,EV_INT_renderfx,fx)
        Entvars_Set_Vector(index,EV_VEC_rendercolor,rendercolor)
        Entvars_Set_Int(index,EV_INT_rendermode,render)
        Entvars_Set_Float(index,EV_FL_renderamt,float(amount))
}

new Title[] = "AMX Fireworks"
new Version[] = "1.1.1"
new Author[] = "Sanji"

new sprSmoke
new sprFlare6
new sprLgtning
new sprBflare
new sprRflare
new sprGflare
new sprTflare
new sprOflare
new sprPflare
new sprYflare

new has_rocket = 0
new has_drop = 0

new fPlayer[33] = {0,...}

public fireworks_think() {
        new iCurrent
        new temp
        new Float:vVelocity[3]
        new Float:vNormal[3]
        new Float:vOrigin[3]
        new Float:vTraceStart[3]
        new Float:vTraceEnd[3]
        new stat,stat2,c1[128]
        new life
        new id

        new Float:fmin,Float:fmax,Float:fxy
        fmin = get_cvar_float("fireworks_velocity_min")
        fmax = get_cvar_float("fireworks_velocity_max")
        fxy = get_cvar_float("fireworks_velocity_xy")

        iCurrent = FindEntity(-1, "fly_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "fly_fireworks")
                life = Entvars_Get_Int(temp,EV_INT_iuser1)
                life--
                Entvars_Set_Int(temp,EV_INT_iuser1,life)
                vVelocity[0] = random_float(-fxy,fxy)
                vVelocity[1] = random_float(-fxy,fxy)
                vVelocity[2] = random_float(fmin,fmax)
                Entvars_Set_Vector(temp,EV_VEC_velocity,vVelocity)
                Entvars_Get_Vector(temp,EV_VEC_origin,vOrigin)
                id = Entvars_Get_Edict(temp,EV_ENT_owner)
                vTraceStart[0] = vOrigin[0]
                vTraceStart[1] = vOrigin[1]
                vTraceStart[2] = vOrigin[2] - 1.0
                vTraceEnd[0] = vOrigin[0]
                vTraceEnd[1] = vOrigin[1]
                vTraceEnd[2] = vOrigin[2] + 5.0
                stat2 = TraceLn(temp, vTraceStart, vTraceEnd, vNormal)
                stat = TraceNormal(temp, vTraceStart, vTraceEnd, vNormal)
                if (stat != 0) {
                        if (is_entity(stat2)) {
                                Entvars_Get_String(stat2,EV_SZ_classname,c1,siz
eof(c1))
                                if (!equali("fly_fireworks",c1) && !equali("nrm
_fireworks",c1) && !equali("player",c1)) {
                                        explode(temp)
                                        if (id != 0) {
                                                fPlayer[id]--
                                        }
                                }
                        } else {
                                explode(temp)
                                if (id != 0) {
                                        fPlayer[id]--
                                }
                        }
                } else {
                        if (life <= 0) {
                                explode(temp)
                                if (id != 0) {
                                        fPlayer[id]--
                                }
                        }
                }
        }
}

public shooter_think() {
        new iCurrent
        new temp
        new Float:vVelocity[3]
        new Float:Origin[3]
        new Float:Angles[3]
        new Float:Mins[3] = {-2.0, -2.0, -1.0}
        new Float:Maxs[3] = {2.0, 2.0, 12.0}
        new r,g,b
        new count

        iCurrent = FindEntity(-1, "shooter_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "shooter_fireworks")
                count = Entvars_Get_Int(temp,EV_INT_iuser1)
                if (count <= 0) {
                        RemoveEntity(temp)
                        continue
                }
                count--
                Entvars_Set_Int(temp,EV_INT_iuser1,count)
                Entvars_Get_Vector(temp,EV_VEC_origin,Origin)
                Angles[0] = 90.0
                Angles[1] = random_float(0.0,360.0)
                Angles[2] = 0.0
                Origin[2] += 18.0
                new Ent = CreateEntity("info_target")
                if (Ent) {
                        Entvars_Set_String(Ent,EV_SZ_classname,"fly_fireworks")
                        Entvars_Set_Vector(Ent,EV_VEC_origin,Origin)
                        Entvars_Set_Vector(Ent,EV_VEC_angles,Angles)
                        Entvars_Set_Vector(Ent,EV_VEC_mins,Mins)
                        Entvars_Set_Vector(Ent,EV_VEC_maxs,Maxs)
                        Entvars_Set_Int(Ent,EV_INT_solid,2)
                        Entvars_Set_Int(Ent,EV_INT_movetype,6)
                        ENT_SetModel(Ent,"models/rpgrocket.mdl")
                        if (get_cvar_num("fireworks_colortype")) {
                                switch(random_num(0,6)) {
                                        case 0: {
                                                r = 255
                                                g = 0
                                                b = 0
                                        }
                                        case 1: {
                                                r = 0
                                                g = 255
                                                b = 0
                                        }
                                        case 2: {
                                                r = 0
                                                g = 0
                                                b = 255
                                        }
                                        case 3: {
                                                r = 0
                                                g = 255
                                                b = 255
                                        }
                                        case 4: {
                                                r = 255
                                                g = 0
                                                b = 255
                                        }
                                        case 5: {
                                                r = 255
                                                g = 255
                                                b = 0
                                        }
                                        case 6: {
                                                r = 255
                                                g = 128
                                                b = 0
                                        }
                                }
                        } else {
                                r = random_num(0,255)
                                g = random_num(0,255)
                                b = random_num(0,255)
                        }
                        Entvars_Set_Int(Ent,EV_INT_iuser1,get_cvar_num("firewor
ks_maxlife"))
                        Entvars_Set_Int(Ent,EV_INT_iuser2,r)
                        Entvars_Set_Int(Ent,EV_INT_iuser3,g)
                        Entvars_Set_Int(Ent,EV_INT_iuser4,b)
                        Entvars_Set_Int(Ent,EV_INT_effects,64)

                        emit_sound(Ent, CHAN_WEAPON, "weapons/rocketfire1.wav",
 1.0, ATTN_NORM, 0, PITCH_NORM)

                        if (has_rocket)
                                emit_sound(Ent, CHAN_VOICE, "fireworks/rocket1.
wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
                        else
                                emit_sound(Ent, CHAN_VOICE, "weapons/rocket1.wa
v", 1.0, ATTN_NORM, 0, PITCH_NORM)

                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(22)
                        write_short(Ent)
                        write_short(sprSmoke)
                        write_byte(45)
                        write_byte(4)
                        write_byte(r)
                        write_byte(g)
                        write_byte(b)
                        write_byte(255)
                        message_end()
                        Entvars_Get_Vector(Ent,EV_VEC_velocity,vVelocity)
                        vVelocity[0] = random_float(-150.0,150.0)
                        vVelocity[1] = random_float(-150.0,150.0)
                        Entvars_Set_Vector(Ent,EV_VEC_velocity,vVelocity)
                }
        }
}

public fireworks_spawn(id,level,cid) {
        new fenable = get_cvar_num("fireworks_enable")
        if (fenable == 1) {
                if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                        return PLUGIN_HANDLED
                }
                if (fPlayer[id] > (get_cvar_num("fireworks_maxcount")-1)) {
                        return PLUGIN_HANDLED
                }
        } else if (fenable == 2) {
                if (fPlayer[id] > (get_cvar_num("fireworks_maxcount")-1)) {
                        return PLUGIN_HANDLED
                }
        } else {
                return PLUGIN_HANDLED
        }

        new Float:Return[3]
        new Float:Origin[3]
        new Float:Angles[3]
        Angles[0] = 90.0
        Angles[1] = random_float(0.0,360.0)
        Angles[2] = 0.0
        VelocityByAim(id,64,Return)
        Entvars_Get_Vector(id,EV_VEC_origin,Origin)
        Origin[0] += Return[0]
        Origin[1] += Return[1]
        Origin[2] += Return[2]
        new Float:Mins[3] = {-2.0, -2.0, -1.0}
        new Float:Maxs[3] = {2.0, 2.0, 12.0}
        new r,g,b

        new Ent = CreateEntity("info_target")
        if (Ent) {
                fPlayer[id]++
                Entvars_Set_String(Ent,EV_SZ_classname,"nrm_fireworks")
                Entvars_Set_Vector(Ent,EV_VEC_mins,Mins)
                Entvars_Set_Vector(Ent,EV_VEC_maxs,Maxs)
                Entvars_Set_Vector(Ent,EV_VEC_origin,Origin)
                Entvars_Set_Vector(Ent,EV_VEC_angles,Angles)
                Entvars_Set_Edict(Ent,EV_ENT_owner,id)
                Entvars_Set_Int(Ent,EV_INT_solid,2)
                Entvars_Set_Int(Ent,EV_INT_movetype,6)
                ENT_SetModel(Ent,"models/rpgrocket.mdl")
                if (get_cvar_num("fireworks_colortype")) {
                        switch(random_num(0,6)) {
                                case 0: {
                                        r = 255
                                        g = 0
                                        b = 0
                                }
                                case 1: {
                                        r = 0
                                        g = 255
                                        b = 0
                                }
                                case 2: {
                                        r = 0
                                        g = 0
                                        b = 255
                                }
                                case 3: {
                                        r = 0
                                        g = 255
                                        b = 255
                                }
                                case 4: {
                                        r = 255
                                        g = 0
                                        b = 255
                                }
                                case 5: {
                                        r = 255
                                        g = 255
                                        b = 0
                                }
                                case 6: {
                                        r = 255
                                        g = 128
                                        b = 0
                                }
                        }
                } else {
                        r = random_num(0,255)
                        g = random_num(0,255)
                        b = random_num(0,255)
                }
                set_rendering(Ent,kRenderFxGlowShell,r,g,b,kRenderNormal,20)
                Entvars_Set_Int(Ent,EV_INT_iuser2,r)
                Entvars_Set_Int(Ent,EV_INT_iuser3,g)
                Entvars_Set_Int(Ent,EV_INT_iuser4,b)
                if (has_drop)
                        emit_sound(Ent, CHAN_WEAPON, "fireworks/weapondrop1.wav
", 1.0, ATTN_NORM, 0, PITCH_NORM)
                else
                        emit_sound(Ent, CHAN_WEAPON, "items/weapondrop1.wav", 1
.0, ATTN_NORM, 0, PITCH_NORM)
        }

        return PLUGIN_HANDLED
}

public fireworks_spawn_rgb(id,level,cid) {
        new fenable = get_cvar_num("fireworks_enable")
        if (fenable == 1) {
                if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                        return PLUGIN_HANDLED
                }
                if (fPlayer[id] > (get_cvar_num("fireworks_maxcount")-1)) {
                        return PLUGIN_HANDLED
                }
        } else if (fenable == 2) {
                if (fPlayer[id] > (get_cvar_num("fireworks_maxcount")-1)) {
                        return PLUGIN_HANDLED
                }
        } else {
                return PLUGIN_HANDLED
        }

        if (read_argc() < 4) {
                console_print(id, "Usage:  fireworks_spawn_rgb <r> <g> <b>")
                return PLUGIN_HANDLED
        }

        new Float:Return[3]
        new Float:Origin[3]
        new Float:Angles[3]
        Angles[0] = 90.0
        Angles[1] = random_float(0.0,360.0)
        Angles[2] = 0.0
        VelocityByAim(id,64,Return)
        Entvars_Get_Vector(id,EV_VEC_origin,Origin)
        Origin[0] += Return[0]
        Origin[1] += Return[1]
        Origin[2] += Return[2]
        new Float:Mins[3] = {-2.0, -2.0, -1.0}
        new Float:Maxs[3] = {2.0, 2.0, 12.0}
        new sr[8],sg[8],sb[8]
        new r,g,b
        read_argv(1,sr,sizeof(sr))
        read_argv(2,sg,sizeof(sg))
        read_argv(3,sb,sizeof(sb))
        r = strtonum(sr)
        g = strtonum(sg)
        b = strtonum(sb)

        new Ent = CreateEntity("info_target")
        if (Ent) {
                fPlayer[id]++
                Entvars_Set_String(Ent,EV_SZ_classname,"nrm_fireworks")
                Entvars_Set_Vector(Ent,EV_VEC_mins,Mins)
                Entvars_Set_Vector(Ent,EV_VEC_maxs,Maxs)
                Entvars_Set_Vector(Ent,EV_VEC_origin,Origin)
                Entvars_Set_Vector(Ent,EV_VEC_angles,Angles)
                Entvars_Set_Edict(Ent,EV_ENT_owner,id)
                Entvars_Set_Int(Ent,EV_INT_solid,2)
                Entvars_Set_Int(Ent,EV_INT_movetype,6)
                ENT_SetModel(Ent,"models/rpgrocket.mdl")
                set_rendering(Ent,kRenderFxGlowShell,r,g,b,kRenderNormal,20)
                Entvars_Set_Int(Ent,EV_INT_iuser2,r)
                Entvars_Set_Int(Ent,EV_INT_iuser3,g)
                Entvars_Set_Int(Ent,EV_INT_iuser4,b)
                if (has_drop)
                        emit_sound(Ent, CHAN_WEAPON, "fireworks/weapondrop1.wav
", 1.0, ATTN_NORM, 0, PITCH_NORM)
                else
                        emit_sound(Ent, CHAN_WEAPON, "items/weapondrop1.wav", 1
.0, ATTN_NORM, 0, PITCH_NORM)
        }

        return PLUGIN_HANDLED
}

public fireworks_shoot(id,level,cid) {
        new Owner
        new r,g,b
        new iCurrent
        new iCurrent2
        new Float:vVelocity[3]
        new temp

        iCurrent2 = FindEntity(-1, "fly_fireworks")

        while (iCurrent2 != -1) {
                temp = iCurrent2
                iCurrent2 = FindEntity(iCurrent2, "fly_fireworks")
                Owner = Entvars_Get_Edict(temp,EV_ENT_owner)
                if (Owner == id) {
                        explode(temp)
                        fPlayer[id]--
                }
        }

        iCurrent = FindEntity(-1, "nrm_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "nrm_fireworks")
                Owner = Entvars_Get_Edict(temp,EV_ENT_owner)
                if (Owner == id) {
                        Entvars_Set_String(temp,EV_SZ_classname,"fly_fireworks"
)
                        Entvars_Set_Int(temp,EV_INT_effects,64)

                        emit_sound(temp, CHAN_WEAPON, "weapons/rocketfire1.wav"
, 1.0, ATTN_NORM, 0, PITCH_NORM)

                        if (has_rocket)
                                emit_sound(temp, CHAN_VOICE, "fireworks/rocket1
.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
                        else
                                emit_sound(temp, CHAN_VOICE, "weapons/rocket1.w
av", 1.0, ATTN_NORM, 0, PITCH_NORM)

                        r = Entvars_Get_Int(temp,EV_INT_iuser2)
                        g = Entvars_Get_Int(temp,EV_INT_iuser3)
                        b = Entvars_Get_Int(temp,EV_INT_iuser4)
                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(22)
                        write_short(temp)
                        write_short(sprSmoke)
                        write_byte(45)
                        write_byte(4)
                        write_byte(r)
                        write_byte(g)
                        write_byte(b)
                        write_byte(255)
                        message_end()
                        Entvars_Set_Int(temp,EV_INT_iuser1,get_cvar_num("firewo
rks_maxlife"))
                        Entvars_Get_Vector(temp,EV_VEC_velocity,vVelocity)
                        vVelocity[0] = random_float(-150.0,150.0)
                        vVelocity[1] = random_float(-150.0,150.0)
                        Entvars_Set_Vector(temp,EV_VEC_velocity,vVelocity)
                }
        }

        return PLUGIN_HANDLED
}

public admin_createshooter(id,level,cid) {
        if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                console_print(id, "[AMX] You have no access to that command")
                return PLUGIN_HANDLED
        }

        new Float:Return[3]
        new Float:Origin[3]
        VelocityByAim(id,64,Return)
        Entvars_Get_Vector(id,EV_VEC_origin,Origin)
        Origin[0] += Return[0]
        Origin[1] += Return[1]
        Origin[2] += Return[2]
        new Float:Angles[3]
        Angles[0] = 0.0
        Angles[1] = random_float(0.0,360.0)
        Angles[2] = 0.0
        new Float:Mins[3] = {-6.0, -6.0, -6.0}
        new Float:Maxs[3] = {1.0, 1.0, 10.0}
        new sr[8]
        new r

        new Ent = CreateEntity("info_target")
        if (Ent) {
                Entvars_Set_String(Ent,EV_SZ_classname,"shooter_fireworks")
                Entvars_Set_Vector(Ent,EV_VEC_origin,Origin)
                Entvars_Set_Vector(Ent,EV_VEC_angles,Angles)
                Entvars_Set_Edict(Ent,EV_ENT_owner,id)
                Entvars_Set_Int(Ent,EV_INT_solid,2)
                Entvars_Set_Int(Ent,EV_INT_movetype,6)
                if (read_argc() < 2) {
                        Entvars_Set_Int(Ent,EV_INT_iuser1,get_cvar_num("firewor
ks_maxcount"))
                } else {
                        read_argv(1,sr,sizeof(sr))
                        r = strtonum(sr)
                        Entvars_Set_Int(Ent,EV_INT_iuser1,r)
                }
                ENT_SetModel(Ent,"models/w_rpgammo.mdl")
                Entvars_Set_Vector(Ent,EV_VEC_mins,Mins)
                Entvars_Set_Vector(Ent,EV_VEC_maxs,Maxs)
        }

        return PLUGIN_HANDLED
}

public admin_removeshooter(id,level,cid) {
        if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                console_print(id, "[AMX] You have no access to that command")
                return PLUGIN_HANDLED
        }

        new temp
        new iCurrent = FindEntity(-1, "shooter_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "shooter_fireworks")
                RemoveEntity(temp)
        }

        return PLUGIN_HANDLED
}

public admin_remover(id,level,cid) {
        if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                console_print(id, "[AMX] You have no access to that command")
                return PLUGIN_HANDLED
        }

        new temp

        new iCurrent = FindEntity(-1, "nrm_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "nrm_fireworks")
                RemoveEntity(temp)

        }

        new iCurrent2 = FindEntity(-1, "fly_fireworks")

        while (iCurrent2 != -1) {
                temp = iCurrent2
                iCurrent2 = FindEntity(iCurrent2, "fly_fireworks")
                RemoveEntity(temp)

        }

        for (new i = 0; i <= 32; i++)
                fPlayer[i] = 0

        return PLUGIN_HANDLED
}

public admin_shoot(id,level,cid) {
        if (!(get_user_flags(id)&ADMIN_LEVEL_H)) {
                console_print(id, "[AMX] You have no access to that command")
                return PLUGIN_HANDLED
        }

        new Owner
        new r,g,b
        new iCurrent
        new iCurrent2
        new Float:vVelocity[3]
        new temp

        iCurrent2 = FindEntity(-1, "fly_fireworks")

        while (iCurrent2 != -1) {
                temp = iCurrent2
                iCurrent2 = FindEntity(iCurrent2, "fly_fireworks")
                Owner = Entvars_Get_Edict(temp,EV_ENT_owner)
                if (Owner != 0) {
                        explode(temp)
                        fPlayer[id]--
                }
        }

        iCurrent = FindEntity(-1, "nrm_fireworks")

        while (iCurrent != -1) {
                Owner = Entvars_Get_Edict(iCurrent,EV_ENT_owner)
                if (Owner != 0) {
                        Entvars_Set_String(iCurrent,EV_SZ_classname,"fly_firewo
rks")
                        Entvars_Set_Int(iCurrent,EV_INT_effects,64)

                        emit_sound(iCurrent, CHAN_WEAPON, "weapons/rocketfire1.
wav", 1.0, ATTN_NORM, 0, PITCH_NORM)

                        if (has_rocket)
                                emit_sound(iCurrent, CHAN_VOICE, "fireworks/roc
ket1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
                        else
                                emit_sound(iCurrent, CHAN_VOICE, "weapons/rocke
t1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)

                        r = Entvars_Get_Int(iCurrent,EV_INT_iuser2)
                        g = Entvars_Get_Int(iCurrent,EV_INT_iuser3)
                        b = Entvars_Get_Int(iCurrent,EV_INT_iuser4)
                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(22)
                        write_short(iCurrent)
                        write_short(sprSmoke)
                        write_byte(45)
                        write_byte(4)
                        write_byte(r)
                        write_byte(g)
                        write_byte(b)
                        write_byte(255)
                        message_end()
                        Entvars_Set_Int(iCurrent,EV_INT_iuser1,get_cvar_num("fi
reworks_maxlife"))
                        Entvars_Get_Vector(iCurrent,EV_VEC_velocity,vVelocity)
                        vVelocity[0] = random_float(-150.0,150.0)
                        vVelocity[1] = random_float(-150.0,150.0)
                        Entvars_Set_Vector(iCurrent,EV_VEC_velocity,vVelocity)
                }
                iCurrent = FindEntity(iCurrent, "nrm_fireworks")
        }

        return PLUGIN_HANDLED
}

explode(id) {
        new Float:Origin[3]
        Entvars_Get_Vector(id,EV_VEC_origin,Origin)
        new szType[64],type
        get_cvar_string("fireworks_effect",szType,sizeof(szType))
        type = read_flags(szType)
        new r = Entvars_Get_Int(id,EV_INT_iuser2)
        new g = Entvars_Get_Int(id,EV_INT_iuser3)
        new b = Entvars_Get_Int(id,EV_INT_iuser4)

        if (type&(1<<0)) { //a
                message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
                write_byte(20)                          // TE_BEAMDISK
                write_coord(floatround(Origin[0]))                      // coor
d coord coord (center position)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]))
                write_coord(floatround(Origin[0]))                      // coor
d coord coord (axis and radius)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]+random_float(250.0,750.0)))
                switch(random_num(0,1)) {
                        case 0: write_short(sprFlare6)                  // shor
t (sprite index)
                        case 1: write_short(sprLgtning)                 // shor
t (sprite index)
                }
                write_byte(0)                           // byte (starting frame
)
                write_byte(0)                           // byte (frame rate in 
0.1's)
                write_byte(45)                          // byte (life in 0.1's)
                write_byte(150)                         // byte (line width in 
0.1's)
                write_byte(0)                           // byte (noise amplitud
e in 0.01's)
                write_byte(r)                           // byte,byte,byte (colo
r)
                write_byte(g)
                write_byte(b)
                write_byte(255)                         // byte (brightness)
                write_byte(0)                           // byte (scroll speed i
n 0.1's)
                message_end()
        }
        if (type&(1<<1) && get_cvar_num("fireworks_colortype")) { //b
                message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
                write_byte(15)                          // TE_SPRITETRAIL
                write_coord(floatround(Origin[0]))                      // coor
d, coord, coord (start)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]-20.0))
                write_coord(floatround(Origin[0]))                      // coor
d, coord, coord (end)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]+20.0))
                if ((r == 255) && (g == 0) && (b == 0)) {
                        write_short(sprRflare)
                } else if ((r == 0) && (g == 255) && (b == 0)) {
                        write_short(sprGflare)
                } else if ((r == 0) && (g == 0) && (b == 255)) {
                        write_short(sprBflare)
                } else if ((r == 0) && (g == 255) && (b == 255)) {
                        write_short(sprTflare)
                } else if ((r == 255) && (g == 0) && (b == 255)) {
                        write_short(sprPflare)
                } else if ((r == 255) && (g == 255) && (b == 0)) {
                        write_short(sprYflare)
                } else if ((r == 255) && (g == 128) && (b == 0)) {
                        write_short(sprOflare)
                } else {
                        write_short(sprBflare)
                }
                write_byte(get_cvar_num("fireworks_flare_count"))       
                // byte (count)
                write_byte(10)                          // byte (life in 0.1's)
                write_byte(10)                          // byte (scale in 0.1's
)
                write_byte(random_num(40,100))          // byte (velocity along
 vector in 10's)
                write_byte(40)                          // byte (randomness of 
velocity in 10's)
                message_end()
        }
        if (type&(1<<2)) { //c
                message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
                write_byte(4)
                write_coord(floatround(Origin[0]))                      // coor
d, coord, coord (start)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]))
                message_end()
        }
        if (type&(1<<3)) { //d
                message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
                write_byte(122)
                write_coord(floatround(Origin[0]))                      // coor
d, coord, coord (start)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]))
                write_short(random_num(400,1000))
                write_byte(random_num(0,255))
                write_byte(40)
                message_end()
        }
        if (type&(1<<4)) { //e
                message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
                write_byte(27)
                write_coord(floatround(Origin[0]))                      // coor
d, coord, coord (start)
                write_coord(floatround(Origin[1]))
                write_coord(floatround(Origin[2]))
                write_byte(60)                  // byte (radius in 10's) 
                write_byte(r)                   // byte byte byte (color)
                write_byte(g)
                write_byte(b)
                write_byte(100)                 // byte (life in 10's)
                write_byte(15)                  // byte (decay rate in 10's)
                message_end()
        }

        if (type&(1<<25)) { //z
                emit_sound(id, CHAN_VOICE, "weapons/mortarhit.wav", 1.0, ATTN_N
ORM, 0, PITCH_NORM)
        }

        RemoveEntity(id)
}

public client_disconnect(id) {
        new Owner
        new temp

        new iCurrent2 = FindEntity(-1, "fly_fireworks")

        while (iCurrent2 != -1) {
                temp = iCurrent2
                iCurrent2 = FindEntity(iCurrent2, "fly_fireworks")
                Owner = Entvars_Get_Edict(temp,EV_ENT_owner)
                if (Owner == id) {
                        RemoveEntity(temp)
                }
        }

        new iCurrent = FindEntity(-1, "nrm_fireworks")

        while (iCurrent != -1) {
                temp = iCurrent
                iCurrent = FindEntity(iCurrent, "nrm_fireworks")
                Owner = Entvars_Get_Edict(iCurrent,EV_ENT_owner)
                if (Owner == id) {
                        RemoveEntity(temp)
                }
        }

        fPlayer[id] = 0
}

public plugin_precache() {
        precache_sound("weapons/rocketfire1.wav")
        precache_sound("weapons/mortarhit.wav")

        if (file_exists("sound/fireworks/rocket1.wav")) {
                precache_sound("fireworks/rocket1.wav")
                has_rocket = 1
        } else {
                precache_sound("weapons/rocket1.wav")
                has_rocket = 0
        }

        if (file_exists("sound/fireworks/weapondrop1.wav")) {
                precache_sound("fireworks/weapondrop1.wav")
                has_drop = 1
        } else {
                precache_sound("items/weapondrop1.wav")
                has_drop = 0
        }

        precache_model("models/rpgrocket.mdl")
        precache_model("models/w_rpgammo.mdl")

        sprSmoke = precache_model("sprites/smoke.spr")
        sprFlare6 = precache_model("sprites/flare6.spr")
        sprLgtning = precache_model("sprites/lgtning.spr")

        sprBflare = precache_model("sprites/fireworks/bflare.spr")
        sprRflare = precache_model("sprites/fireworks/rflare.spr")
        sprGflare = precache_model("sprites/fireworks/gflare.spr")
        sprTflare = precache_model("sprites/fireworks/tflare.spr")
        sprOflare = precache_model("sprites/fireworks/oflare.spr")
        sprPflare = precache_model("sprites/fireworks/pflare.spr")
        sprYflare = precache_model("sprites/fireworks/yflare.spr")

        return PLUGIN_CONTINUE
}

public plugin_init() {
        register_plugin(Title,Version,Author)

        set_task(0.1, "fireworks_think", 21, "", 0, "b")
        set_task(0.3, "shooter_think", 21, "", 0, "b")

        register_concmd("fireworks_spawn","fireworks_spawn")
        register_concmd("fireworks_spawn_rgb","fireworks_spawn_rgb")
        register_concmd("fireworks_shoot","fireworks_shoot")

        register_concmd("amx_create_shooter","admin_createshooter",ADMIN_LEVEL_
H)
        register_concmd("amx_remove_shooter","admin_removeshooter",ADMIN_LEVEL_
H)
        register_concmd("amx_remove_rockets","admin_remover",ADMIN_LEVEL_H)
        register_concmd("amx_shoot_rockets","admin_shoot",ADMIN_LEVEL_H)

        if (!cvar_exists("fireworks_enable"))
                register_cvar("fireworks_enable","1",FCVAR_SERVER)
        if (!cvar_exists("fireworks_maxlife"))
                register_cvar("fireworks_maxlife","20",FCVAR_SERVER)
        if (!cvar_exists("fireworks_flare_count"))
                register_cvar("fireworks_flare_count","30",FCVAR_SERVER)
        if (!cvar_exists("fireworks_maxcount"))
                register_cvar("fireworks_maxcount","16",FCVAR_SERVER)
        if (!cvar_exists("fireworks_effect"))
                register_cvar("fireworks_effect","abez",FCVAR_SERVER)
        if (!cvar_exists("fireworks_velocity_min"))
                register_cvar("fireworks_velocity_min","1800.0",FCVAR_SERVER)
        if (!cvar_exists("fireworks_velocity_max"))
                register_cvar("fireworks_velocity_max","2000.0",FCVAR_SERVER)
        if (!cvar_exists("fireworks_velocity_xy"))
                register_cvar("fireworks_velocity_xy","100.0",FCVAR_SERVER)
        if (!cvar_exists("fireworks_colortype"))
                register_cvar("fireworks_colortype","1",FCVAR_SERVER)

        register_cvar("fireworks_version",Version,FCVAR_SERVER|FCVAR_EXTDLL|FCV
AR_UNLOGGED|FCVAR_SPONLY)

        return PLUGIN_CONTINUE
}
