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

API Scripting Help |HELP| How to add on/off for zombie class


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 03-06-2015 , 08:10   |HELP| How to add on/off for zombie class
Reply With Quote #1

I'm struggling to make cvar for on and off-which means if cvar is off,then that class not appear in the menu for the class,and if set cvar to on,then that class will appear.
Can someone please help me with this?

here is simple class for example:

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <biohazard>

#define D_ZOMBIE_NAME "Chainsaw class"
#define D_ZOMBIE_DESC "strong attack (DMG)"
#define D_PLAYER_MODEL "chainsaw_ghost"
#define D_CLAWS "models/v_new_ghost_chainsaw.mdl"
#define PMODEL "models/player/chainsaw_ghost/chainsaw_ghost.mdl"

new g_zclassid1

new const chainsaw_sounds[][] =
{
        
"weapons/knife_deploy1.wav",
        
"biohazard/chainsaw1_miss.wav",
        
"biohazard/chainsaw1_miss.wav",
        
"biohazard/chainsaw1_miss.wav",
        
"biohazard/chainsaw1_miss.wav",
        
"biohazard/chain_hitwall1.wav",
        
"biohazard/chainsaww_slash1.wav",
        
"biohazard/chainsaww_slash2.wav",
        
"biohazard/chainsaw_stab.wav"
}

new const 
knife_sounds[][] =
{
    
"weapons/knife_deploy1.wav",
    
"weapons/knife_hit1.wav",
    
"weapons/knife_hit2.wav",
    
"weapons/knife_hit3.wav",
    
"weapons/knife_hit4.wav",
    
"weapons/knife_hitwall1.wav",
    
"weapons/knife_slash1.wav",
    
"weapons/knife_slash2.wav",
    
"weapons/knife_stab.wav"
}

public 
register_class_data()
{
    
g_zclassid1 register_class(D_ZOMBIE_NAMED_ZOMBIE_DESC)

    if(
g_zclassid1 != -1)
    {
        
set_class_data(g_zclassid1DATA_HEALTH259.0)
        
set_class_data(g_zclassid1DATA_SPEED250.0)
        
set_class_data(g_zclassid1DATA_GRAVITY0.80)
        
set_class_data(g_zclassid1DATA_ATTACK3.5)
                
set_class_data(g_zclassid1DATA_HITREGENDLY6.0)
        
set_class_pmodel(g_zclassid1D_PLAYER_MODEL)
        
set_class_wmodel(g_zclassid1D_CLAWS)
    }
}

public 
plugin_init()
{
    
register_plugin("[ZP] Chainsaw Zombie Class""0.1""Artos")
    
    
register_forward(FM_EmitSound"fw_EmitSound");

        
register_class_data()
}

public 
plugin_precache()
{    
    for(new 
0sizeof chainsaw_soundsi++)
        
precache_sound(chainsaw_sounds[i])

        
precache_model(PMODEL)
    
precache_model(D_CLAWS)
}

public 
fw_EmitSound(idchannel, const sound[])
{
    if(!
is_user_alive(id) || get_user_class(id) != g_zclassid1 || !is_user_zombie(id))
        return 
FMRES_IGNORED
        
    
for(new 0sizeof chainsaw_soundsi++)
    {
        if(
equal(soundknife_sounds[i]))
        {
            
emit_sound(idchannelchainsaw_sounds[i], 1.0ATTN_NORM0PITCH_NORM)
            return 
FMRES_SUPERCEDE
        
}
    }
            
    return 
FMRES_IGNORED


Last edited by Krtola; 03-06-2015 at 08:24.
Krtola is offline
Send a message via Skype™ to Krtola
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-06-2015 , 08:34   Re: |HELP| How to add on/off for zombie class
Reply With Quote #2

You will have to modify the main plugin in order to do so.
__________________
Currently offline for study.
RateX is offline
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 03-06-2015 , 08:38   Re: |HELP| How to add on/off for zombie class
Reply With Quote #3

Quote:
Originally Posted by RateX View Post
You will have to modify the main plugin in order to do so.
I understand, as it is done in ZP.
But if there's a way,the whole plugin(this class) can turn on or off during games/round?
Krtola is offline
Send a message via Skype™ to Krtola
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-06-2015 , 08:46   Re: |HELP| How to add on/off for zombie class
Reply With Quote #4

Nope, as the menu is handled by the main plugin.
__________________
Currently offline for study.
RateX is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 03-06-2015 , 08:52   Re: |HELP| How to add on/off for zombie class
Reply With Quote #5

Just try below:
Code:
public register_class_data()
{
    g_zclassid1 = register_class(D_ZOMBIE_NAME, D_ZOMBIE_DESC)

    if(g_zclassid1 != -1)
    {
        set_class_data(g_zclassid1, DATA_HEALTH, 259.0)
        set_class_data(g_zclassid1, DATA_SPEED, 250.0)
        set_class_data(g_zclassid1, DATA_GRAVITY, 0.80)
        set_class_data(g_zclassid1, DATA_ATTACK, 3.5)
                set_class_data(g_zclassid1, DATA_HITREGENDLY, 6.0)
        set_class_pmodel(g_zclassid1, D_PLAYER_MODEL)
        set_class_wmodel(g_zclassid1, D_CLAWS)
    }
}

public plugin_init()
{
    register_plugin("[ZP] Chainsaw Zombie Class", "0.1", "Artos")
    
    register_forward(FM_EmitSound, "fw_EmitSound");

        register_class_data()
}
-->
Code:
new g_iClassOnOff

public plugin_init()
{
    register_plugin("[ZP] Chainsaw Zombie Class", "0.1", "Artos")
    
    register_forward(FM_EmitSound, "fw_EmitSound");
    
    g_iClassOnOff = register_cvar("cs_class_onoff", "1") // On or Off zombie class
    
    register_class_data()
}

public register_class_data()
{
    if(get_pcvar_num(g_iClassOnOff))
    {
        g_zclassid1 = register_class(D_ZOMBIE_NAME, D_ZOMBIE_DESC)

        if(g_zclassid1 != -1)
        {
            set_class_data(g_zclassid1, DATA_HEALTH, 259.0)
            set_class_data(g_zclassid1, DATA_SPEED, 250.0)
            set_class_data(g_zclassid1, DATA_GRAVITY, 0.80)
            set_class_data(g_zclassid1, DATA_ATTACK, 3.5)
                    set_class_data(g_zclassid1, DATA_HITREGENDLY, 6.0)
            set_class_pmodel(g_zclassid1, D_PLAYER_MODEL)
            set_class_wmodel(g_zclassid1, D_CLAWS)
        }
    }
}
zmd94 is offline
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 03-06-2015 , 09:12   Re: |HELP| How to add on/off for zombie class
Reply With Quote #6

@zmd94 I just tested,but does not work.Seems to be impossible.
Krtola is offline
Send a message via Skype™ to Krtola
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 03-06-2015 , 09:22   Re: |HELP| How to add on/off for zombie class
Reply With Quote #7

Alright.
zmd94 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-06-2015 , 10:24   Re: |HELP| How to add on/off for zombie class
Reply With Quote #8

It doesn't work because the register_class_data() forward only call once, so everytime you change cvar, you have to restart your server.
As I said, the only option is to modify the main plugin.
__________________
Currently offline for study.
RateX is offline
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 03-06-2015 , 11:56   Re: |HELP| How to add on/off for zombie class
Reply With Quote #9

Quote:
Originally Posted by RateX View Post
It doesn't work because the register_class_data() forward only call once, so everytime you change cvar, you have to restart your server.
As I said, the only option is to modify the main plugin.
Can you give me some guidance,on what to look for in zp main plugin,and try to pull code from there then to apply in my biohazard?
Krtola is offline
Send a message via Skype™ to Krtola
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-06-2015 , 12:58   Re: |HELP| How to add on/off for zombie class
Reply With Quote #10

Since you're using biohazard, why don't you work on it directly.
I'm about to sleep, so I'm gonna show you some basic step.
1. Add
PHP Code:
#define DATA_YOURNAME 11
#define CLASS_HIDEMENUON 1.0
#define CLASS_HIDEMENUOFF 0.0 
in both main plugin and inc file(so your plugin can use it).
2. Add a cvar in main plugin to enable and disable this feature.
3. In main plugin, display_classmenu funtion, in the first loop, use native_get_class_data to check if it's equal CLASS_HIDEMENUON. If true, and the cvar is on, add "continue". Else execute the rest of the code.
__________________
Currently offline for study.
RateX 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 12:57.


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