Raised This Month: $ Target: $400
 0% 

[HELP]Switch functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FaTzZu
Junior Member
Join Date: Mar 2013
Old 09-06-2013 , 08:53   [HELP]Switch functions
Reply With Quote #1

Hi.

I made this code

Code:
enum _:Class {
	
	nc_regenerator,
	nc_tank,
	nc_hunter,
	nc_hulk
	
}

new g_Class [ 33 ] [ Class ];

RegisterHam(Ham_Spawn, "player", "p_Spawn", 1);

public p_Spawn(id)
{
	if(!is_user_connected(id) || !is_user_alive(id))
		return 1;
	
	
	
	if(g_Class[id][nc_regenerator])
	{
		
	}
	if(g_Class[id][nc_tank])
	{
		
	}
	if(g_Class[id][nc_hunter])
	{
		
	}
	if(g_Class[id][nc_hulk])
	{
		
	}
	
	
	
}
and i want to make a switch for class.Can you help me?
FaTzZu is offline
SpaWn2KiLl
Member
Join Date: Aug 2012
Old 09-06-2013 , 08:56   Re: [HELP]Switch functions
Reply With Quote #2

Try this:

PHP Code:
public p_Spawn(id)
{
    if(!
is_user_connected(id) || !is_user_alive(id))
        return 
1;
    
    switch(
g_Class[id])
    {
        case 
nc_regenerator:
        {
        }
        case 
nc_tank:
        {
        }
        case 
nc_hunter:
        {
        }
        case 
nc_hulk:
        {
        }
    }

__________________
SpaWn2KiLl is offline
FaTzZu
Junior Member
Join Date: Mar 2013
Old 09-06-2013 , 09:03   Re: [HELP]Switch functions
Reply With Quote #3

I am so noob ... thank you man
FaTzZu is offline
dark_style
Senior Member
Join Date: Jul 2009
Location: Bulgaria
Old 09-06-2013 , 09:07   Re: [HELP]Switch functions
Reply With Quote #4

Why do you return 1 there ? Use only return instead.
__________________




Last edited by dark_style; 09-06-2013 at 09:11.
dark_style is offline
FaTzZu
Junior Member
Join Date: Mar 2013
Old 09-06-2013 , 09:48   Re: [HELP]Switch functions
Reply With Quote #5

Man i have a error when i compile the plugin

error 033: array must be indexed (variable "-unknown-")

can you help me?
FaTzZu is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-06-2013 , 11:54   Re: [HELP]Switch functions
Reply With Quote #6

new g_Class[33];
__________________
Black Rose is offline
SpaWn2KiLl
Member
Join Date: Aug 2012
Old 09-06-2013 , 15:50   Re: [HELP]Switch functions
Reply With Quote #7

You can't do
PHP Code:
new g_Class[33][Class] 
and use it with
PHP Code:
switch 

This is the final code:
PHP Code:
#include <amxmodx>

#define PLUGIN "asdasd"
#define VERSION "1.0"
#define AUTHOR "asdasd"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""p_Spawn"1);
}

enum _:Class {
    
nc_regenerator,
    
nc_tank,
    
nc_hunter,
    
nc_hulk
    
}

new 
g_Class[33];

public 
p_Spawn(id)
{
    if(!
is_user_connected(id) || !is_user_alive(id))
        return 
1;
    
    
// if method
    
if(g_Class[id] == nc_regenerator)
    {
        
client_print(0print_chat"TEST")
    }
    
    
// switch method
    
switch(g_Class[id])
    {
        case 
nc_regenerator:
        {
        }
        case 
nc_tank:
        {
        }
        case 
nc_hunter:
        {
        }
        case 
nc_hulk:
        {
        }
    }
    return 
PLUGIN_CONTINUE

Thanks Black Rose for the help

Sorry for late answer.

EDIT: Added spawn function
__________________

Last edited by SpaWn2KiLl; 09-07-2013 at 23:04.
SpaWn2KiLl is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-06-2013 , 22:50   Re: [HELP]Switch functions
Reply With Quote #8

Quote:
Originally Posted by dark_style View Post
Why do you return 1 there ? Use only return instead.
No, it should be "return HAM_IGNORED".
__________________
fysiks is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-07-2013 , 05:31   Re: [HELP]Switch functions
Reply With Quote #9

Just to clarify
Code:
/**
 * Ham return types.
 * -
 * Return these from hooks to disable calling the target function.
 * Numbers match up with fakemeta's FMRES_* for clarity.  They are interchangable.
 * 0 (or no return) is also interpretted as HAM_IGNORED.
 */
#define HAM_IGNORED		1	/* Calls target function, returns normal value */
#define HAM_HANDLED		2	/* Tells the module you did something, still calls target function and returns normal value */
#define HAM_OVERRIDE	3	/* Still calls the target function, but returns whatever is set with SetHamReturn*() */
#define HAM_SUPERCEDE	4	/* Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */
Quote:
Originally Posted by SpaWn2KiLl View Post
...
You forgot to register spawn
__________________

Last edited by Black Rose; 09-07-2013 at 05:37.
Black Rose is offline
SpaWn2KiLl
Member
Join Date: Aug 2012
Old 09-07-2013 , 23:05   Re: [HELP]Switch functions
Reply With Quote #10

Quote:
Originally Posted by Black Rose View Post
Just to clarify
Code:
/**
 * Ham return types.
 * -
 * Return these from hooks to disable calling the target function.
 * Numbers match up with fakemeta's FMRES_* for clarity.  They are interchangable.
 * 0 (or no return) is also interpretted as HAM_IGNORED.
 */
#define HAM_IGNORED		1	/* Calls target function, returns normal value */
#define HAM_HANDLED		2	/* Tells the module you did something, still calls target function and returns normal value */
#define HAM_OVERRIDE	3	/* Still calls the target function, but returns whatever is set with SetHamReturn*() */
#define HAM_SUPERCEDE	4	/* Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */


You forgot to register spawn
Yes, you are right... My mistake... thanks
__________________
SpaWn2KiLl 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 10:57.


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