AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP]Switch functions (https://forums.alliedmods.net/showthread.php?t=225562)

FaTzZu 09-06-2013 08:53

[HELP]Switch functions
 
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? :)

SpaWn2KiLl 09-06-2013 08:56

Re: [HELP]Switch functions
 
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:
        {
        }
    }



FaTzZu 09-06-2013 09:03

Re: [HELP]Switch functions
 
I am so noob ... thank you man

dark_style 09-06-2013 09:07

Re: [HELP]Switch functions
 
Why do you return 1 there ? Use only return instead.

FaTzZu 09-06-2013 09:48

Re: [HELP]Switch functions
 
Man i have a error when i compile the plugin

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

can you help me?

Black Rose 09-06-2013 11:54

Re: [HELP]Switch functions
 
new g_Class[33];

SpaWn2KiLl 09-06-2013 15:50

Re: [HELP]Switch functions
 
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

fysiks 09-06-2013 22:50

Re: [HELP]Switch functions
 
Quote:

Originally Posted by dark_style (Post 2029350)
Why do you return 1 there ? Use only return instead.

No, it should be "return HAM_IGNORED".

Black Rose 09-07-2013 05:31

Re: [HELP]Switch functions
 
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 (Post 2029611)
...

You forgot to register spawn

SpaWn2KiLl 09-07-2013 23:05

Re: [HELP]Switch functions
 
Quote:

Originally Posted by Black Rose (Post 2029845)
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 :D


All times are GMT -4. The time now is 18:51.

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