AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weapon firing when MOTD appears | CVAR not updating | (https://forums.alliedmods.net/showthread.php?t=309009)

edon1337 07-10-2018 09:01

Weapon firing when MOTD appears | CVAR not updating |
 
Hi,

1. So when I kill someone a MOTD is supposed to appear to me, but after I kill him and the MOTD appears I'm unable to stop the gun firing, so it automatically keeps shooting until I'm out of ammo. Why does this loop happen?

2. My CVARs don't update when I first get in the game, I have to use 'restart' command so it can be fully updated. Basically this is my code that sets the CVARs.
PHP Code:

public plugin_init( )
{        
    
g_iCvars] = register_cvar"cs_battleroyale_team_num""6" ); // number of teams
    
g_iCvars] = register_cvar"cs_battleroyale_player_per_team""4" ); // number of players in one team
    
    
g_iMaxTeams get_pcvar_numg_iCvars] );
    
g_iPlayerPerTeam get_pcvar_numg_iCvars] );


while in my amxx.cfg it's
Quote:

cs_battleroyale_team_num 4
cs_battleroyale_player_per_team 2
When I join game for the first time I get 'Number of teams: 6 | Number of players per team: 4' same as inside the .sma , but when I restart it is same as amxx.cfg
Why is this?

CrazY. 07-10-2018 09:49

Re: Weapon firing when MOTD appears | CVAR not updating |
 
That's considered a bug, the same happens if you hold IN_ATTACK and open the console. I believe you can fix that "holstering" and "deploying" the active item of the player when motd be shown. Or you can "supercede" the primary attack if the motd is current opened.

I'm not sure, but you need to set these variables in plugin_cfg, not in plugin_init.

Code:
g_iMaxTeams = get_pcvar_num( g_iCvars[ 0 ] ); g_iPlayerPerTeam = get_pcvar_num( g_iCvars[ 1 ] );

^SmileY 07-10-2018 09:55

Re: Weapon firing when MOTD appears | CVAR not updating |
 
You need to force the player stop shooting before call show_motd

Also here

g_iMaxTeams = get_pcvar_num( g_iCvars[ 0 ] );
g_iPlayerPerTeam = get_pcvar_num( g_iCvars[ 1 ] );

Is fine, is not needed to move into plugin_cfg.
but why not use get_pcvar_num( g_iCvars[ 0 ] ) on plugin, instead of g_iMaxTeams, is needed to fix this variable to initial value? same to other g_iPlayerPerTeam??

edon1337 07-10-2018 12:35

Re: Weapon firing when MOTD appears | CVAR not updating |
 
Quote:

Originally Posted by ^SmileY (Post 2602643)
You need to force the player stop shooting before call show_motd

Also here

g_iMaxTeams = get_pcvar_num( g_iCvars[ 0 ] );
g_iPlayerPerTeam = get_pcvar_num( g_iCvars[ 1 ] );

Is fine, is not needed to move into plugin_cfg.
but why not use get_pcvar_num( g_iCvars[ 0 ] ) on plugin, instead of g_iMaxTeams, is needed to fix this variable to initial value? same to other g_iPlayerPerTeam??

g_iMaxTeams is just a variable that holds the cached value of cs_battleroyale_team_num CVAR, is that what you asked?

Full code here, if you want to check:
PHP Code:

#include < amxmodx >
#include < hamsandwich >
#include < fakemeta >
#include < fun >
#include < cstrike >

#define MAX_PLAYERS 32
#define NO_TEAM 0

new g_iPlayerPerTeam;
new 
g_iMaxTeams;

new 
g_iCvars];

new 
g_iTeammatesMAX_PLAYERS ];
new 
g_iPlayerTeamMAX_PLAYERS ];

new 
HamHook:g_iHamTakeDamageFw;
new 
HamHook:g_iHamTraceAttackFw;
new 
HamHook:g_iHamKilledFw;

public 
plugin_init( )
{
    
register_plugin"CS Battle Royale Fake Teams""1.0""DoNii" );
        
    
g_iCvars] = register_cvar"cs_battleroyale_team_num""6" ); // number of teams
    
g_iCvars] = register_cvar"cs_battleroyale_player_per_team""4" ); // number of players in one team
    
    
g_iMaxTeams get_pcvar_numg_iCvars] );
    
g_iPlayerPerTeam get_pcvar_numg_iCvars] );
    
    
register_event"HLTV""OnNewRound""a""1=0""2=0" );
    
    
g_iHamTakeDamageFw RegisterHamHam_TakeDamage"player""fw_HamTakeDamagePre");
    
DisableHamForwardg_iHamTakeDamageFw );
    
    
g_iHamTraceAttackFw RegisterHamHam_TraceAttack"player""fw_HamTraceAttackPre");
    
DisableHamForwardg_iHamTraceAttackFw );
    
    
g_iHamKilledFw RegisterHamHam_Killed"player""fw_HamKilledPre");
    
DisableHamForwardg_iHamKilledFw );
}

public 
plugin_cfg( )
{
    
EnableHamForwardg_iHamTakeDamageFw );
    
EnableHamForwardg_iHamTraceAttackFw );
    
EnableHamForwardg_iHamKilledFw );
}

public 
plugin_natives( )
{
    
register_library"cs_battleroyale_faketeams" );

    
register_native"GetPlayerTeam""OnNativeGetPlayerTeam");
    
register_native"SetPlayerTeam""OnNativeSetPlayerTeam");
    
    
register_native"GetMaxTeams""OnNativeGetMaxTeams");
    
register_native"SetMaxTeams""OnNativeSetMaxTeams");
    
register_native"GetPlayerPerTeam""OnNativeGetPlayerPerTeam");
    
register_native"SetPlayerPerTeam""OnNativeSetPlayerPerTeam");
}

public 
OnNativeGetPlayerTeamid )
{
    if( ! 
is_user_connectedid ) )
    return -
1;

    return 
g_iPlayerTeamid ];
}

public 
OnNativeSetPlayerTeamidiTeam )
{
    if( ! 
is_user_connectedid ) )
    return -
1;

    
g_iPlayerTeamid ] = iTeam;
    return 
1;
}

public 
OnNativeGetMaxTeams( )
{
    return 
g_iMaxTeams;
}

public 
OnNativeSetMaxTeamsiValue )
{
    if( !( 
<= iValue <= MAX_PLAYERS ) )
    return -
1;

    
g_iMaxTeams iValue;
    return 
1;
}

public 
OnNativeGetPlayerPerTeam( )
{
    return 
g_iPlayerPerTeam;
}

public 
OnNativeSetPlayerPerTeamiValue )
{
    if( !( 
<= iValue <= MAX_PLAYERS ) )
    return -
1;

    
g_iPlayerPerTeam iValue;
    return 
1;
}

public 
client_disconnectid )
{
    if( 
g_iPlayerTeamid ] != NO_TEAM )
    {
        
g_iTeammatesg_iPlayerTeamid ] ]--;
        
g_iPlayerTeamid ] = NO_TEAM;
    }
    
g_iPlayerTeamid ] = NO_TEAM;
}

public 
client_connectid )
{
    
g_iPlayerTeamid ] = NO_TEAM;
    
FindAvailableTeamid );
}

public 
fw_HamKilledPreiVictimiAttackeriShouldGib )
{
    if( 
iVictim == iAttacker )
    return 
HAM_IGNORED;

    new 
iVictimTeam get_user_teamiVictim );
    
    if( 
g_iPlayerTeamiVictim ] != g_iPlayerTeamiAttacker ] )
    {
        if( 
iVictimTeam == get_user_teamiAttacker ) )
        {
            
cs_set_user_teamiVictimiVictimTeam == );
        }
        return 
HAM_IGNORED;
    }
    return 
HAM_SUPERCEDE;
}

public 
fw_HamTraceAttackPreiVictimiAttackerFloat:fDamageFloat:fDir], iPtriDamageType )
{
    if( 
iVictim == iAttacker )
    return 
HAM_IGNORED;

    new 
iVictimTeam get_user_teamiVictim );
    
    if( 
g_iPlayerTeamiVictim ] != g_iPlayerTeamiAttacker ] )
    {
        if( 
iVictimTeam == get_user_teamiAttacker ) )
        {
            
cs_set_user_teamiVictimiVictimTeam == );
            
ExecuteHamBHam_TraceAttackiVictimiAttackerfDamagefDiriPtriDamageType);
            
cs_set_user_teamiVictimiVictimTeam );
        }
        return 
HAM_IGNORED;
    }
    
SetHamParamFloat30.0 );
    return 
HAM_SUPERCEDE;
}

public 
fw_HamTakeDamagePreiVictimiInflictoriAttackerFloat:fDamageiDamageBits )
{    
    if( 
iVictim == iAttacker )
    return 
HAM_IGNORED;
    
    new 
iVictimTeam get_user_teamiVictim );
    
    if( 
g_iPlayerTeamiVictim ] != g_iPlayerTeamiAttacker ] )
    {
        if( 
iVictimTeam == get_user_teamiAttacker ) )
        {
            
cs_set_user_teamiVictimiVictimTeam == );
            
ExecuteHamBHam_TakeDamageiVictimiInflictoriAttackerfDamageiDamageBits );
            
cs_set_user_teamiVictimiVictimTeam );
        }
        return 
HAM_IGNORED;
    }
    
SetHamParamFloat40.0 );
    return 
HAM_SUPERCEDE;
}

public 
OnNewRound( )
{
    static 
szPlayers32 ], iNum;
    
get_playersszPlayersiNum"a" );

    static 
iTempID;
    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];

        if( 
g_iPlayerTeamiTempID ] == NO_TEAM && ( ( <= get_user_teamiTempID ) <= ) ) )
        {
            
FindAvailableTeamiTempID );
        }
    }
}

FindAvailableTeamid )
{
    for( new 
iTeam=1iTeam <= g_iMaxTeamsiTeam++ )
    {
        if( 
IsTeamAvailableiTeam ) )
        {
            
g_iPlayerTeamid ] = iTeam;
            
g_iTeammatesiTeam ]++;
            
            break;
        }
        continue;
    }
}

IsTeamAvailableiTeam )
{
    return 
g_iTeammatesiTeam ] < g_iPlayerPerTeam 0;


Quote:

Originally Posted by CrazY. (Post 2602641)
That's considered a bug, the same happens if you hold IN_ATTACK and open the console. I believe you can fix that "holstering" and "deploying" the active item of the player when motd be shown. Or you can "supercede" the primary attack if the motd is current opened.

I'm not sure, but you need to set these variables in plugin_cfg, not in plugin_init.

Code:
g_iMaxTeams = get_pcvar_num( g_iCvars[ 0 ] ); g_iPlayerPerTeam = get_pcvar_num( g_iCvars[ 1 ] );

I already tried using plugin_cfg but it didn't change anything.
About the MOTD thanks I'll try it.

CrazY. 07-10-2018 12:46

Re: Weapon firing when MOTD appears | CVAR not updating |
 
Check cvars.ini too.

edon1337 07-10-2018 17:26

Re: Weapon firing when MOTD appears | CVAR not updating |
 
Quote:

Originally Posted by CrazY. (Post 2602719)
Check cvars.ini too.

Do I have to put CVARs that I put in amxx.cfg in cvars.ini too?

edon1337 07-12-2018 12:13

Re: Weapon firing when MOTD appears | CVAR not updating |
 
I tried setting 9999.9 delay and returning HAM_SUPERCEDE in Ham_Weapon_PrimaryAttack but it didn't stop player from shooting

Ghosted 07-12-2018 13:42

Re: Weapon firing when MOTD appears | CVAR not updating |
 
Quote:

Originally Posted by edon1337 (Post 2603158)
I tried setting 9999.9 delay and returning HAM_SUPERCEDE in Ham_Weapon_PrimaryAttack but it didn't stop player from shooting

Can you post code?

edon1337 07-12-2018 16:15

Re: Weapon firing when MOTD appears | CVAR not updating |
 
PHP Code:

new bool:g_bVictoryBlockAttack33 ];

#define g_iBitsum (1<<CSW_P228)|(1<<CSW_GLOCK)|(1<<CSW_C4)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_UMP45)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)

public plugin_init( )
{
    for( new 
CSW_P228<= CSW_P90i++ )
    {
        if( 
g_iBitsum & (1<<i) )
        continue;
        
        
get_weaponnameiszWeaponNamecharsmaxszWeaponName ) );
        
RegisterHamHam_Weapon_PrimaryAttackszWeaponName"@HamPrimaryAttack_Pre" );
    }
}

public @
HamPrimaryAttack_PreiEnt )
{
    new 
id;
    
id peviEntpev_owner );
    
    if( 
g_bVictoryBlockAttackid ] )
    {
        
set_pdata_floatiEntm_flNextPrimaryAttack9999.9);
        return 
HAM_SUPERCEDE;
    }
    
    return 
HAM_IGNORED;
}

VictoryiPlayer )
{
    new 
szPlayers32 ], iNumiTempID;
    
get_playersszPlayersiNum"a" );
    
    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];
        
g_bVictoryBlockAttackiTempID ] = true;
    }



^SmileY 07-12-2018 16:54

Re: Weapon firing when MOTD appears | CVAR not updating |
 
This m_flNextPrimaryAttack will not work since weapon is already fired.

set_pdata_int(id, m_bCanShoot, false);

Try with


All times are GMT -4. The time now is 12:36.

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