Raised This Month: $ Target: $400
 0% 

First plugin, need feedback


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
2called-chaos
Senior Member
Join Date: Jul 2006
Old 11-10-2013 , 02:37   First plugin, need feedback
Reply With Quote #1

Hey guys,

I just build my first plugin and it works! I know that there is a plugin doing exactly that but I couldn't find it anymore so I thought it would be a good first project

Would bee cool if someone more experienced could tell me if this would be considered good code. I'm normally ruby programmer where everything is an object and pawn doesn't even know the concept. That's also the reason why I did not put in any semicolons

Thanks in advance!

And as I like gists much more because you can comment on lines and stuff: https://gist.github.com/2called-chao...ed2c09f1d3d7e9

Changes I made after feedback: https://gist.github.com/2called-chao...d7e9/revisions

PHP Code:
/*
 *
 *  Author:   2called-chaos
 *  Date:     10-November-2013
 *
 *
 *  Description: "Flashes" user on each spawn or round start with it's team color.
 *               Especially on deathmatch it's sometimes surprising if you got teambalanced.
 *
 *  Cvars:
 *
 *      amx_who2shoot          1    Enable plugin
 *      amx_who2shoot_spawn    1    flash 1 = on every spawn; 0 = only on round start
 *      amx_who2shoot_stay     0.1  Duration layer is shown before fading it out
 *      amx_who2shoot_duration 0.3  Duration of the fade effect in seconds
 *      amx_who2shoot_alpha    150  Max. alpha of the layer (0 = invisible, 255 = solid)
 *
 *
 *  Requirements: AMXModX
 *                cstrike
 *                HamSandwich
 *                Screenfade Util (https://forums.alliedmods.net/showthread.php?t=87623)
 *
 */

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <screenfade_util>

// Layer color CT (R, G, B)
#define CT_LAYER_COLOR_R 110
#define CT_LAYER_COLOR_G 156
#define CT_LAYER_COLOR_B 190

// Layer color T (R, G, B)
#define T_LAYER_COLOR_R 255
#define T_LAYER_COLOR_G 63
#define T_LAYER_COLOR_B 63

// Globals
new g_enabledg_flash_on_spawng_flash_stayg_flash_durationg_flash_alpha
new bool:g_round_started

public plugin_init()
{
    
register_plugin("who2shoot""1.0""2called-chaos")
    
g_round_started true

    
// events
    
register_event("HLTV" "event_new_round" "a" "1=0" "2=0")
    
RegisterHam(Ham_Spawn"player""event_player_spawned"1)
    
register_logevent("reset_round_started"2"1=Round_Start")
    
register_logevent("reset_round_started"2"1=Round_End")

    
// cvars
    
g_enabled        register_cvar("amx_who2shoot""1")
    
g_flash_on_spawn register_cvar("amx_who2shoot_spawn""1")
    
g_flash_stay     register_cvar("amx_who2shoot_stay""0.1")
    
g_flash_duration register_cvar("amx_who2shoot_duration""0.3")
    
g_flash_alpha    register_cvar("amx_who2shoot_alpha""180")
}

// ==========
// = EVENTS =
// ==========

// new round
public event_new_round()
{
    
g_round_started true
    
return PLUGIN_CONTINUE
}

// flash player on spawn
public event_player_spawned(id)
{
    
// plugin disabled
    
if (!get_pcvar_num(g_enabled))
        return 
PLUGIN_CONTINUE

    
// we don't flash on every spawn and round has not been started recently
    
if (!get_pcvar_num(g_flash_on_spawn) && !g_round_started)
        return 
PLUGIN_CONTINUE

    flash_user_with_team_color
(id)
    return 
PLUGIN_CONTINUE
}

// reset round started
public reset_round_started()
{
    
g_round_started false
    
return PLUGIN_CONTINUE
}



// ============
// = FLASHING =
// ============
flash_user_with_team_color(id)
{
    
// plugin disabled
    
if (!get_pcvar_num(g_enabled))
        return 
PLUGIN_CONTINUE

    
// user dead
    
if (!is_user_alive(id))
        return 
PLUGIN_CONTINUE

    
// set color
    
new color[3]
    switch(
cs_get_user_team(id))
    {
        case 
CS_TEAM_T:
        {
            
color[0] = T_LAYER_COLOR_R
            color
[1] = T_LAYER_COLOR_G
            color
[2] = T_LAYER_COLOR_B
        
}

        case 
CS_TEAM_CT:
        {
            
color[0] = CT_LAYER_COLOR_R
            color
[1] = CT_LAYER_COLOR_G
            color
[2] = CT_LAYER_COLOR_B
        
}

        default: 
// Spec or unassigned
            
return PLUGIN_CONTINUE
    
}

    
// actual fade
    
UTIL_ScreenFade(idcolorget_pcvar_float(g_flash_duration), get_pcvar_float(g_flash_stay), get_pcvar_num(g_flash_alpha), FFADE_INtrue)
    return 
PLUGIN_CONTINUE

My next plugin will be a C4 respawner... I block round ends but allow bombs (gungame) and after detonation or defuse one random player (prefer CTs & Bots) gets c4 (and maybe drops it).
__________________


My post was useful? Than klick here, please. Tanks.

Last edited by 2called-chaos; 11-10-2013 at 12:54.
2called-chaos is offline
 


Thread Tools
Display Modes

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 23:17.


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