AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   2 c4 at roundstart (https://forums.alliedmods.net/showthread.php?t=164401)

katna 08-11-2011 03:16

2 c4 at roundstart
 
i had a problem with c4 detection at round start to i tried to fix it. anyway
i need to save the c4 to a global varible at the roundstart event. The problem is at the round start its detect 2 weapon_c4 and 0.1 its detect only 1 ( only when mp_freezetime 0), when mp_freezetime is bigger then 0 then there is no problem with the c4

Code:

new ent, count
while((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", "weapon_c4")))
{
    count++
}
       
ColorChat(0, "%d c4 detected", count)


Doc-Holiday 08-11-2011 03:52

Re: 2 c4 at roundstart
 
Quote:

Originally Posted by katna (Post 1530098)
i had a problem with c4 detection at round start to i tried to fix it. anyway
i need to save the c4 to a global varible at the roundstart event. The problem is at the round start its detect 2 weapon_c4 and 0.1 its detect only 1 ( only when mp_freezetime 0), when mp_freezetime is bigger then 0 then there is no problem with the c4

Code:

new ent, count
while((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", "weapon_c4")))
{
    count++
}
   
ColorChat(0, "%d c4 detected", count)


PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define fm_find_ent_by_class(%1,%2) engfunc( EngFunc_FindEntityByString, %1, "classname", %2 )

new iC4ID

public plugin_init()
{
    
RegisterHam(Ham_Spawn"player""fwdPlayerSpawn");
}

public 
fwdPlayerSpawn()
{
    
iC4ID fm_find_ent_by_class(-1"weapon_c4");
    
    
server_print("C4 Index: %d"iC4ID);


This got it for me.. ent id 47 every time i would spawn with the bomb

ConnorMcLeod 08-11-2011 04:07

Re: 2 c4 at roundstart
 
Only 1 of the 2 c4 should have a player as owner (if pev_owner doesn't work, try m_pPlayer offset).

@Doc-Holiday
Player spawn is called many times, and it's too early to detect c4 ( c4 is given the same frame but after spawn, so, index you get is old c4, by chance new c4 had same index but it is not sure.

Code:

void CHalfLifeMultiplay::RestartRound()
{
    // [ .. ]

    @@ // HLTV Event ( New Round )
    MESSAGE_BEGIN( MSG_SPEC, gmsgHLTV );
        WRITE_BYTE( 0 );                // 0 = all players
        WRITE_BYTE( 100 | 128 );        // 100 health + msg flag
    MESSAGE_END();

    MESSAGE_BEGIN( MSG_SPEC, gmsgHLTV );
        WRITE_BYTE( 0 );                // all players
        WRITE_BYTE( 0 );                // to default FOV value
    MESSAGE_END();

    // [ .. ]
    for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CBasePlayer *pPlayer = CBasePlayer::Instance( i );
       
        if ( pPlayer && !FNullEnt( pPlayer->edict() ) )
        {
            pPlayer->m_iNumSpawns  = 0;
            pPlayer->m_bTeamChanged = false;
       
            if ( !unknowCall168() )
            {
                pPlayer->SyncRoundTimer();
            }
           
            switch ( m_iTeam )
            {
                case TEAM_CT :
                {
                    if ( !playerOffset222 )
                    {
                        pPlayer->AddAccount( m_iAccountCT, 1 );
                    }
                }
                case TEAM_TERRORIST :
                {
                    m_iNumEscapers++;
                   
                    if ( !playerOffset222 )
                    {
                        pPlayer->AddAccount( m_iAccountTerrorist, 1 );
                    }
                   
                    if ( m_bMapHasEscapeZone )
                    {
                        pPlayer->m_bNotKilled = false;
                    }
                }
            }
           
            if ( m_iTeam != TEAM_UNASSIGNED && m_iTeam != TEAM_SPECTATOR )
            {
                if ( m_bHasC4 )
                {
@@                    pPlayer->DropPlayerItem( "weapon_c4" );
                }
               
@@              pPlayer->RoundRespawn(); // spawns
            }
        }
    }
   
    CleanUpMap();
   
    if ( m_bMapHasBombTarget )
    {
@@        GiveC4(); // after spawns
    }


katna 08-11-2011 04:56

Re: 2 c4 at roundstart
 
i will check owner, i'm not very familiar with offset. but what does the mp_freezetime has to do with it?

Doc-Holiday 08-11-2011 05:19

Re: 2 c4 at roundstart
 
PHP Code:

#define m_pPlayer 41
new id get_pdata_cbase(iC4Entm_pPlayer4

something like that Connor?

ConnorMcLeod 08-11-2011 06:06

Re: 2 c4 at roundstart
 
Quote:

Originally Posted by katna (Post 1530138)
but what does the mp_freezetime has to do with it?

I have no idea, may be then roundstart happen the same frame as newround, and maybe c4 is still there but has flag FL_KILLME, you can also check that.

If( pev(iC4, pev_flags) & FL_KILLME ) should do the trick as well.


All times are GMT -4. The time now is 03:25.

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