AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reduce code (https://forums.alliedmods.net/showthread.php?t=254410)

Eviatar Mor 01-02-2015 08:08

Reduce code
 
hey,
i made this:
PHP Code:

public fw_PlayerKilled(victimattacker)  
{
    if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
    {
        
set_dhudmessage(random(256), random(256), random(256));
        
show_dhudmessage(0"%s Vs %s!"ctNametName)
        
client_cmd(0,"spk ^"vox/ %s vs %s^""ctNametName
    }
    
    if(
cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 0){
        
set_dhudmessage(random(256), random(256), random(256));
        
show_dhudmessage(0"%s The Last And Only!"tName)
    }
    if(
cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 1){
        
set_dhudmessage(random(256), random(256), random(256));
        
show_dhudmessage(0"%s The Last And Only!"tName)
        
client_cmd(read_data(2), "spk %s"g_szSoundVoice);
    }
    if(
cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 2){
        
set_dhudmessage(random(256), random(256), random(256));
        
show_dhudmessage(0"%s The Last And Only!"tName)
        
client_cmd(read_data(2), "spk %s"g_szSoundVoice1);
    }


and i want a way how to Reduce it.

YamiKaitou 01-02-2015 08:12

Re: Reduce code
 
Why? There is nothing wrong with that

Eviatar Mor 01-02-2015 08:17

Re: Reduce code
 
Quote:

Originally Posted by YamiKaitou (Post 2243632)
Why? There is nothing wrong with that

i can't make this smaller ?
PHP Code:

    if(cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 0){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
    } 
    if(
cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 1){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
        
client_cmd(read_data(2), "spk %s"g_szSoundVoice); 
    } 
    if(
cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 2){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
        
client_cmd(read_data(2), "spk %s"g_szSoundVoice1); 
    } 

because i dont want to make always like that:
get_pcvar_num(toao_voice) == 0:
PHP Code:

if(cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 0){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
    } 

get_pcvar_num(toao_voice) == 1:
PHP Code:

if(cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 1){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
client_cmd(read_data(2), "spk %s"g_szSoundVoice);
    } 

get_pcvar_num(toao_voice) == 2:
PHP Code:

if(cs_get_terrorist_count(1) == && get_pcvar_num(toao_voice) == 2){ 
        
set_dhudmessage(random(256), random(256), random(256)); 
        
show_dhudmessage(0"%s The Last And Only!"tName
client_cmd(read_data(2), "spk %s"g_szSoundVoice1);
    } 


YamiKaitou 01-02-2015 08:18

Re: Reduce code
 
With the code that you have shown us, no.

Again, why?

Eviatar Mor 01-02-2015 08:20

Re: Reduce code
 
Quote:

Originally Posted by YamiKaitou (Post 2243634)
With the code that you have shown us, no.

okay thanks u.

Flick3rR 01-02-2015 08:35

Re: Reduce code
 
Something like that, if it's reduced enough? :D
PHP Code:

public fw_PlayerKilled(victimattacker)   

    
    if(
cs_get_counter_count(1) == 1)
    {
        
set_dhudmessage(random(256), random(256), random(256))
        
        if(
cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs %s!"ctNametName
            
client_cmd(0,"spk ^"vox/ %s vs %s^""ctNametName)
            return
        }
        
        
show_dhudmessage(0"%s The Last And Only!"tName
        if(
get_pcvar_num(toao_voice))
            
client_cmd(read_data(2), "spk %s"get_pcvar_num(toao_voice) == g_szSoundVoice g_szSoundVoice1); 
            
        return
        
    }



Eviatar Mor 01-02-2015 08:38

Re: Reduce code
 
Quote:

Originally Posted by Flick3rR (Post 2243642)
Something like that, if it's reduced enough? :D
PHP Code:

public fw_PlayerKilled(victimattacker)   

    
    if(
cs_get_counter_count(1) == 1)
    {
        
set_dhudmessage(random(256), random(256), random(256))
        
        if(
cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs %s!"ctNametName
            
client_cmd(0,"spk ^"vox/ %s vs %s^""ctNametName)
            return
        }
        
        
show_dhudmessage(0"%s The Last And Only!"tName
        if(
get_pcvar_num(toao_voice))
            
client_cmd(read_data(2), "spk %s"get_pcvar_num(toao_voice) == g_szSoundVoice g_szSoundVoice1); 
            
        return
        
    }



yes it's good.
and flicker and this how can i reduce:
PHP Code:

if(get_pcvar_num(CVARenabled) == 1){
        
set_dhudmessage(random(256), random(256), random(256));
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs %s!"CTnameTname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs 2 Ct!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs 3 Ct!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs 4 Ct!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs 5 Ct!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 1)
        {
            
show_dhudmessage(0"%s Vs 6 Ct!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 2)
        {
            
show_dhudmessage(0"%s Vs 2 T!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 3)
        {
            
show_dhudmessage(0"%s Vs 3 T!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 4)
        {
            
show_dhudmessage(0"%s Vs 4 T!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 5)
        {
            
show_dhudmessage(0"%s Vs 5 T!"Tname)
        }
        if(
cs_get_counter_count(1) == && cs_get_terrorist_count(1) == 6)
        {
            
show_dhudmessage(0"%s Vs 6 T!"Tname)
        }
        
client_cmd(read_data(2), "spk %s"g_szSoundVoice);    
    } 


YamiKaitou 01-02-2015 08:45

Re: Reduce code
 
Code:

if (get_pcvar_num(CVARenabled) == 1)
{
        set_dhudmessage(random(256), random(256), random(256));
       
        new iCT = cs_get_counter_count(1);
        new iT = cs_get_terrorist_count(1)
       
        if(iCT == 1 && iT == 1)
        {
                show_dhudmessage(0, "%s Vs %s!", CTname, Tname)
        }
        else if(iT == 1)
        {
                show_dhudmessage(0, "%s Vs %i Ct!", Tname, iCT)
        }
        else if(iCT == 1)
        {
                show_dhudmessage(0, "%s Vs %i T!", Tname, iT)
        }
       
        client_cmd(read_data(2), "spk %s", g_szSoundVoice);   
}


klippy 01-02-2015 08:46

Re: Reduce code
 
I would go with this. Additionally, it will work for any number of players, not just up to 6!
PHP Code:

if(get_pcvar_num(CVARenabled) == 1)
{
    
set_dhudmessage(random(256), random(256), random(256));
    new 
iCTCount cs_get_counter_count(1);
    new 
iTCount cs_get_terrorist_count(1);
    
    if(
iCTCount == && iTCount == 1)
        
show_dhudmessage(0"%s Vs %s!"CTnameTname);
    else if(
iCTCount && iTCount == 1)
        
show_hudmessage(0"%s Vs %d Ct!"TnameiCTCount);
    else if(
iTCount && iCTCount == 1)
        
show_hudmessage(0"%s Vs %d T!"TnameiTCount); // Should this be CTname instead of Tname?
    
    
    
client_cmd(read_data(2), "spk %s"g_szSoundVoice);    


EDIT:
Yami ninja'd me... :/

Eviatar Mor 01-02-2015 08:48

Re: Reduce code
 
Quote:

Originally Posted by YamiKaitou (Post 2243648)
Code:

if (get_pcvar_num(CVARenabled) == 1)
{
        set_dhudmessage(random(256), random(256), random(256));
       
        new iCT = cs_get_counter_count(1);
        new iT = cs_get_terrorist_count(1)
       
        if(iCT == 1 && iT == 1)
        {
                show_dhudmessage(0, "%s Vs %s!", CTname, Tname)
        }
        else if(iT == 1)
        {
                show_dhudmessage(0, "%s Vs %i Ct!", Tname, iCT)
        }
        else if(iCT == 1)
        {
                show_dhudmessage(0, "%s Vs %i T!", Tname, iT)
        }
       
        client_cmd(read_data(2), "spk %s", g_szSoundVoice);   
}


oh, thank you


All times are GMT -4. The time now is 15:17.

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