Create customs Modes

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Create customs Modes

Post by Archive-Poster »

Well, i was doing a plugin about modes like zombie plague but for normal gameplay (not zp).

So, i took the zp code and passed it to a normal code (without zombie plague include)

(Sorry my english)

Here is:

So we add the includes and definitions:

Code: Select all

/* Create Modes with Zombie Plague style, but for normal Counter Strike */

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich> 

#define VERSION "1.0"

new cvar_mode, cvar_min_players, cvar_chance //We register our pcvars
new g_newround
new g_endround
new g_lastmode
new g_modexample //And the Variables

/*Also we have to enum our modes for the game */
enum
{
    MODE_NONE = 0,
    MODE_ONE
} 
Here our plugin_init()

Code: Select all

public plugin_init() 
{
    register_plugin("My Modes", VERSION, "Zapdos1") //We register the Plugin Name and the Plugin Author
    
    register_event( "HLTV", "RoundStart", "a", "1=0", "2=0" ) //Here the RoundStart event (When the round starts)
    register_logevent("Round_end", 2, "1=Round_End") //Here the round_end event (When the round ends)
    RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage") //Here when the player takes damage
    
    //Aquí registramos las pcvars
    cvar_mode = register_cvar("modes_toggle", "1") //If the modes are enabled
    cvar_min_players = register_cvar("mode_min_players", "2")
    cvar_chance = register_cvar("mode_chances", "50")
} 
Later ours RoundStart and Round_end events

Code: Select all

public RoundStart()
{
    g_newround = true
    g_endround = false
    g_modexample = false
    
    set_task(2.0, "go_to_mode") //Later of setting the Variables true or false, we set a task to the public "go_to_mode"
}

public Round_end()
{
    g_newround = false //We set again this false
    g_endround = true //And this true
} 
The modes code:

Code: Select all

public go_to_mode()
{
    start_mode(NO_MODE) 
}

start_mode(mode)
{
    static iPlayersnum
    iPlayersnum = get_playersnum() //We get the number of players 
    
    if (iPlayersnum < 1) //If players number < 1, start with no mode 
    {
        set_task(2.0, "go_to_mode")
        return;
    }
    
    g_newround = false 
    
    if ((mode == MODE_NONE || (g_lastmode != MODE_ONE) && random_num(1, get_pcvar_num(cvar_chance)) && get_pcvar_num(cvar_modo) && iPlayersnum >= get_pcvar_num(cvar_min_jugadores)) || mode == MODE_ONE)
    { 
        g_modexample = true //Our mode is now true
        g_lastmode = MODE_ONE  
        
        set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 5.0) //So we send a message to the players
        show_hudmessage(0, "The example mode was started!")
    }
} 
If you compile now your plugin, the Amxx-Studio is going to tells you, than you are not using the Variables

So we are going to use them...

Code: Select all

public fw_TakeDamage(victim)
{
    if (g_newround || g_endround)
    return HAM_SUPERCEDE;
    
    if (g_modexample) 
    return HAM_IGNORED; //The mode can't affect the gameplay, so we return it 
    
    return PLUGIN_CONTINUE;
} 
Remember than i passed from the zombie plague code to the normal code, and I'm posting this to help you if you want to do modes for your plugin
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: Create customs Modes

Post by Archive-Poster »

Why are you using hltv event to hook round start and not the normal logevent?
So, i took the zp code and passed it to a normal code
Don't blindly take codes if you don't know the difference, if you post in this section its because you can help others.
i posted that code, just to help to anybody than wants to do modes for his plugin
t ur last example you shouldnt use return plugin_continue, but you should use ham_ignored
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest