AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Format a message? (https://forums.alliedmods.net/showthread.php?t=279068)

Depresie 02-14-2016 12:36

[SOLVED] Format a message?
 
Can anyone explain to me how i can do the following? :)

I have about 20 cases with different type of victims, and i would like to save the desired text i want to display for each specific case then insert it into a hud message
PHP Code:


fw_PlayerKilled
(victimattacker)
{
        if(
leader_human(victim))
        {
                
save "Last Kill: get_pcvar_num(cvar_numer_points_last) Points" text in a variable/array
        else if(
last_human(victim))
        {
                
save "Last Kill: get_pcvar_num(cvar_numer_points_last Points" text in a variable/array
        }
        
set_hudmessage(bla bla)
        
show_hudmessage(attacker"%s"text from above cases)



Bugsy 02-14-2016 13:45

Re: [HELP] Format a message?
 
I don't understand what you're trying to do, can you try to explain better? Maybe give some examples.

Depresie 02-14-2016 14:02

Re: [HELP] Format a message?
 
Ok, i will try to explain again

I want to send a hud message to the attacker when he killed a player, but i want the message to be different depending on the case, following the next example

PHP Code:


public fw_PlayerKilled(victimattacker)
{
         new 
g_mesage
         
if(is_user_last_human(victim))
         {
                   
g_message "You killed the Last Human, You were awarded get_pcvar_num(cvar_last_human_reward) points"
         
}
         else if(
is_user_first_kill(victim))
         { 
                 
g_message "You killed the bla bla, awarded bla bla cvar points"
         

          
set_hudmessage(255,0,0, ...............)
          
show_hudmessage(attacker"%s"g_message")



EpicMonkey 02-14-2016 14:10

Re: [HELP] Format a message?
 
format

Bugsy 02-14-2016 14:38

Re: [HELP] Format a message?
 
You may need to do what you are already doing. The if checking will stop when it hits a true condition so if there's a chance of a player having more than 1 condition, put them in the order of priority.

PHP Code:

if ( is_thisid ) )
   
copyszMsg charsmaxszMsg ) , "You did this" );
else if ( 
is_this_insteadid ) )
   
copyszMsg charsmaxszMsg ) , "You did this instead" ); 


Depresie 02-14-2016 14:48

Re: [HELP] Format a message?
 
So i should make a global variable szMsg? and what about fomat? do i have to use it aswell?
Can you give me a more concrete example please?:)

Bugsy 02-14-2016 15:10

Re: [HELP] Format a message?
 
PHP Code:

enum KillStatus
{
    
LeaderHuman,
    
LastHuman,
    
ThisInstead2,
    
ThisInstead3
}

new const 
KillStatusMsgKillStatus ][] =  
{
    
"Leader human msg",
    
"Last human msg",
    
"This instead 2",
    
"This instead 3"
};

public 
Killedid )
{
    new 
KillStatus:ksStatus;
    
    if ( 
is_leader_humanid ) ) ksStatus LeaderHuman;
    else if ( 
is_last_humanid ) ) ksStatus LastHuman;
    else if ( 
is_this_instead2id ) ) ksStatus ThisInstead2;
    else if ( 
is_this_instead3id ) ) ksStatus ThisInstead3;

    
show_hudmessageid KillStatusMsgksStatus ] );



Depresie 02-14-2016 15:15

Re: [HELP] Format a message?
 
Nice, but could you explain to me one thing please ?:P

This line, how does it work? what ":" stands for in this case
PHP Code:

new KillStatus:ksStatus

And how can i add a cvar value into the text?

Bugsy 02-14-2016 15:24

Re: [HELP] Format a message?
 
Quote:

Originally Posted by Depresie (Post 2392987)
Nice, but could you explain to me one thing please ?:P

This line, how does it work? what ":" stands for in this case
PHP Code:

new KillStatus:ksStatus


I created an enumerator (KillStatus) to define items (LeaderHuman,LastHuman,ThisInstead2,ThisInste ad3). Defining a variable with this tag will make it expect to hold only one of the items that I defined under that type/tag. Technically there is no change in the data, but the compiler will throw a warning if you try to place data other than the defined type in the variable.

So if you did:
ksStatus = ThisInstead3
you will have no issues/warnings
but if you did:
ksStatus = 3
you would get warning. Even though ThisInstead3 equals 3 as defined in the enumerator, it will give you a warning. If you ever have a need to do this and want to not get a warning, you can tag it like this:
ksStatus = KillStatus: 3

I think someone wrote a tut on enumerators/types in the tuts section.

Depresie 02-14-2016 15:26

Re: [HELP] Format a message?
 
I understood now, thanks :)

But, how can i add a cvar value into the text? also the cvar value would be different for each case...


All times are GMT -4. The time now is 09:27.

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