Raised This Month: $ Target: $400
 0% 

client_print cmd_target problems...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-25-2009 , 02:40   client_print cmd_target problems...
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <fun>
#include <amxmisc>

#define PLUGIN "Cloak"
#define VERSION "1.0"
#define AUTHOR "Master A.K.A. HLM"

new g_iVisibilityState[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("amx_cloak","give_invis"ADMIN_KICK,"<name|#userid|steamid> <on/half/off> ")
}

public 
give_invis(id,level,cid)
{
    if(!
cmd_access(id,level,cid,3))
        return 
PLUGIN_HANDLED
    
    
new szarg1[33], szarg2[8]
    
read_argv(1,szarg1,32)
    
read_argv(2,szarg2,7)
    new 
mode str_to_num(szarg2)
    
    new 
target cmd_target(id,szarg1,2)
    new 
name[32];
    
get_user_name(idname32)
    if(
target)
    {
        
g_iVisibilityState[target] = mode
        
switch(mode)
        {
            case 
0:
            {
                if(
is_user_alive(target))
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
                
client_print(target,print_chat,"-[EVIL]- %s is no longer cloaked ",name)
            }
            case 
1:
            {
                if(
is_user_alive(target))
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,85)
                
client_print(target,print_chat"-[EVIL]- %s is partially cloaked ",name)
                
// Partial Cloak
            
}
            case 
2:
            {
                if(
is_user_alive(target))
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,0)
                
client_print(target,print_chat"-[EVIL]- %s is completely cloaked ",name)
                
// Full Cloak
            
}
        }
    }
        
    return 
PLUGIN_HANDLED

I wantto change case 0: case 1: case 2: to equal on half and off.. then I dont have to run amx_cloak %s <0/1/2>

how would I do this?

EDIT: This has been solved, view post 16 for the current issue at hand..
__________________
+|- KARMA Respectively


Last edited by HLM; 06-26-2009 at 01:42.
HLM is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-25-2009 , 03:53   Re: make a case of a switch equal a string?
Reply With Quote #2

You can't do it with full strings, you can do a switch for the first character though. I would suggest just doing if/else.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-25-2009 , 15:17   Re: make a case of a switch equal a string?
Reply With Quote #3

PHP Code:
if azarg2 "on" then $dothis
else
if 
szarg2 ="off" then $turn_this_off
else
if 
szarg2 "half" then $use_this 
am I going about this correctly?
__________________
+|- KARMA Respectively


Last edited by HLM; 06-25-2009 at 16:32. Reason: DONT READ THIS!!
HLM is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 06-25-2009 , 16:41   Re: make a case of a switch equal a string?
Reply With Quote #4

Quote:
Originally Posted by HLM View Post
PHP Code:
if azarg2 "on" then $dothis
else
if 
szarg2 ="off" then $turn_this_off
else
if 
szarg2 "half" then $use_this 
am I going about this correctly?
Emp already told you that you can't do it with strings. You can do following:
PHP Code:
switch( szarg2] )
{
     case 
'n': { }
     case 
'f': { }
     case 
'a': { }

Or
PHP Code:
if( equalszarg2"on" ) ) { }
else if( 
equalszarg2"off" ) ) { }
else if( 
equalszarg2"half" ) ) { } 
SnoW is offline
Send a message via MSN to SnoW
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-25-2009 , 18:17   Re: make a case of a switch equal a string?
Reply With Quote #5

okay, I now have it 100% set up, I still have to warning about indentation.. IDK but how do I 'refresh' the cloak after user dies?

like.. is_user_dead, is there anything like that?
__________________
+|- KARMA Respectively

HLM is offline
Atspulgs
Senior Member
Join Date: Mar 2008
Old 06-25-2009 , 18:21   Re: make a case of a switch equal a string?
Reply With Quote #6

there is
is_user_alive(id)
__________________
-=DG Ats
DoomedGang web page -
http://www.doomedgang.com
Atspulgs is offline
tpt
Member
Join Date: Jun 2009
Location: Scripting help section
Old 06-25-2009 , 18:39   Re: make a case of a switch equal a string?
Reply With Quote #7

Quote:
Originally Posted by Atspulgs View Post
there is
is_user_alive(id)
Code:
if( is_user_alive( index ) ) //alive if( !is_user_alive( index ) ) //dead

But i think you're looking for deathmsg event.

Code:
public plugin_init()        register_event("DeathMsg", "e_death", "a", "1>0") public e_death() {      //player has died      new Killer = read_data(1)      new Victim = read_data(2) }

Last edited by tpt; 06-25-2009 at 18:45.
tpt is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-25-2009 , 19:04   Re: make a case of a switch equal a string?
Reply With Quote #8

Also, you need to start using braces.

PHP Code:
                if(is_user_alive(target))
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
                
client_print(target,print_chat,"-[EVIL]- %s is no longer cloaked ",name
If user is alive both are executed. If user is dead the second is still executed. Is this check really needed anyways?
__________________
fysiks is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 06-25-2009 , 19:21   Re: make a case of a switch equal a string?
Reply With Quote #9

Quote:
Originally Posted by Emp` View Post
You can't do it with full strings, you can do a switch for the first character though. I would suggest just doing if/else.
PHP Code:
new random_text[] = "this is untested but should work";

switch( 
engfuncEngFunc_AllocStringrandom_text ) )
{
    
// 123 should be the returned value of engfunc( EngFunc_AllocString, your_case ) since switch requires constant expressions
    
case 123client_printplrprint_chat"lol Emp was wrong!" );
    default: 
client_printplrprint_chat"fail" );

__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-25-2009 , 19:30   Re: make a case of a switch equal a string?
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
Also, you need to start using braces.

PHP Code:
                if(is_user_alive(target))
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
                
client_print(target,print_chat,"-[EVIL]- %s is no longer cloaked ",name
If user is alive both are executed. If user is dead the second is still executed. Is this check really needed anyways?
the if is_user_alive bit was my way of trying to get it to do it whenever user is alive, but now I feel asif it should be removed, because this is not looping infinitely redoing the command constantly... (wouldnt that kill the server?)
the final product:
PHP Code:
#include <amxmodx>
#include <fun>
#include <amxmisc>

#define PLUGIN "Cloak"
#define VERSION "1.0"
#define AUTHOR "Master A.K.A. HLM"

new g_iVisibilityState[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("amx_cloak","give_invis"ADMIN_KICK,"<name|#userid|steamid> <on/half/off> ")
    
register_event("DeathMsg""e_death""a""1>0")
}

public 
give_invis(id,level,cid)
{
    if(!
cmd_access(id,level,cid,3))
        return 
PLUGIN_HANDLED
    
    
new szarg1[33], szarg2[8]
    
read_argv(1,szarg1,32)
    
read_argv(2,szarg2,7)
    new 
mode str_to_num(szarg2)
    
    new 
target cmd_target(id,szarg1,2)
    new 
name[32];
    
get_user_name(idname32)
    if(
target)
    {
        
g_iVisibilityState[target] = mode
        
            
if( equalszarg2"off" ) )
            {
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
                
client_print(target,print_chat,"-[EVIL]- %s is no longer cloaked ",name)
            }
            else if( 
equalszarg2"half" ) ) 
            {
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,85)
                
client_print(target,print_chat"-[EVIL]- %s is partially cloaked ",name)
                
// Partial Cloak
            
}
            else if( 
equalszarg2"on" ) )
            {
                
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,0)
                
client_print(target,print_chat"-[EVIL]- %s is completely cloaked ",name)
                
// Full Cloak
            
}
    }
return 
PLUGIN_HANDLED
}

public 
e_death(id,level,cid)
{
    
    new 
szarg1[33], szarg2[8]
    
read_argv(1,szarg1,32)
    
read_argv(2,szarg2,7)
    new 
mode str_to_num(szarg2)
    
    new 
target cmd_target(id,szarg1,2)
    new 
name[32];
    
get_user_name(idname32)
    
    if( 
equalszarg2"off" ) )
    {
        
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
    }
    else if( 
equalszarg2"half" ) )
    {
        
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,85)
        
client_print(target,print_chat"-[EVIL]- %s, you are still partially cloaked! ",name)
    }
    else if( 
equalszarg2"on" ) )
    {
        
set_user_rendering(target,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,0)
        
client_print(target,print_chat"-[EVIL]- %s, you are still completely cloaked! ",name)
    }
return 
PLUGIN_HANDLED

the only problem is that it does NOT last through death.. I have a feeling that it is because I redefined the vars and whatnot.. is it possible to have a public in a public? or call upon the value of the args from a different function?
__________________
+|- KARMA Respectively


Last edited by HLM; 06-25-2009 at 19:56. Reason: added the final product..
HLM 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 15:33.


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