AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Solved ] help with code optimizing (https://forums.alliedmods.net/showthread.php?t=74804)

xPaw 07-25-2008 10:26

[ Solved ] help with code optimizing
 
someone can optimize my code pls ? +karma
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>
#include <colorchat>

/* Night Club
 *     Original from "Advanced Roll The Dice"
 * 
 * (c) Copyright 2008 xPaw.
 * 
 *  Credits:
 * 
 *    Striker        - his "Advanced Roll The Dice"
 *    OpenMind    - Helping ;)
 */

new HasPrize[33][2];
new 
sprBflare;
new 
sprRflare;
new 
sprGflare;
new 
sprTflare;
new 
sprOflare;
new 
sprPflare;
new 
sprYflare;
new 
bool:Nightclub;

public 
plugin_init()
{
    
register_plugin("Night Club","1.6","xPaw");

    
register_clcmd("say /club""nightclub");
    
register_clcmd("say club""nightclub");
    
register_clcmd("say_team /club""nightclub");
    
register_clcmd("say_team club""nightclub");
    
register_clcmd("club""nightclub");

    
register_cvar("sv_club_time""10");
    
register_cvar("sv_club_flare_count""12");
}

public 
plugin_precache()
{
    
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");

    
precache_sound("misc/xPaw/benny1.wav");
    
precache_sound("misc/xPaw/candyshop.mp3");
    
precache_sound("misc/xPaw/crazy.mp3");
    
precache_sound("misc/xPaw/fighter.mp3");
    
precache_sound("misc/xPaw/poppin.mp3");
    
precache_sound("misc/xPaw/vodka.mp3");
    
precache_sound("misc/xPaw/coco.mp3");
    
precache_sound("misc/xPaw/makeit.mp3");
    
    return 
PLUGIN_CONTINUE;
}

public 
nightclub(id)
{
    if(!
is_user_alive(id))
    {
         
ColorChat(idRED"^x01**^x04 Dead people dont go to^x03 Nightclub!")
    }
    if(
Nightclub)
    {
        
ColorChat(idRED"^x01**^x04 Now you cant go to^x03 Nightclub,^x04 try later!"
    }
    else
    {

        new 
rand random_num(1,8);
        new 
User[32], tid[2];
        
get_user_name(id,User,32);
        
HasPrize[id][1] = get_cvar_num("sv_club_time");
        
Nightclub true;
    
        
tid[0] = id;
        
tid[1] = 1;
        
set_task(0.1,"single_knife",0,tid,2,"a",((HasPrize[id][1]+2)*10)-10);
        
set_task(15.0"nightclub_off");

            if(
rand == 1) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 60-x Party^x01 :)",User)
                
client_cmd(0,"spk misc/xPaw/benny1.wav");
            }
            if(
rand == 2) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 50cent!",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/candyshop.mp3");
            }
            if(
rand == 3) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 CrazyGirl!",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/crazy.mp3");
            }
            if(
rand == 4) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 DJ Fighter!",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/fighter.mp3");
            }
            if(
rand == 5) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 DJ DarkSide ;D",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/poppin.mp3");
            }
            if(
rand == 6) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 MC Russ!",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/vodka.mp3");
            }
            if(
rand == 7) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 Mp3 :/",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/makeit.mp3");
            }
            if(
rand == 8) {
                
ColorChat(0BLUE"^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 DJ CoCo :D",User)
                
client_cmd(0,"mp3 play sound/misc/xPaw/coco.mp3");
            }
    }
}

public 
nightclub_off(id) {
    
ColorChat(0RED"^x01**^x04 Now^x03 Nightclub^x04 is open for ^x01guests!")

    
Nightclub false;
    
set_user_rendering(id)
}

public 
client_disconnect() {
   
Nightclub false;
}

public 
single_knife(id[])
{
        new 
r,g,b
        r 
random_num(0,255);
        
random_num(0,255);
        
random_num(0,255);

        new 
color random_num(0,255);
        new 
width random_num(400,1000);

        new 
korigin[3];
        
get_user_origin(id[0],korigin)

        
set_user_rendering(id[0],kRenderFxGlowShell,r,g,b,kRenderTransAlpha,255)

            
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
            
write_byte(15);                        // TE_SPRITETRAIL
            
write_coord(korigin[0]);            // coord, coord, coord (start)
            
write_coord(korigin[1]);
            
write_coord(korigin[2]-20);
            
write_coord(korigin[0]);            // coord, coord, coord (end)
            
write_coord(korigin[1]);
            
write_coord(korigin[2]+20);
            
            if ((
128) && (127) && (127))
                
write_short(sprRflare);
            
            else if ((
127) && (128) && (127))
                
write_short(sprGflare);
            
            else if ((
127) && (127) && (128))
                
write_short(sprBflare);
                
            else if ((
127) && (128) && (128))
                
write_short(sprTflare);
                
            else if ((
128) && (127) && (200) && (100))
                
write_short(sprPflare);
                
            else if ((
128) && (128) && (127))
                
write_short(sprYflare);
                
            else if ((
128) && (100) && (200) && (127))
                
write_short(sprOflare);
            else
                
write_short(sprBflare);
            
            
write_byte(get_cvar_num("sv_club_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(); 

            
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
            
write_byte(27);
            
write_coord(korigin[0]);    // coord, coord, coord (start)
            
write_coord(korigin[1]);
            
write_coord(korigin[2]);
            
write_byte(30);            // byte (radius in 10's) 
            
write_byte(r);            // byte byte byte (color)
            
write_byte(g);
            
write_byte(b);
            
write_byte(70);            // byte (life in 10's)
            
write_byte(11);            // byte (decay rate in 10's)
            
message_end();

            
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
            
write_byte(122);         // very similar to lavasplash.
            
write_coord(korigin[0]);    // coord, coord, coord (start)
            
write_coord(korigin[1]);
            
write_coord(korigin[2]);
            
write_short (width);
            
write_byte (color);         // (particle color)
            
write_byte (40);         // (duration * 10) (will be randomized a bit)
            
message_end();

            
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
            
write_byte(14);
            
write_coord(korigin[0]);
            
write_coord(korigin[1]);
            
write_coord(korigin[2]-100);
            
write_byte(3500);         // radius
            
write_byte(80);
            
write_byte(20);
            
message_end();



xPaw 07-26-2008 04:57

Re: help with code optimizing
 
nobody can help me ? :(

Arkshine 07-26-2008 07:46

Re: help with code optimizing
 
You should review your code G-Dog, it's badly optimized, really.

Dr. Jan Itor 07-26-2008 07:48

Re: help with code optimizing
 
Quote:

Originally Posted by G-dog
btw I think your trying to use multiple colors in the colrchat stuff which I don't believe you can do, but it's untested since I never bothered with colorchat(thus I don't have the include to test this either)

i think you can
Quote:

Originally Posted by colorchat functions thread examples
ColorChat(0, RED, "%s, ^x01This color is yellow. ^x03This color is red. ^x04This color is green.);


G-Dog 07-26-2008 10:28

Re: help with code optimizing
 
Quote:

Originally Posted by arkshine (Post 659027)
You should review your code G-Dog, it's badly optimized, really.

ok I noticed I could have done a few things better, still learning actually so any pointers are welcome
Code:

#include <amxmodx>
#include <fakemeta>
#include <colorchat>

/* Night Club
 *        Original from "Advanced Roll The Dice"
 *
 * (c) Copyright 2008 xPaw.
 *
 *  Credits:
 *
 *        Striker                - his "Advanced Roll The Dice"
 *        OpenMind        - Helping ;)
 */
 
//sprites
new sprflare[7];
//pcvars
new cvar_time, cvar_count;
//misc
new bool:Nightclub, timer_ent, timer;

new soundlist[8][] = {
"misc/xPaw/benny1.wav", "misc/xPaw/candyshop.mp3", "misc/xPaw/crazy.mp3",
"misc/xPaw/fighter.mp3", "misc/xPaw/poppin.mp3", "misc/xPaw/vodka.mp3",
"misc/xPaw/makeit.mp3", "misc/xPaw/coco.mp3"
}

new partynames[8][] = {
"60-x Party^x01 :)", "50cent!", "CrazyGirl!", "DJ Fighter!", "DJ DarkSide ;D",
"MC Russ!", "Mp3 :/", "DJ CoCo :D"
}

new flarelist[7][] = {
"sprites/fireworks/bflare.spr", "sprites/fireworks/rflare.spr", "sprites/fireworks/gflare.spr",
"sprites/fireworks/tflare.spr", "sprites/fireworks/oflare.spr", "sprites/fireworks/pflare.spr",
"sprites/fireworks/yflare.spr"
}

new rmin[7] = { 0, 129, 0, 0, 129, 129, 129 }
new rmax[7] = { 126, 255, 126, 126, 255, 255, 255 }
new gmin[7] = { 0, 0, 129, 129, 101, 0, 129 }
new gmax[7] = { 126, 126, 255, 255, 199, 126, 255 }
new bmin[7] = { 129, 0, 0, 129, 0, 101, 0 }
new bmax[7] = { 255, 126, 126, 255, 126, 199, 126 }

new const plugin[] = "Night Club"
new const version[] = "1.6"
new const author[] = "xPaw"

public plugin_init()
{
        register_plugin(plugin,version,author);

        cvar_time = register_cvar("sv_club_time", "10");
        cvar_count = register_cvar("sv_club_flare_count", "12");
       
        timer_ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
        if ( pev_valid(timer_ent) )
        {
                set_pev(timer_ent, pev_classname, "timer_loop");
                set_pev(timer_ent, pev_nextthink, get_gametime() + 0.1);
                register_forward(FM_Think, "timer_think");
        }
}

public plugin_precache()
{
        new i
        for( i = 0; i < 8; i++ )
                engfunc(EngFunc_PrecacheSound, soundlist[i]);
               
        for( i = 0; i < 7; i++ )
                sprflare[i] = engfunc(EngFunc_PrecacheModel, flarelist[i]);
}
public client_command(id) //was trying to get everything done at once, is it actually better to register the 5(3 if use say) differant commands instead?
{
        static cmd[10];
        read_argv(1,cmd,9);
       
        if ( equali( cmd, "say", 3 ) || equali( cmd, "say_team", 8 ) ) {
                read_argv(2,cmd,9);
                //strip "/" if it's there
                if ( equali( cmd, "/", 1 ) ) copy( cmd, 9, cmd[1] );
        }
               
        if ( equali(cmd, "club",4) ) {
                start_nightclub(id);
                return PLUGIN_HANDLED;
        }
       
        return PLUGIN_CONTINUE;
}

public client_disconnect(id) {
        timer = 0;
        nightclub_off(id);
}

public timer_think(ent)
{
        if ( ent != timer_ent ) return FMRES_IGNORED;
       
        if ( timer > 0 ) {
                new id = pev(timer_ent, pev_owner);       
                single_knife(id);                               
                timer--;
               
                if ( timer == 0 ) nightclub_off(id);
        }
       
        set_pev(timer_ent, pev_nextthink, get_gametime() + 0.1);
        return FMRES_HANDLED;
}

start_nightclub(id)
{
        if( !is_user_alive(id) ) ColorChat(id, RED, "^x01**^x04 Dead people dont go to^x03 Nightclub!")

        if( Nightclub ) ColorChat(id, RED, "^x01**^x04 Now you cant go to^x03 Nightclub,^x04 try later!")

        else
        {
                new rand = random_num(0,7);
                static User[32];
                get_user_name(id,User,31);
               
                Nightclub = true;
                set_pev(timer_ent, pev_owner, id);       
                timer = ( get_pcvar_num(cvar_time) + 2 ) * 90;

                ColorChat(0, BLUE, "^x01**^x03 %s^x04 is dancing at the^x03 NightClub,^x04 here is^x01 %s",User, partynames[rand]);
                client_cmd(0, "%s %s", rand == 0 ? "spk" : "mp3 play", soundlist[rand]);
        }
}

nightclub_off(id) {
        ColorChat(0, RED, "^x01**^x04 Now^x03 Nightclub^x04 is open for ^x01guests!");

        Nightclub = false;
        timer = 0;
        _set_rendering(id);
}

single_knife(id)
{
        new rand = random_num(0, 6);
       
        new r,g,b
        r = random_num(rmin[rand],rmax[rand]);
        g = random_num(gmin[rand],gmax[rand]);
        b = random_num(bmin[rand],bmax[rand]);
       
        static korigin[3];
        get_user_origin(id,korigin)

        _set_rendering(id,kRenderFxGlowShell,r,g,b,kRenderTransAlpha,255)

        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(15);                                                // TE_SPRITETRAIL
        write_coord(korigin[0]);                        // coord, coord, coord (start)
        write_coord(korigin[1]);
        write_coord(korigin[2]-20);
        write_coord(korigin[0]);                        // coord, coord, coord (end)
        write_coord(korigin[1]);
        write_coord(korigin[2]+20);
        write_short(sprflare[rand]);               
        write_byte(get_pcvar_num(cvar_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();
       
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(27);
        write_coord(korigin[0]);        // coord, coord, coord (start)
        write_coord(korigin[1]);
        write_coord(korigin[2]);
        write_byte(30);                        // byte (radius in 10's)
        write_byte(r);                        // byte byte byte (color)
        write_byte(g);
        write_byte(b);
        write_byte(70);                        // byte (life in 10's)
        write_byte(11);                        // byte (decay rate in 10's)
        message_end();
       
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(122);                // very similar to lavasplash.
        write_coord(korigin[0]);        // coord, coord, coord (start)
        write_coord(korigin[1]);
        write_coord(korigin[2]);
        write_short (random_num(400,1000));
        write_byte (random_num(0,255));                // (particle color)
        write_byte (40);                // (duration * 10) (will be randomized a bit)
        message_end();
       
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(14);
        write_coord(korigin[0]);
        write_coord(korigin[1]);
        write_coord(korigin[2]-100);
        write_byte(3500);                // radius
        write_byte(80);
        write_byte(20);
        message_end();


_set_rendering(index, fx=kRenderFxNone, r=255, g=255, b=255, render=kRenderNormal, amount=16)
{
        if ( !pev_valid(index) ) return 0;
       
        set_pev(index, pev_renderfx, fx);
        new Float:RenderColor[3];
        RenderColor[0] = float(r);
        RenderColor[1] = float(g);
        RenderColor[2] = float(b);
        set_pev(index, pev_rendercolor, RenderColor);
        set_pev(index, pev_rendermode, render);
        set_pev(index, pev_renderamt, float(amount));

        return 1;
}



All times are GMT -4. The time now is 05:28.

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