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

Different messages controlled by if statemenets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
staNioN
Junior Member
Join Date: Jul 2013
Old 08-01-2021 , 21:43   Different messages controlled by if statemenets
Reply With Quote #1

Hello, Im trying to add different cvars and have them each show a different message when they are enabled.
I have 5-6 cvars(kz_nfs, kz_wayz ,icevip ,newicevip ,sxj) and i want to combine them with another cvar(kz_chatinfo) and what i want to achieve is the following:

If any of the cvars is enabled WITH kz_chatinfo ENABLED ==> Different Message for each cvar
If any of the cvars is enabled WITH kz_chatinfo DISABLED ==> Different message for each cvar
If NONE of the cvars is enabled AND kz_chatinfo is DISABLED ==> another message (Default message) when everything is disabled.

Whenever i try to use If and else if for each it just wont compile saying either invalid expressions, or expected ";" and found "if" or ")" and when it finally DOES compile, all the messages show at the same time, like the cvars arent doing or controlling anything. Im attaching the plugin and posting the code of the problem area in the post. Hopeflly someone can save me from this hell
EDIT: Just posted the full plugin files and an updated sma file. The file compiles fine now but the issue is that all the message appear at once, not when each cvar is enabled. Like even if all/most(?) of them are off, it still gives 6 different messages.

PHP Code:
                                        if(get_pcvar_num(kz_nfs) && get_pcvar_num(kz_chatinfo))
                                        {
                                            
ColorChat(idsRED"^3[%s] %s %s'd %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], Jtype[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                        }
                                        else if (
get_pcvar_num(kz_nfs))
                                        
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units! %i%% ^1%s%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }                                    
                                        if(
get_pcvar_num(kz_wayz) && get_pcvar_num(kz_chatinfo))
                                        {
                                            
ColorChat(idsRED,"^1[%s] ^4%s ^1%s Distance: ^3%.1f ^1Pre: ^3%.1f ^1Strafes: ^3%i ^1Sync: ^3%i%% %s%s%s"prefix,g_playername[id],Jtype[id],distance[id],prestrafe[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                        }
                                        else if(
get_pcvar_num(kz_wayz))
                                        
ColorChat(idsRED,"^1[%s] ^4%s ^1%s Distance: ^3%.1f ^1Pre: ^3%.1f ^1Strafes: ^3%i ^1Sync: ^3%i%% %s%s%s"prefix,g_playername[id],Jtype[id],distance[id],prestrafe[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }                                    
                                        if(
get_pcvar_num(kz_icevip) && get_pcvar_num(kz_chatinfo))
                                        {
                                            
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %s like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                        }
                                        else if(
get_pcvar_num(kz_icevip))
                                        
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %s like a BOSS! ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }
                                        if(
get_pcvar_num(kz_nfsicevip) && get_pcvar_num(kz_chatinfo))
                                        {
                                            
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %s like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                        }    
                                        else if(
get_pcvar_num(kz_nfsicevip))
                                        
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %s like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }
                                        if(
get_pcvar_num(kz_newicevip) && get_pcvar_num(kz_chatinfo))
                                        {
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s with %i strafes and %i%% sync on %s like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                        }
                                        else if(
get_pcvar_num(kz_newicevip))
                                        
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s on %s like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }
                                        if(
get_pcvar_num(kz_sxj) && get_pcvar_num(kz_chatinfo) && jump_type[id] == Type_LongJump || jump_type[id] == Type_HighJump)
                                        {
                                            
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                        }
                                        else if(
get_pcvar_num(kz_sxj))
                                        
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s"prefixg_playername[id], distance[id], block_strweapon_namepre_type[id]);
                                        else 
                                        {
                                            if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                            else
                                            
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                        }
                                    } 
Attached Files
File Type: zip uq_jumpstats_v2.51.zip (654.7 KB, 58 views)

Last edited by staNioN; 08-02-2021 at 06:45. Reason: Uploaded new .sma file and all the necessary plugin stuff
staNioN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 22:31   Re: Different messages controlled by if statemenets
Reply With Quote #2

The code snippet that you posted doesn't seems to relate to your post (i.e. it doesn't have any reference to cvars) and it also doesn't appear to consistent with the attached plugin.

A suggestion that I think may help is to properly indent your code. Not doing this can make it confusing as to what code is actually supposed to be executed (in both the true and false states). I also recommend always (for the most part) using braces around even single line statements so that it's absolutely clear what is going to be executed.

I'm also seeing places where there this sequence which is not valid:

Code:
if()
else
else if()
else
//etc.
"else" must always be preceded by an "if".

Fix some of these issues and it might make it easier to fix the issue.
__________________

Last edited by fysiks; 08-01-2021 at 22:42.
fysiks is offline
staNioN
Junior Member
Join Date: Jul 2013
Old 08-01-2021 , 22:52   Re: Different messages controlled by if statemenets
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
The code snippet that you posted doesn't seems to relate to your post (i.e. it doesn't have any reference to cvars) and it also doesn't appear to consistent with the attached plugin.

A suggestion that I think may help is to properly indent your code. Not doing this can make it confusing as to what code is actually supposed to be executed (in both the true and false states). I also recommend always (for the most part) using braces around even single line statements so that it's absolutely clear what is going to be executed.

I'm also seeing places where there this sequence which is not valid:

Code:
if()
else
else if()
else
//etc.
"else" must always be preceded by an "if".

Fix some of these issues and it might make it easier to fix the issue.
I just uploaded the correct version along with the necessary files for the plugin itself.
What im getting now is that all the messages appear at once no matter what cvar is enabled/disabled. Could you please look at the code and at least do one example where its all correct and i can just go from there. All of the messages are basically the same so if you can post one correct format i can just do it with the others.

Else if => if the code above it is wrong right? I tried using a bunch of them for each line but i got it wrong

Also, is there a way to specify the cvar value in the if statement itself instead of using get_pcvar_nu
? does that make sense? sorry im a complete beginner so im not sure if my questions make sense haha
staNioN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 23:48   Re: Different messages controlled by if statemenets
Reply With Quote #4

Note that it might be helpful to have the original code that you started with so that we can see exactly what changes you made. I noticed that someone created a version of this plugin (which appears to be based on the one you started with) on GitHub here, does this one do what you need already? Maybe it would be easier to start with it? I'm not sure because I don't fully understand what this plugin does or what you are trying to do with it.

Quote:
Originally Posted by staNioN View Post
I just uploaded the correct version along with the necessary files for the plugin itself.
What im getting now is that all the messages appear at once no matter what cvar is enabled/disabled. Could you please look at the code and at least do one example where its all correct and i can just go from there. All of the messages are basically the same so if you can post one correct format i can just do it with the others.

Else if => if the code above it is wrong right? I tried using a bunch of them for each line but i got it wrong
You still have multiple lines of code after an if or and else that are not in braces but appear like they should be. Note that if you have more than one line that you want to be executed conditionally, both lines must be encapsulated in braces. If they are not in braces then only the first line is executed conditionally, all other lines will be executed unconditionally.

Also, it looks like you would get multiple messages if multiple of the main cvars are enabled. They are not mutually exclusive.


Quote:
Originally Posted by staNioN View Post
Also, is there a way to specify the cvar value in the if statement itself instead of using get_pcvar_nu
? does that make sense? sorry im a complete beginner so im not sure if my questions make sense haha
You should only use it once in a single function. If you need to use the value multiple times, you should cache the value into a variable and then use the variable.
__________________

Last edited by fysiks; 08-01-2021 at 23:50.
fysiks is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-02-2021 , 00:12   Re: Different messages controlled by if statemenets
Reply With Quote #5

Regarding your original, specific question, you can cache the cvar values and then do some preprocessing to determine which variant of the message you want to send. I've created an example here with three of the cvars plus the chat info cvar:

PHP Code:

// Cache cvar values
static chatinfonfswayzicevip
chatinfo 
= !!get_pcvar_num(kz_chatinfo)
nfs = !!get_pcvar_num(kz_nfs)
wayz = !!get_pcvar_num(kz_wayz)
icevip = !!get_pcvar_num(kz_icevip)

// Determine type of message
static msgType

anyCvarEnabled 
nfs || wayz || icevip

if( anyCvarEnabled && chatinfo )
{
    
msgType 0
}
else if( 
anyCvarEnabled && !chatinfo )
{
    
msgType 1
}
else
{
    
// No cvars are enabled, show a message here if desired
    
msgType 2
}

// Show the message for each cvar
if( nfs )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }
}

if( 
wayz )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }
}

if( 
icevip )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }

__________________

Last edited by fysiks; 08-02-2021 at 00:15.
fysiks is offline
staNioN
Junior Member
Join Date: Jul 2013
Old 08-02-2021 , 00:33   Re: Different messages controlled by if statemenets
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Regarding your original, specific question, you can cache the cvar values and then do some preprocessing to determine which variant of the message you want to send. I've created an example here with three of the cvars plus the chat info cvar:

PHP Code:

// Cache cvar values
static chatinfonfswayzicevip
chatinfo 
= !!get_pcvar_num(kz_chatinfo)
nfs = !!get_pcvar_num(kz_nfs)
wayz = !!get_pcvar_num(kz_wayz)
icevip = !!get_pcvar_num(kz_icevip)

// Determine type of message
static msgType

anyCvarEnabled 
nfs || wayz || icevip

if( anyCvarEnabled && chatinfo )
{
    
msgType 0
}
else if( 
anyCvarEnabled && !chatinfo )
{
    
msgType 1
}
else
{
    
// No cvars are enabled, show a message here if desired
    
msgType 2
}

// Show the message for each cvar
if( nfs )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }
}

if( 
wayz )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }
}

if( 
icevip )
{
    switch( 
msgType )
    {
        case 
0:
        {
            
// Send message type 0 here
        
}
        case 
1:
        {
            
// send message type 1 here
        
}
    }

I appreciate you taking the time doing this, thank you!
I'm just a bit unsure where do i exactly place the code that you've shown? is it independent and it just grabs values/stuff from the code above?
Because all of the messages that i've shown(the one's i want to edit and fix) depend on alot of other if statements above them, the whole plugin is a bunch of IF statements lol. Because a different sound file will load depending on the distance you jump + the jump type/technique.

If you have the patience to look at where the stuff i want to change start, they're at line #6420-ish

Again, thank you and sorry if its annoying trying to explain stuff to someone new who doesn't know anything lol
staNioN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-02-2021 , 00:51   Re: Different messages controlled by if statemenets
Reply With Quote #7

The example that I've given is specifically for the area where you try to implement the logic that you explained in your original post (line 6433). For example the following is effectively replaced by my code:

PHP Code:
    if(get_pcvar_num(kz_nfs) && get_pcvar_num(kz_chatinfo))
    {
        
ColorChat(idsRED"^3[%s] %s %s'd %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], Jtype[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
    }
    else if (
get_pcvar_num(kz_nfs))
    {
        
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units! %i%% ^1%s%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
    }
    else
    {
        if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
        
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
        else
        
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
    } 
With the exception that the else case shown here actually moves to the case where msgType is assigned a value of 2. This will probably solve the issue where it was printing multiple messages when none of the cvars are enabled.

While not technically required, the caching of the cvars can be done much earlier in the preThink function so that those variables can replace the get_pcvar_num() calls for those cvars. I would leave the caching to just this section for now until you get it this issue resolved and then you can optimize later by moving the caching earlier in preThink.
__________________

Last edited by fysiks; 08-02-2021 at 00:54.
fysiks is offline
staNioN
Junior Member
Join Date: Jul 2013
Old 08-02-2021 , 02:32   Re: Different messages controlled by if statemenets
Reply With Quote #8

PHP Code:
                                    if ( distance[id] >= god_dist ) {
                                        if( 
uq_sounds && enable_sound[ids]==true )
                                        {
                                            if(
get_pcvar_num(kz_godlike))
                                            
client_cmd(ids"speak misc/mod_godlike");
                                            else
                                            
client_cmd(ids"speak misc/mod_ownage");
                                        }
                                        
// Cache cvar values
                                        
static chatinfonfswayzicevipnfsicevipnewicevipsxj
                                        chatinfo 
= !!get_pcvar_num(kz_chatinfo);
                                        
nfs = !!get_pcvar_num(kz_nfs);
                                        
wayz = !!get_pcvar_num(kz_wayz);
                                        
icevip = !!get_pcvar_num(kz_icevip);
                                        
nfsicevip = !!get_pcvar_num(kz_nfsicevip);
                                        
newicevip = !!get_pcvar_num(kz_newicevip);
                                        
sxj = !!get_pcvar_num(kz_sxj);
                                        
                                        
// Determine type of message
                                        
static msgType
                                        anyCvarEnabled 
nfs || wayz || icevip || nfsicevip || newicevip || sxj
                                        
if( anyCvarEnabled && chatinfo );
                                        {
                                        
msgType 0
                                        
}
                                        else if( 
anyCvarEnabled && !chatinfo );
                                        {
                                        
msgType 1
                                        
}
                                        else
                                        {
                                        
// No cvars are enabled, show a message here if desired
                                        
msgType 2
                                        
}
                                        
// Show the message for each cvar
                                        
if( nfs )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED"^3[%s] %s %s'd %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], Jtype[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units! %i%% ^1%s%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        }
                                        if( 
wayz )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^4%s ^1%s Distance: ^3%.1f ^1Pre: ^3%.1f ^1Strafes: ^3%i ^1Sync: ^3%i%% %s%s%s"prefix,g_playername[id],Jtype[id],distance[id],prestrafe[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                            }
                                        }
                                        if( 
icevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %d like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %d like a BOSS! ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
nfsicevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %d like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %d like a BOSS! ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
newicevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s with %i Strafes and %i%% Sync on %d like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s on %s like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
sxj )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                        
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsBLUE,"^1[%s] ^3%s jumped %.3f units with %s! Strafes: %i Sync: %i%% ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],strafe_num[id], sync_[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                                case 
1:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                        
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s"prefixg_playername[id], distance[id], block_strweapon_namepre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsBLUE,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                            }
                                        } 
                                    } 
This is what I've done so far, did I place it in the correct place? Because I'm getting the following errors when i try to compile it:
scripting\plugin-test.sma(6435) : error 001: expected token: ";", but found "-identifier-"
scripting\plugin-test.sma(6445) : error 001: expected token: ";", but found "-identifier-"
scripting\plugin-test.sma(6445) : error 017: undefined symbol "anyCvarEnabled"
scripting\plugin-test.sma(6445 -- 6446) : warning 215: expression has no effect
scripting\plugin-test.sma(6446) : error 001: expected token: ";", but found "if"
scripting\plugin-test.sma(6446) : fatal error 107: too many error messages on one line
staNioN is offline
staNioN
Junior Member
Join Date: Jul 2013
Old 08-02-2021 , 05:03   Re: Different messages controlled by if statemenets
Reply With Quote #9

Quote:
Originally Posted by staNioN View Post
PHP Code:
                                    if ( distance[id] >= god_dist ) {
                                        if( 
uq_sounds && enable_sound[ids]==true )
                                        {
                                            if(
get_pcvar_num(kz_godlike))
                                            
client_cmd(ids"speak misc/mod_godlike");
                                            else
                                            
client_cmd(ids"speak misc/mod_ownage");
                                        }
                                        
// Cache cvar values
                                        
static chatinfonfswayzicevipnfsicevipnewicevipsxj
                                        chatinfo 
= !!get_pcvar_num(kz_chatinfo);
                                        
nfs = !!get_pcvar_num(kz_nfs);
                                        
wayz = !!get_pcvar_num(kz_wayz);
                                        
icevip = !!get_pcvar_num(kz_icevip);
                                        
nfsicevip = !!get_pcvar_num(kz_nfsicevip);
                                        
newicevip = !!get_pcvar_num(kz_newicevip);
                                        
sxj = !!get_pcvar_num(kz_sxj);
                                        
                                        
// Determine type of message
                                        
static msgType
                                        anyCvarEnabled 
nfs || wayz || icevip || nfsicevip || newicevip || sxj
                                        
if( anyCvarEnabled && chatinfo );
                                        {
                                        
msgType 0
                                        
}
                                        else if( 
anyCvarEnabled && !chatinfo );
                                        {
                                        
msgType 1
                                        
}
                                        else
                                        {
                                        
// No cvars are enabled, show a message here if desired
                                        
msgType 2
                                        
}
                                        
// Show the message for each cvar
                                        
if( nfs )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED"^3[%s] %s %s'd %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], Jtype[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units! %i%% ^1%s%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        }
                                        if( 
wayz )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^4%s ^1%s Distance: ^3%.1f ^1Pre: ^3%.1f ^1Strafes: ^3%i ^1Sync: ^3%i%% %s%s%s"prefix,g_playername[id],Jtype[id],distance[id],prestrafe[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s",prefixg_playername[id], distance[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                            }
                                        }
                                        if( 
icevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %d like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s jumped %.3f units with %s on %d like a BOSS! ^1%s%s",prefixg_playername[id],distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
nfsicevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %d like a BOSS! Strafes: %i Sync: %i%% ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,strafe_num[id],sync_[id],weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^3[%s] %s %s'd %.3f units on %d like a BOSS! ^1%s%s",prefixg_playername[id],Jtype[id],distance[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
newicevip )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s with %i Strafes and %i%% Sync on %d like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],strafe_num[id],sync_[id],block_str,weapon_name,pre_type[id]);
                                                }
                                                case 
1:
                                                {
                                                    
ColorChat(idsRED,"^1[%s] ^3%s jumped %.3f units %s on %s like a BOSS! ^1%s%s",prefixg_playername[id], distance[id],Jtype[id],block_str,weapon_name,pre_type[id]);
                                                }
                                            }
                                        } 
                                        if( 
sxj )
                                        {
                                            switch( 
msgType )
                                            {
                                                case 
0:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                        
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! Strafes: %i Sync: %i%% ^1%s%s%s"prefixg_playername[id], distance[id], strafe_num[id], sync_[id], block_strweapon_namepre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsBLUE,"^1[%s] ^3%s jumped %.3f units with %s! Strafes: %i Sync: %i%% ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],strafe_num[id], sync_[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                                case 
1:
                                                {
                                                    if(
jump_type[id]==Type_LongJump||jump_type[id]==Type_HighJump)
                                                    {
                                                        
ColorChat(idsRED"^1[%s] ^3%s jumped %.3f units! ^1%s%s%s"prefixg_playername[id], distance[id], block_strweapon_namepre_type[id]);
                                                    }
                                                    else
                                                    {
                                                    
ColorChat(idsBLUE,"^1[%s] ^3%s jumped %.3f units with %s! ^1%s%s%s",prefixg_playername[id], distance[id],Jtype1[id],block_str,weapon_name,pre_type[id]);
                                                    }
                                                }
                                            }
                                        } 
                                    } 
This is what I've done so far, did I place it in the correct place? Because I'm getting the following errors when i try to compile it:
scripting\plugin-test.sma(6435) : error 001: expected token: ";", but found "-identifier-"
scripting\plugin-test.sma(6445) : error 001: expected token: ";", but found "-identifier-"
scripting\plugin-test.sma(6445) : error 017: undefined symbol "anyCvarEnabled"
scripting\plugin-test.sma(6445 -- 6446) : warning 215: expression has no effect
scripting\plugin-test.sma(6446) : error 001: expected token: ";", but found "if"
scripting\plugin-test.sma(6446) : fatal error 107: too many error messages on one line
So i finally got it to compile and no more messages getting spammed in the chat!!
For some reason though, the console and the hud messages are spamming 5-6 messages at the same time now(i think this behavior was happening before too), am wondering how do i go about fixing that now?
I uploaded the most updated file, hopefully someone can point me to where the issues are coming from.

I FIXED EVERYTHING, THANK YOU FYSIKS!!

Last edited by staNioN; 08-02-2021 at 06:44. Reason: I fixed everything, thank you
staNioN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-02-2021 , 23:21   Re: Different messages controlled by if statemenets
Reply With Quote #10

Yeah, I forgot to add the creation of the anyCvarEnabled variable so you had to fix that part. Regarding your changes, I don't see a .sma anywhere that has the changes you made. The ZIP file has some completely other version of the jump stats plugin.
__________________
fysiks 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 13:13.


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