Raised This Month: $51 Target: $400
 12% 

Set the flare light color depending on the player team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 05-13-2017 , 08:51   Set the flare light color depending on the player team
Reply With Quote #1

If Ct throw flare they should emit blue color,if Ts throw they should emit red color.
So I set this and work,but I wonder is this a good way to do this?

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta>
#include <hamsandwich>
#include <fun>
#include <xs>

#define pev_flare pev_iuser4

#define flare_id 1337

#define is_ent_flare(%1) (pev(%1, pev_flare) == flare_id) ? 1 : 0

new const explosive_flare_model[] = "models/w_smokegrenade.mdl"

const Float:FLARE_EXPLOSION_DAMAGE 65.0
const Float:FLARE_EXPLOSION_RADIUS 270.0
const Float:FLARE_DAMAGE_MULTI 1.0
const DMG_HEGRENADE = (1<<24)

new 
explosive_sprite2explosive_sprite

public plugin_precache() 
{
    
precache_model(explosive_flare_model)
        
explosive_sprite precache_model("sprites/flare_exp_1.spr")
        
explosive_sprite2 precache_model("sprites/flare_exp_2.spr")
}

public 
plugin_init()
{
    
register_plugin("[ZP]Explosive Flare""1.0""[Half-Life] Biohazard")

    
register_forward(FM_SetModel"explosive_model_stuff")
    
    
register_forward(FM_Think"explosive_think")
}

public 
explosive_model_stuff(ent, const model[]) 
{
    if(!
pev_valid(ent) || !equal(model[9], "smokegrenade.mdl"))
        return 
FMRES_IGNORED

    
static Float:light_origin[3]  

    
pev(ent,pev_origin,light_origin)

    static 
classname[32]; pev(entpev_classnameclassname31)

    if(
equal(classname"grenade"))
    {
        
engfunc(EngFunc_SetModelentexplosive_flare_model)

        
set_task(0.1"make_flare_flash"ent)

                
set_task(4.0"make_flare_explode"ent)

        
set_pev(entpev_flare,   flare_id)

        
set_pev(entpev_nextthinkget_gametime() + 199)
        
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

public 
make_flare_flash(ent
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED

    
static Float:light_origin[3
 
    
pev(ent,pev_origin,light_origin)

    static 
classname[32]; pev(entpev_classnameclassname31)

    if(
equal(classname"grenade"))
        {
        
engfunc(EngFunc_SetModelentexplosive_flare_model)
        
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        
write_byte(27
        
engfunc(EngFunc_WriteCoord,light_origin[0]) 
        
engfunc(EngFunc_WriteCoord,light_origin[1]) 
        
engfunc(EngFunc_WriteCoord,light_origin[2]) 
        
write_byte(22)    // radius
        
write_byte(237// r
            
write_byte(247// g
            
write_byte(35// b
        
write_byte(3)     // life
        
write_byte(0)    // rate
        
message_end()
        
set_task(0.1,"make_flare_flash",ent);
        
        return 
FMRES_SUPERCEDE
        
}
    return 
FMRES_IGNORED
}

public 
make_flare_explode(ent)
{
    if(!
pev_valid(ent))
            return

     new 
Float:atkOrigin[3]

     
pev(entpev_originatkOrigin)

     static 
classname[32]; pev(entpev_classnameclassname31)

     if(
equal(classname"grenade"))
     {     
    
engfunc(EngFunc_MessageBeginMSG_PASSVC_TEMPENTITYatkOrigin0)
    
write_byte(TE_EXPLOSION)
    
engfunc(EngFunc_WriteCoordatkOrigin[0])
    
engfunc(EngFunc_WriteCoordatkOrigin[1])
    
engfunc(EngFunc_WriteCoordatkOrigin[2] + 50.0)
    
write_short(explosive_sprite)
    
write_byte(15)
    
write_byte(15)
        
write_byte(10)
    
message_end()

        
message_begin (MSG_BROADCAST,SVC_TEMPENTITY)
        
write_byteTE_SPRITETRAIL 
        
engfunc(EngFunc_WriteCoordatkOrigin]) 
        
engfunc(EngFunc_WriteCoordatkOrigin])
        
engfunc(EngFunc_WriteCoordatkOrigin] + 200.0)
        
engfunc(EngFunc_WriteCoordatkOrigin]) 
        
engfunc(EngFunc_WriteCoordatkOrigin])
        
engfunc(EngFunc_WriteCoordatkOrigin] + 30.0)
        
write_short(explosive_sprite2
        
write_byte(20
        
write_byte(random_num(1,2)) 
        
write_byte(2
        
write_byte(15
        
write_byte(2
        
message_end() 

        
set_task(4.0"make_flare_explode"ent)
     }
                               
     new 
attacker pev(entpev_owner)

     if(!
is_user_connected(attacker))
     {
        
engfunc(EngFunc_RemoveEntityent)
        return
     }
    
     new 
victim = -1
    
     
while((victim engfunc(EngFunc_FindEntityInSpherevictimatkOriginFLARE_EXPLOSION_RADIUS)) != 0)
     {     
        if(!
is_user_alive(victim)) continue;
        
        new 
Float:fOrigin[3], Float:fDistanceFloat:fDamage

        pev
(victimpev_originfOrigin)

        
fDistance get_distance_f(fOriginatkOrigin)

        
fDamage FLARE_EXPLOSION_DAMAGE floatmul(FLARE_EXPLOSION_DAMAGEfloatdiv(fDistanceFLARE_EXPLOSION_RADIUS))

        
fDamage *= 1.0

        
if(fDamage 1.0) continue;
        
        
xs_vec_sub(fOriginatkOriginfOrigin)

        
xs_vec_mul_scalar(fOriginfDamage*FLARE_DAMAGE_MULTIfOrigin)

        
xs_vec_mul_scalar(fOriginFLARE_EXPLOSION_DAMAGE xs_vec_len(fOrigin), fOrigin)

        
set_pev(victimpev_velocityfOrigin)
        
        
ExecuteHamB(Ham_TakeDamagevictimentattackerfDamageDMG_HEGRENADE)
     }
}

public 
explosive_think(ent
{
      if(
pev_valid(ent) && is_ent_flare(ent))
      {
      
engfunc(EngFunc_RemoveEntityent)
      }

PHP Code:
if(cs_get_user_team(id) == CS_TEAM_CT)
            {
        
engfunc(EngFunc_SetModelentexplosive_flare_model)
        
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        
write_byte(27
        
engfunc(EngFunc_WriteCoord,light_origin[0]) 
        
engfunc(EngFunc_WriteCoord,light_origin[1]) 
        
engfunc(EngFunc_WriteCoord,light_origin[2]) 
        
write_byte(30)    // radius
        
write_byte(0// r
            
write_byte(0// g
            
write_byte(160// b
        
write_byte(3)     // life
        
write_byte(0)    // rate
        
message_end()

        
set_task(0.1,"make_flare_flash",ent)
    
           }
           else
           {
                
engfunc(EngFunc_SetModelentexplosive_flare_model)
        
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        
write_byte(27
        
engfunc(EngFunc_WriteCoord,light_origin[0]) 
        
engfunc(EngFunc_WriteCoord,light_origin[1]) 
        
engfunc(EngFunc_WriteCoord,light_origin[2]) 
        
write_byte(30)    // radius
        
write_byte(250// r
            
write_byte(0// g
            
write_byte(0// b
        
write_byte(3)     // life
        
write_byte(0)    // rate
        
message_end()

        
set_task(0.1,"make_flare_flash",ent)
                
           }
           return 
FMRES_SUPERCEDE 

Last edited by Krtola; 05-13-2017 at 09:03.
Krtola is offline
Send a message via Skype™ to Krtola
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-13-2017 , 09:48   Re: Set the flare light color depending on the player team
Reply With Quote #2

The least you can do is check only the 3 write_byte functions instead of the whole code.

The right way do to it:

PHP Code:
// SPEC, T, CT, SPEC
new const g_iColors[][] = { {000}, {25000}, {00160}, {000} } 
PHP Code:
new CsTeams:iTeam cs_get_user_team(id)

engfunc(EngFunc_SetModelentexplosive_flare_model)
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(27
engfunc(EngFunc_WriteCoord,light_origin[0]) 
engfunc(EngFunc_WriteCoord,light_origin[1]) 
engfunc(EngFunc_WriteCoord,light_origin[2]) 
write_byte(30)    // radius
write_byte(g_iColors[iTeam][0]) // r
write_byte(g_iColors[iTeam][1]) // g
write_byte(g_iColors[iTeam][2]) // b
write_byte(3)     // life
write_byte(0)    // rate
message_end() 
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 05-13-2017 , 12:33   Re: Set the flare light color depending on the player team
Reply With Quote #3

Ok I will test this tomorow.
Krtola is offline
Send a message via Skype™ to Krtola
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 05-14-2017 , 02:08   Re: Set the flare light color depending on the player team
Reply With Quote #4

PHP Code:
write_byte(g_iColors[iTeam][0]) // r
write_byte(g_iColors[iTeam][1]) // g
write_byte(g_iColors[iTeam][2]) // b 
PHP Code:
tag mismatch 
Krtola is offline
Send a message via Skype™ to Krtola
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-14-2017 , 07:23   Re: Set the flare light color depending on the player team
Reply With Quote #5

Use _: to strip the tag from cs_get_user_team()
new iTeam = _:cs_get_user_team(id)
__________________
Black Rose is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 05-15-2017 , 13:59   Re: Set the flare light color depending on the player team
Reply With Quote #6

Eh, faq readability, was in a hurry
PHP Code:
public make_flare_flash(ent)  

    if(!
pev_valid(ent)) 
        return 
FMRES_IGNORED 

    
static Float:light_origin[3]  
  
    
pev(ent,pev_origin,light_origin

    static 
classname[32]; pev(entpev_classnameclassname31

    new 
iOwner pev(entpev_owner)
    new 
iTeam cs_get_user_team(iOwner)

    new 
iColor[3] = iTeam == CS_TEAM_T ? {2550} : iTeam == CS_TEAM_CT ? {00255} : {255255255 }

    
cs_get_user_team(iOwner) == CS_TEAM_T 
    if(
equal(classname"grenade")) 
        { 
        
engfunc(EngFunc_SetModelentexplosive_flare_model
        
message_begin(MSG_BROADCAST,SVC_TEMPENTITY
        
write_byte(27)  
        
engfunc(EngFunc_WriteCoord,light_origin[0])  
        
engfunc(EngFunc_WriteCoord,light_origin[1])  
        
engfunc(EngFunc_WriteCoord,light_origin[2])  
        
write_byte(22)    // radius 
        
write_byte(iColor[0]) // r 
        
write_byte(iColor[1]) // g 
        
write_byte(iColor[2]) // b 
        
write_byte(3)     // life 
        
write_byte(0)    // rate 
        
message_end() 
        
set_task(0.1,"make_flare_flash",ent); 
         
        return 
FMRES_SUPERCEDE 
        

    return 
FMRES_IGNORED 

__________________

Last edited by Depresie; 05-15-2017 at 14:01.
Depresie is offline
Old 05-15-2017, 14:00
Depresie
This message has been deleted by Depresie.
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode