AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with buttons (https://forums.alliedmods.net/showthread.php?t=233555)

kiryxa 01-16-2014 14:52

Help with buttons
 
Hello, i want that when i use the button "w"(I go forward),i move back
I try it:
Code:

public client_PreThink(id)
{
new iButton = get_user_button(id)
if(iButton & IN_FORWARD)
{
client_print(id, print_center, "test")
entity_set_int(id,EV_INT_button,iButton & ~IN_FORWARD & IN_BACK)
}
}

But it does not work.I go forward.Why?Others ideas?

.Dare Devil. 01-16-2014 15:47

Re: Help with buttons
 
What did you do there?
Anyway, try this:
PHP Code:

public client_PreThink(id)
{
    new 
iButton get_user_button(id)
    if(
iButton IN_FORWARD)
    {
        
client_print(idprint_center"test")
        
iButton &= ~IN_FORWARD
        iButton 
|= IN_BACK
        entity_set_int
(id,EV_INT_button,iButton)
    }



kiryxa 01-17-2014 00:13

Re: Help with buttons
 
Your does not work(
I want that this code was for shock grenade for zp.When human shocked this grenade,when he goes forward,he goes back.After graduating from shock human goes normally.
Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <fun>
#include <engine>
#include <zombieplague>
#include <fakemeta_util>

// Plugin version
#define VERSION "1.4"

// Defines
#define MAXPLAYERS        32
#define FCVAR_FLAGS        ( FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
#define OFFSET_PLAYER        41
#define OFFSET_ACTIVE        373
#define LINUX_DIFF        5
#define NADE_TYPE_CONC        7000
#define FFADE_IN        0x0000
#define REPEAT                0.1 // Time when next screen fade/shake message is being sent
#define TASK_AFFECT        666
#define ID_AFFECT        ( taskid - TASK_AFFECT )
#define OFFSET_FLAMMO        387

// Grenade cost
#define GRENADE_COST        5
#define MAXCARRY    5 // Лимит гранат

// Grenade models
new const grenade_model_w[] = "models/zp_cso/grenades/w_grenad_s3.mdl"

// Sounds
new const explosion_sound [ ] = "zp_cso/shockbomb/concgren_blast1.wav"
new const purchase_sound2 [ ] = "items/9mmclip1.wav"

// Cached sprite indexes
new m_iTrail, m_iRing

// Item ID
new g_conc

new g_MaxPlayers

// Player variables
new g_NadeCount [ MAXPLAYERS+1 ]

// Message ID's
new g_msgScreenFade, g_msgScreenShake

// CVAR pointers
new cvar_nade_radius, cvar_duration

// Precache
public plugin_precache ( )
{
        // Precache grenade models
        precache_model ( grenade_model_w )
       
        // Precache sounds
        precache_sound ( explosion_sound )
        precache_sound ( purchase_sound2 )
       
        // Precache sprites
        m_iRing = precache_model ( "sprites/zp_cso/cso_expgrenadeV2.spr" )
        m_iTrail = precache_model ( "sprites/laserbeam.spr" )
}

// Plugin initialization
public plugin_init ( )
{
        // New plugin
        register_plugin ( "[CSO:Shock grenade]", VERSION, "NiHiLaNTh" )
       
        // Add cvar to detect servers with this plugin
        register_cvar ( "zp_concgren_version", VERSION, FCVAR_FLAGS )
       
        // New extra item
        g_conc = zp_register_extra_item ( "Conc Grenade", GRENADE_COST, ZP_TEAM_ZOMBIE )
       
        // Events
        register_event ( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )
        register_event ("DeathMsg", "EV_DeathMsg", "a")
       
        // Forwards
        register_forward ( FM_SetModel, "fw_SetModel" )
        RegisterHam ( Ham_Think, "grenade", "fw_ThinkGrenade" )
        register_forward ( FM_CmdStart, "fw_CmdStart" )
       
        // CVARs
        cvar_nade_radius = register_cvar ( "zp_conc_nade_radius", "600" )
        cvar_duration = register_cvar ( "zp_conc_nade_duration", "7" )
       
        // Messages
        g_msgScreenShake = get_user_msgid ( "ScreenShake" )
        g_msgScreenFade = get_user_msgid ( "ScreenFade" )
       
        g_MaxPlayers = get_maxplayers()
       
        register_dictionary("zp_extra_conc.txt")
}

// Someone decided to buy our an extra item
public zp_extra_item_selected ( Player, Item )
{
        // This is our grenade
        if ( Item == g_conc )
        {       
                // Player already have it
                if ( g_NadeCount [ Player ] >= 1 )
                {
                        // Increase nade count
                        g_NadeCount [ Player ]++
                       
                        print_col_chat(Player, "^4[ZP] ^1%L", Player, "BY_CON")
                       
                        // Increase bp ammo
                        set_pdata_int ( Player, OFFSET_FLAMMO, get_pdata_int ( Player, OFFSET_FLAMMO, LINUX_DIFF )+1, LINUX_DIFF )
                       
                        AmmoPickup ( Player, 11, 1 )
                       
                        // Emit sound
                        emit_sound ( Player, CHAN_WEAPON, purchase_sound2, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
                        ShowWeaponPickup(Player, CSW_FLASHBANG)
                }
                else // 0 grenades
                {                       
                        // Increase nade count
                        g_NadeCount [ Player ] = 1
                       
                        // Give him flashbang
                        give_item ( Player, "weapon_flashbang" )
                        print_col_chat(Player, "^4[ZP] ^1%L", Player, "BY_CON")
                       
                        AmmoPickup ( Player, 11, 1 )
                }
        }
        return PLUGIN_CONTINUE
}

public client_connect ( id )
{
        g_NadeCount [ id ] = 0
}

public client_disconnect(id)
{
        g_NadeCount [ id ] = 0
}
       
// Someone was infected       
public zp_user_infected_post ( Player, Infector )
{
       
        // We were affected by concussion grenade
        if ( task_exists ( Player+TASK_AFFECT ) )
                remove_task ( Player+TASK_AFFECT )
}       

stock ShowWeaponPickup(id, iWeaponId)
{
        static iMsgWeaponPickup;

        if(!iMsgWeaponPickup)
        iMsgWeaponPickup = get_user_msgid("WeapPickup");

        message_begin(MSG_ONE_UNRELIABLE, iMsgWeaponPickup, _, id);
        write_byte(iWeaponId);
        message_end();
}

public AmmoPickup ( id, AmmoID, AmmoAmount )
{
        message_begin ( MSG_ONE, get_user_msgid ( "AmmoPickup" ), _, id )
        write_byte ( AmmoID )
        write_byte ( AmmoAmount )
        message_end ( )
}

// Someone were turned back to human
public zp_user_humanized_post ( Player, Survivor )
{
        // We dont' have nade anymore
        if ( g_NadeCount [ Player ] )
        {
                g_NadeCount [ Player ] = 0
        }
}

// New round started
public Event_NewRound ( )
{
        // Reset nade count
        arrayset ( g_NadeCount, false, 33 )
               
        // And they aren't affected by conc.grenade
        remove_task ( TASK_AFFECT )       
}

public EV_DeathMsg()
{       
        new iVictim = read_data (2)

        if (!is_user_connected(iVictim))
                return;
               
        if(!zp_get_user_zombie(iVictim))
                return
                               
        ham_strip_weapon(iVictim,"weapon_flashbang")

        g_NadeCount[iVictim] = 0
}

// Someone died
public Event_DeathMsg ( )
{
        // Get victim
        new victim = read_data ( 2 )
       
        // Some people had error without this check
        if ( !is_user_connected ( victim ) )
                return
       
        // Remove hallucinations
        remove_task ( victim+TASK_AFFECT )
               
        // Reset nade count       
        g_NadeCount [ victim ] = 0
}

public zp_round_ended()
{
    for (new id = 1; id <= g_MaxPlayers; id++)
    {
        if( !is_user_alive( id ) )
            continue
       
        if(zp_get_user_zombie(id))

        {
            g_NadeCount[id] = 0;
            ham_strip_weapon(id, "weapon_flashbang")
        } 
    }
}

stock ham_strip_weapon(id, weapon[])
{
    if(!equal(weapon,"weapon_",7)) 
        return 0
   
    new wId = get_weaponid(weapon)
   
    if(!wId) return 0
   
    new wEnt
   
    while((wEnt = find_ent_by_class(wEnt, weapon)) && entity_get_edict(wEnt, EV_ENT_owner) != id) {}
   
    if(!wEnt) return 0
   
    if(get_user_weapon(id) == wId) 
        ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
   
    if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) 
        return 0
       
    ExecuteHamB(Ham_Item_Kill, wEnt)
   
    entity_set_int(id, EV_INT_weapons, entity_get_int(id, EV_INT_weapons) & ~(1<<wId))

    return 1
}

// Set model
public fw_SetModel ( Entity, const Model [ ] )
{
        // Prevent invalid ent messages
        if ( !pev_valid ( Entity ) )
                return FMRES_IGNORED
               
        // Grenade not thrown yet       
        if ( pev ( Entity, pev_dmgtime ) == 0.0 )
                return FMRES_IGNORED
               
        // We are throwing concussion grenade       
        if ( g_NadeCount [ pev ( Entity, pev_owner ) ] >= 1 && equal ( Model [7 ], "w_fl", 4 ) )
        {
                //Draw trail
                message_begin ( MSG_BROADCAST, SVC_TEMPENTITY )
                write_byte ( TE_BEAMFOLLOW ) // Temp entity ID
                write_short ( Entity ) // Entity to follow
                write_short ( m_iTrail ) // Sprite index
                write_byte ( 10 ) // Life
                write_byte ( 10 ) // Line width
                write_byte ( 0 ) // Red amount
                write_byte ( 190 ) // Green amount
                write_byte ( 250 ) // Blue amoun
                write_byte ( 255 ) // Alpha
                message_end ( )
               
                // Set grenade entity
                set_pev ( Entity, pev_flTimeStepSound, NADE_TYPE_CONC )
               
                // Decrease nade count
                g_NadeCount [ pev ( Entity, pev_owner ) ]--
               
                fm_set_rendering(Entity, kRenderFxGlowShell, 0, 190, 250, kRenderNormal, 16)
                engfunc ( EngFunc_SetModel, Entity, grenade_model_w )
                set_pev(Entity, pev_body, 3)
         
                return FMRES_SUPERCEDE
        }
        return FMRES_IGNORED
}

public fw_ThinkGrenade ( Entity )
{
        if ( !pev_valid ( Entity ) )
                return HAM_IGNORED
       
        // Get damage time
        static Float:dmg_time
        pev ( Entity, pev_dmgtime, dmg_time )
       
        if ( dmg_time > get_gametime ( ) )
                return HAM_IGNORED
               
        if ( pev ( Entity, pev_flTimeStepSound ) == NADE_TYPE_CONC )
        {
                concussion_explode ( Entity )
                return HAM_SUPERCEDE
        }
        return HAM_IGNORED
}

public fw_CmdStart ( Player, UC_Handle, Seed )
{
        if ( !is_user_alive ( Player ) || zp_get_user_zombie ( Player ) || !task_exists ( Player+TASK_AFFECT ) )
                return FMRES_IGNORED
       
        new buttons = get_uc ( UC_Handle, UC_Buttons )
       
        if ( buttons & IN_ATTACK )
        {
                if ( get_pdata_cbase ( Player, OFFSET_ACTIVE, LINUX_DIFF ) )
                {
                        set_pev ( Player, pev_punchangle, Float:{3.0, 3.0, 4.0} )
                }
        }
        return FMRES_HANDLED
}
                       
public concussion_explode ( Entity )
{
        if ( !pev_valid ( Entity  ) )
                return
       
        static Float:origin [ 3 ]
        pev ( Entity, pev_origin, origin )
       
        UTIL_DrawRing (origin )
       
        emit_sound ( Entity, CHAN_WEAPON, explosion_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
       
        static victim
        victim = -1
       
        static Float:radius
        radius = get_pcvar_float ( cvar_nade_radius )
       
        while ( ( victim = engfunc ( EngFunc_FindEntityInSphere, victim, origin, radius ) ) != 0 )
        {
                if ( !is_user_alive ( victim ) || zp_get_user_zombie ( victim ) )
                        continue
                               
                if ( !task_exists ( victim+TASK_AFFECT ) )
                {
                        new duration = get_pcvar_num ( cvar_duration )
                       
                        new affect_count = floatround ( duration / REPEAT )
                       
                        set_task ( REPEAT, "affect_victim", victim+TASK_AFFECT, _, _, "a", affect_count )
                }
        }
       
        // Remove entity from ground
        engfunc ( EngFunc_RemoveEntity, Entity )
}

// We are going to affect you
public affect_victim ( taskid )
{
        if ( !is_user_alive ( ID_AFFECT ) )
                return
               
        message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenFade, {0,0,0}, ID_AFFECT )
        write_short ( 1<<13 ) // Duration
        write_short ( 1<<14 ) // Hold Time
        write_short ( FFADE_IN ) // Fade type
        write_byte ( random_num ( 50, 200 ) ) // Red amount
        write_byte ( random_num ( 50, 200 ) ) // Green amount
        write_byte ( random_num ( 50, 200 ) ) // Blue amount
        write_byte ( random_num ( 50, 200 ) ) // Alpha
        message_end ( )
               
        message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT )
        write_short ( 0xFFFF ) // Amplitude
        write_short ( 1<<13 ) // Duration
        write_short ( 0xFFFF ) // Frequency
        message_end ( )

        remove_task ( ID_AFFECT )
}

stock UTIL_DrawRing ( const Float:origin [ 3 ] )
{
        engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
        write_byte(TE_BEAMCYLINDER) // TE id
        engfunc(EngFunc_WriteCoord, origin[0]) // x
        engfunc(EngFunc_WriteCoord, origin[1]) // y
        engfunc(EngFunc_WriteCoord, origin[2]) // z
        engfunc(EngFunc_WriteCoord, origin[0]) // x axis
        engfunc(EngFunc_WriteCoord, origin[1]) // y axis
        engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
        write_short( m_iRing ) // sprite
        write_byte(0) // startframe
        write_byte(0) // framerate
        write_byte(4) // life
        write_byte(60) // width
        write_byte(10) // noise
        write_byte(0) // red
        write_byte(190) // green
        write_byte(255) // blue
        write_byte(255) // brightness
        write_byte(0) // speed
        message_end()
}

stock print_col_chat(const id, const input[], any:...)
{
    new count = 1, players[32];
    static msg[191];
    vformat(msg, 190, input, 3);
    replace_all(msg, 190, "!g", "^4") 
    replace_all(msg, 190, "!y", "^1") 
    replace_all(msg, 190, "!t", "^3")
    if (id) players[0] = id; else get_players(players, count, "ch")
    {
        for ( new i = 0; i < count; i++ )
        {
            if ( is_user_connected(players[i]) )
            {
                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
                write_byte(players[i]);
                write_string(msg);
                message_end();
            }
        }
    }
}


ConnorMcLeod 01-17-2014 01:09

Re: Help with buttons
 
You have to change pmove properties, not pev:

https://forums.alliedmods.net/showth...03#post1173503

kiryxa 01-19-2014 06:22

Re: Help with buttons
 
Sorry, buy i do not understand i do not know the orpheu module.I want without orpheu

ConnorMcLeod 01-19-2014 07:09

Re: Help with buttons
 
Then, you can't.


All times are GMT -4. The time now is 10:06.

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