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

[Req] How to make this code better?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Giass
Member
Join Date: Aug 2011
Location: {Israel}
Old 01-27-2016 , 07:08   [Req] How to make this code better?
Reply With Quote #1

A friend gave me this code, how to make it better?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fun>
#include <cstrike>
#include <fakemeta_util>
#include <hamsandwich>
#include <engine>
#include <ColorChat>

#define PLUGIN "Bomb Game"
#define VERSION "1.0"
#define AUTHOR "/A/"

#define _random(%1) random_num(0, %1 - 1)  
#define TIME 30
#define TASKID 1337
#define    FL_WATERJUMP    (1<<11)    // player jumping out of water
#define    FL_ONGROUND    (1<<9)    // At rest / on the ground
#define BitHideKnife(%1)         ( BitKnife |= ( 1 << ( %1 & 31 ) ) )
#define BitShowKnife(%1)         ( BitKnife &= ~( 1 << ( %1 & 31 ) ) )
#define BitCheckKnife(%1)        ( BitKnife & ( 1 << ( %1 & 31 ) ) )

new iTime
new szName33 ]
new 
Glow
new BitKnife;

new 
gBuyCommands[][] = 
{
     
"usp""glock""deagle""p228""elites""fn57""m3""xm1014""mp5""tmp""p90""mac10""ump45""ak47"
    
"galil""famas""sg552""m4a1""aug""scout""awp""g3sg1""sg550""m249""vest""vesthelm""flash""hegren",
    
"sgren""defuser""nvgs""shield""primammo""secammo""km45""9x19mm""nighthawk""228compact""12gauge",
    
"autoshotgun""smg""mp""c90""cv47""defender""clarion""krieg552""bullpup""magnum""d3au1""krieg550",
    
"buyammo1""buyammo2"


new 
gCvarPluginToggle 

public plugin_init() {
    
register_event("CurWeapon""event_current_weapon""be""1=1")
    
register_logevent("logevent_round_start"2"1=Round_Start")  
    
register_logevent("logevent_round_start1"2"1=Round_Start")  
    
register_logevent("logevent_round_start2"2"1=Round_Start"
    
register_logevent("logevent_round_end"2"1=Round_End"
    
register_forwardFM_PlayerPreThink "fwdPlayerPreThink" )
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
RegisterHamHam_Spawn"player""fwdPlayerSpawn")
    
register_cvar("amx_gamename","BombGame 2.0.0");
         
register_forward(FM_GetGameDescription,"GameDesc");
    
gCvarPluginToggle register_cvar("amx_block_buy""1"
    for (new 
isizeof gBuyCommandsi++)
         
register_clcmd(gBuyCommands[i], "BlockBuyCommands"
    
Glow register_cvar"amx_techno""1" )
    
register_cvar("sbhopper_version""1.2"FCVAR_SERVER)
    
register_cvar("bh_enabled""1")
    
register_cvar("bh_autojump""1")
    
register_cvar("bh_showusage""1")
    
RegisterHamHam_Spawn"player""OnCBasePlayer_Spawn_P", .Post=);
    
RegisterHamHam_Spawn"player""FwdHamPlayerSpawn1"1)
}


public 
plugin_precache(){
    
precache_model("models/lol/v_bomb.mdl")  
    
precache_model("models/lol/Infected.mdl")
}

public 
BlockBuyCommands(id)
{

    if (!
get_pcvar_num(gCvarPluginToggle))
        return 
PLUGIN_CONTINUE;

    return 
PLUGIN_HANDLED;


public 
event_current_weapon(id){
    if (
read_data(2) == CSW_C4){
        
set_pev(idpev_viewmodel2"models/lol/v_bomb.mdl")
    }
    return 
PLUGIN_CONTINUE
}


public 
logevent_round_start(client){
    
    
    
         
iTime TIME
     
      set_task
1.0"countdown"TASKID__"a"TIME )
    
        
set_hudmessage(17900, -1.0, -1.020.021.00.010.110)
        
show_hudmessageclient"Time: 30 Seconds"iTime)
    
        static 
randomplayer
    
    
static players[32], numiid
    get_players
(playersnum"a")
    
    
randomplayer players[_random(num)]
    
    for(
0numi++)
    {
        
id players[i]
        if(
id == randomplayer)    
        {
            new 
userid get_user_userid(id)
        
fm_give_item(id"weapon_c4");
       
get_user_name(useridszNamecharsmax(szName))
       
show_hudmessage(client"%s chosen randomly"szName)
       
ColorChat(clientRED"^03%s Are Infected!"szName)
       if ( 
iTime <= ){
       
client_cmduserid"kill")
}
        }
    }
}  

public 
countdown()
{
    if( 
iTime >= )
    {    
        
iTime--
        
        
set_hudmessage(17900, -1.0, -1.020.021.00.010.110)
        
show_hudmessage0"Time: %i Seconds"iTime )
    
    
    }
}  

public 
fwdPlayerPreThinkid )
{
    if( 
is_user_aliveid ) )
    {
        
set_pevidpev_fuser2 0.0 )
    }


public 
player_spawn(userid){
if(
cs_get_user_team(userid) == CS_TEAM_T ){
           
cs_set_user_model(userid"Infected")
        
    }
    
}

public 
GameDesc()
{
    new 
gamename[32];
    
get_cvar_string("amx_gamename",gamename,31);
    
forward_return(FMV_STRING,gamename);
    return 
FMRES_SUPERCEDE;


public 
fwdPlayerSpawnuserid )
{
     if(
is_user_aliveuserid ) )

     
Glowsuserid )
}

public 
Glowsuserid )
{
     
set_task(3.0"Glows"userid)
     if( 
is_user_aliveuserid ) && get_pcvar_numGlow ) )
     {
             
set_user_rendering(useridkRenderFxGlowShell,  random_num0,255 ),  random_num0,255 ),  random_num0,255 ), kRenderNormal16 )

     }

}

public 
client_PreThink(id) {
    if (!
get_cvar_num("bh_enabled"))
        return 
PLUGIN_CONTINUE

    entity_set_float
(idEV_FL_fuser20.0)        

    if (!
get_cvar_num("bh_autojump"))
        return 
PLUGIN_CONTINUE
    
    
if (entity_get_int(idEV_INT_button) & 2) {    
        new 
flags entity_get_int(idEV_INT_flags)

        if (
flags FL_WATERJUMP)
            return 
PLUGIN_CONTINUE
        
if ( entity_get_int(idEV_INT_waterlevel) >= )
            return 
PLUGIN_CONTINUE
        
if ( !(flags FL_ONGROUND) )
            return 
PLUGIN_CONTINUE

        
new Float:velocity[3]
        
entity_get_vector(idEV_VEC_velocityvelocity)
        
velocity[2] += 250.0
        entity_set_vector
(idEV_VEC_velocityvelocity)

        
entity_set_int(idEV_INT_gaitsequence6)    
    }
    return 
PLUGIN_CONTINUE
}
public 
client_authorized(id)
    
set_task(30.0"showUsage"id)

public 
showUsage(id) {
    if ( !
get_cvar_num("bh_enabled") || !get_cvar_num("bh_showusage") )
        return 
PLUGIN_HANDLED

    
if ( !get_cvar_num("bh_autojump") ) {
        
client_print(idprint_chat"[LoL Bomb Game] Bunny hopping is enabled on this server. You will not slow down after jumping.")
    } else {
        
client_print(idprint_chat"[LoL Bomb Game] Auto bunny hopping is enabled on this server. Just hold down jump to bunny hop.")
    }
    return 
PLUGIN_HANDLED
}

public 
logevent_round_start1(client)
{
    
client_cmd(client,"bh_autojump 1")
    
fm_set_user_health(client100)
}

public 
OnCBasePlayer_Spawn_Pindex )
{
    if( 
is_user_aliveindex ) && get_user_teamindex ) == )
    {
        
BitHideKnifeindex );
        
Ham_StripWeaponindex"weapon_knife" );
    }
}

public 
logevent_round_start2index ){
        if( 
BitCheckKnifeindex ) )
    {
        
BitShowKnifeindex );
        
give_itemindex"weapon_knife" );
    }
    else
    {
        
BitHideKnifeindex );
        
Ham_StripWeaponindex"weapon_knife" );
    }
    return 
PLUGIN_HANDLED;
}

stock Ham_StripWeapon(index,weapon[])
{
    if(!
equal(weapon,"weapon_",7)) return 0;
    
    new 
wId get_weaponid(weapon);
    if(!
wId) return 0;
    
    new 
wEnt;
    while((
wEnt engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != index ) {}
    if(!
wEnt) return 0;
    
    if(
get_user_weaponindex ) == wId
        
ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
    
    if(!
ExecuteHamB(Ham_RemovePlayerItem,index,wEnt) ) return 0;
    
ExecuteHamB(Ham_Item_Kill,wEnt);
    
    
set_pevindex,pev_weapons,pevindex,pev_weapons) & ~(1<<wId));
    
    return 
1;
}  

public 
FwdHamPlayerSpawn1(id){
if(
is_user_alive(id) && is_user_connected(id))
    {
        
fm_set_user_health(id1000)
}

Thanks!
__________________
All you need is carb
Giass is offline
JoaoVieira
Senior Member
Join Date: May 2013
Location: Portugal
Old 01-27-2016 , 07:35   Re: [Req] How to make this code better?
Reply With Quote #2

put this

PHP Code:
#pragma tabsize 0 
its realy ugly see that Loose indentation
JoaoVieira is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-27-2016 , 09:32   Re: [Req] How to make this code better?
Reply With Quote #3

Put this code in amxmodx studio and then at the top find indenter and click on it. Will arange your code and after that copy back to .sma file.
siriusmd99 is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 01-27-2016 , 09:40   Re: [Req] How to make this code better?
Reply With Quote #4

Quote:
Originally Posted by Giass View Post
how to make it better?
By learning scripting yourself, we can't answer to your question so very easy, you need by yourself to learn how to code and add optimization and etc.
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
wickedd
Veteran Member
Join Date: Nov 2009
Old 01-27-2016 , 11:51   Re: [Req] How to make this code better?
Reply With Quote #5

Never copy and paste a plugin together because this is what happens.
PHP Code:
register_logevent("logevent_round_start"2"1=Round_Start")  
register_logevent("logevent_round_start1"2"1=Round_Start")  
register_logevent("logevent_round_start2"2"1=Round_Start"
RegisterHam(Ham_Spawn"player""player_spawn"1)
RegisterHamHam_Spawn"player""fwdPlayerSpawn")
RegisterHamHam_Spawn"player""OnCBasePlayer_Spawn_P", .Post=);
RegisterHamHam_Spawn"player""FwdHamPlayerSpawn1"1
You can start here by hooking player spawn and round start only once.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 01-27-2016 at 11:54.
wickedd is offline
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 05:05.


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