AlliedModders

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

Awesome_man 04-14-2016 06:49

Stock Help
 
What's wrong with the code below :-

I registered a command /destroy to destroy dispenser but it's not working whats wrong ?

PHP Code:

public destroy(iOwner)  
{
    new 
iEnt FM_NULLENT;  
    new 
iOwner peviEntpev_iuser2 ); 
        
      
bDispenserBuildiOwner ] = false;
           
set_peviEntpev_flagspeviEntpev_flags ) | FL_KILLME );  
    }
           
        
        
    }  
/*         
    ~~~~~~~~~~~~~~~~~~~~~~~
        Here is the stock 
    ~~~~~~~~~~~~~~~~~~~~~~~
*/


stock UTIL_DestroyDispensers( )
{
    new 
iEnt FM_NULLENT;
    
    while( ( 
iEnt find_ent_by_classiEntgDispenserClassname ) ) )
    {
        new 
iOwner peviEntpev_iuser2 );
        
        
bDispenserBuildiOwner ] = false;
        
set_peviEntpev_flagspeviEntpev_flags ) | FL_KILLME );
    }


someone please help.. thanks.

simanovich 04-14-2016 09:06

Re: Stock Help
 
Why to set KILLME flag if you can just remove the ent?

SpannerSpammer 04-14-2016 18:48

Re: Stock Help
 
Here you go, you needed to compare the owner IDs.
Code:

stock public destroy( iOwner )
{
    new iEnt = FM_NULLENT;
    while( ( iEnt = find_ent_by_class( iEnt, gDispenserClassname ) ) )
    {
        if ( pev_valid( iEnt ))
        {
            new index = pev( iEnt, pev_iuser2 );
            if (  index == iOwner )
            {
                bDispenserBuild[ iOwner ] = false;
                set_pev( iEnt, pev_flags, pev( iEnt, pev_flags ) | FL_KILLME );
                break;
            }
        }
    }
}

_________________________________________


Quote:

Originally Posted by simanovich
Why to set KILLME flag if you can just remove the ent?

Both methods are valid, remove_entity() is just faster.


All times are GMT -4. The time now is 18:40.

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