Raised This Month: $32 Target: $400
 8% 

Solved entity problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 04-06-2021 , 19:43   entity problem
Reply With Quote #1

hello guys, i hope you are ok in this pandemic shit.

i have this code,
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < engine >
#include < fakemeta >
#include < fakemeta_util >
#include < fun >
#include < hamsandwich >

#define PLUGIN "BonusBox"
#define VERSION "1.0"
#define AUTHOR "SkepT Jr."

new const iTag[] = "^4[^3CSGO^4]^1"
new const ClassName [ ] = "BonusBox"
new models_box [] = {    
    
"models/bonus_box/easter_egg.mdl"
};

const 
UNIT_SEC 0x1000;
const 
FFADE 0x0000;

#define FFADE_IN        0x0000        
#define FFADE_OUT        0x0001        
#define FFADE_MODULATE        0x0002        
#define FFADE_STAYOUT        0x0004    
#define SPEEDBOX         600.0    

native set_user_scraps(idvalue)
    
native set_user_money(idvalue)
    
native set_user_keys(idvalue)
    
native set_user_cases(idvalue)
    
native get_user_scraps(id)
    
native get_user_money(id)
    
native get_user_keys(id)
    
native get_user_cases(id)
    
native is_user_logged(id)
    

public 
plugin_init ( ) {
    
    
register_plugin PLUGINVERSIONAUTHOR );
    
register_event "DeathMsg""eDeath""a" );
    
register_forward FM_PlayerPreThink"ForcePlayerSpeed" );
    
register_forward FM_Touch"Touch" );
    
RegisterHam Ham_Spawn"player""Ham_Spawn_Post"true );
    
    
    
// Add your code here...
}

public 
plugin_precache() {
    for(new 
isizeof (models_box) ; i++)
        
precache_model(models_box)
}

public 
eDeath ( ) {
    
    new 
iKiller read_data (1);
    new 
iVictim read_data (2);
    new 
iRandom random_num(010)
    
    if ( 
iKiller == iVictim ) {
        
        return 
PLUGIN_HANDLED;
        
    }
    
    if(
iRandom 5)
    {
        
bonus_box iVictim );
    }
    
    return 
PLUGIN_HANDLED;
}



public 
bonus_box id ) {
    
    if ( 
is_user_connected id ) && cs_get_user_team id ) != CS_TEAM_SPECTATOR ) {
        
        new 
Ent fm_create_entity "info_target" );
        new 
Origin ];
        
get_user_origin idOrigin);
        
set_pev Entpev_classnameClassName )
        
        
engfunc EngFunc_SetModelEntmodels_box [0] );
        
        
set_pev Entpev_minsFloat: { -10.0,-10.0,0.0 } );
        
set_pev Entpev_maxsFloat: { 10.0,10.0,25.0 } );
        
set_pev Entpev_sizeFloat: { -10.0,-10.0,0.0,10.0,10.0,25.0 } ); 
        
engfunc EngFunc_SetSizeEntFloat: { -10.0, -10.00.0 }, Float: { 10.010.025.0 } );
        
        
set_pev Ent,pev_solidSOLID_BBOX );
        
set_pev Ent,pev_movetypeMOVETYPE_TOSS );
        
        new 
FloatfOrigin ];
        
IVecFVec OriginfOrigin );
        
set_pev Entpev_originfOrigin );
        
    }
    
}

public 
Touch touchertouched ) {
    
    if ( !
is_user_alive toucher ) || !pev_valid touched ) )
        return 
FMRES_IGNORED;
    
    new 
classname 32 ];    
    
pev touchedpev_classnameclassname31 );
    
    if (!
equal classnameClassName ) )
        return 
FMRES_IGNORED;
    
    if(
is_user_logged(toucher) == 1)
    {
        
give_bonus toucher );
    }
    else
        
client_print_color(toucherprint_team_default"%s You must be logged in to get this from bonus box!"iTag)
    
    
set_pev touchedpev_effectsEF_NODRAW );
    
set_pev touchedpev_solidSOLID_NOT );
    
remove_entity touched );
    
    return 
FMRES_IGNORED;
    
}

public 
give_bonus id ) {
    
    new 
iRandom random_num(0,3)
    new 
iRandomBonusiMoney[MAX_PLAYERS 1], iCases[MAX_PLAYERS 1], iKeys[MAX_PLAYERS 1], iScraps[MAX_PLAYERS 1]
    
    switch(
iRandom)
    {
        case 
0:
        {
            
iMoney[id] = get_user_money(id)
            
            
iRandomBonus random_num(-5,5)
            
            if (
iRandomBonus 0)
            {
                if(
iMoney[id] - iRandomBonus 0)
                {
                    
client_print_color(idprint_team_default"%s You haven't lost anything because you don't have enough."iTag)
                    
                    return 
PLUGIN_HANDLED
                
}
                else
                {
                    
client_print_color(idprint_team_default"%s You lost^4 %i^1 dolars."iTagiRandomBonus)
                    
                }
            }
            
            else if (
iRandomBonus 0)
            {
                
client_print_color(idprint_team_default"%s You win^4 %i^1 dolars!"iTagiRandomBonus)
                
            }
            
            else if (
iRandomBonus == 0)
            {
                
client_print_color(idprint_team_default"%s You didn't get anything!"iTagiRandomBonus)
            }
            
            
set_user_money(idiRandomBonus)
        }
        
        case 
1:    
        {
            
iCases[id] = get_user_cases(id)
            
            
iRandomBonus random_num(-2,2)
            
            if (
iRandomBonus 0)
            {
                if(
iCases[id] - iRandomBonus 0)
                {
                    
client_print_color(idprint_team_default"%s You haven't lost anything because you don't have enough."iTag)
                    
                    return 
PLUGIN_HANDLED
                
}
                else
                {
                    
client_print_color(idprint_team_default"%s You lost^4 %i^1 case%s."iTagiRandomBonusiRandomBonus == "" "s")
                }
            }
            
            else if (
iRandomBonus 0)
            {
                
client_print_color(idprint_team_default"%s You win^4 %i^1 case%s!"iTagiRandomBonusiRandomBonus == "" "s")
            }
            
            else if (
iRandomBonus == 0)
            {
                
client_print_color(idprint_team_default"%s You didn't get anything!"iTagiRandomBonus)
            }
            
            
set_user_cases(idiRandomBonus)    
        }
        
        case 
2:
        {            
            
iKeys[id] = get_user_keys(id)
            
            
iRandomBonus random_num(-2,2)
            
            if (
iRandomBonus 0)
            {
                if(
iKeys[id] - iRandomBonus 0)
                {
                    
client_print_color(idprint_team_default"%s You haven't lost anything because you don't have enough."iTag)
                    
                    return 
PLUGIN_HANDLED
                
}
                else
                {
                    
client_print_color(idprint_team_default"%s You lost^4 %i^1 key%s."iTagiRandomBonusiRandomBonus == "" "s")
                }
            }
            
            else if (
iRandomBonus 0)
            {
                
client_print_color(idprint_team_default"%s You win^4 %i^1 key%s!"iTagiRandomBonusiRandomBonus == "" "s")
            }
            
            else if (
iRandomBonus == 0)
            {
                
client_print_color(idprint_team_default"%s You didn't get anything!"iTagiRandomBonus)
            }
            
            
set_user_money(idiRandomBonus)
            
        }
        
        case 
3:
        {            
            
iScraps[id] = get_user_scraps(id)
            
            
iRandomBonus random_num(-6,6)
            
            if (
iRandomBonus 0)
            {
                if(
iKeys[id] - iRandomBonus 0)
                {
                    
client_print_color(idprint_team_default"%s You haven't lost anything because you don't have enough."iTag)
                    
                    return 
PLUGIN_HANDLED
                
}
                else
                {
                    
client_print_color(idprint_team_default"%s You lost^4 %i^1 key%s."iTagiRandomBonusiRandomBonus == "" "s")
                }
            }
            
            else if (
iRandomBonus 0)
            {
                
client_print_color(idprint_team_default"%s You win^4 %i^1 key%s!"iTagiRandomBonusiRandomBonus == "" "s")
            }
            
            else if (
iRandomBonus == 0)
            {
                
client_print_color(idprint_team_default"%s You didn't get anything!"iTagiRandomBonus)
            }
            
            
set_user_money(idiRandomBonus)
            
        }
    }
    
    return 
PLUGIN_CONTINUE

but i don t know why sometimes i get 2,3 or all bonuses

Last edited by lexzor; 04-11-2021 at 10:42.
lexzor is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-07-2021 , 14:25   Re: entity problem
Reply With Quote #2

touch forward could be triggering multiple times before the entity is removed.

Code:
public Touch ( toucher, touched ) {         if ( !is_user_alive( toucher ) || !pev_valid( touched ) )         return FMRES_IGNORED;         new classname [ 32 ];        pev( touched, pev_classname, classname, 31 );         if (!equal( classname, ClassName ) )         return FMRES_IGNORED;     set_pev ( touched, pev_effects, EF_NODRAW );     set_pev ( touched, pev_solid, SOLID_NOT );     if (!remove_entity( touched ))         return FMRES_IGNORED;     if(is_user_logged(toucher) == 1)     {         give_bonus( toucher );     }     else         client_print_color(toucher, print_team_default, "%s You must be logged in to get this from bonus box!", iTag)                 return FMRES_IGNORED;     }

Last edited by jimaway; 04-07-2021 at 14:27.
jimaway is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 04-08-2021 , 20:51   Re: entity problem
Reply With Quote #3

what library is better to use for entity scripting ?

Are there some good tutorials about them ?
lexzor is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-08-2021 , 22:47   Re: entity problem
Reply With Quote #4

You can find just about anything by searching. While there are tutorials for a lot, there is not one for how to solve every specific issue. Sometimes you need to try stuff on your own.

If jimaway's solution doesn't work, try this:
PHP Code:
public Touch touchertouched 
{    
    if ( !
is_user_alive toucher ) || !pev_valid touched ) )
        return 
FMRES_IGNORED;
    
    static 
classname 32 ];    
    
pevtouchedpev_classnameclassnamecharsmaxclassname ) );
    
    if ( !
equal classnameClassName ) )
        return 
FMRES_IGNORED;
    
    if ( !( 
pevtouched pev_iuser2 ) & ( << ( toucher 31 ) ) ) )
    {
        if ( 
is_user_loggedtoucher ) == )
        {
            
give_bonus toucher );
        }
        else
        {
            
client_print_color(toucherprint_team_default"%s You must be logged in to get this from bonus box!"iTag)
        }
        
        
set_pevtouched pev_iuser2 pevtouched pev_iuser2 ) | ( << ( toucher 31 ) ) );
        
set_pev touchedpev_effectsEF_NODRAW );
        
set_pev touchedpev_solidSOLID_NOT );
        
remove_entity touched );
    }
    
    return 
FMRES_IGNORED;    

__________________
Bugsy is online now
lexzor
Veteran Member
Join Date: Nov 2020
Old 04-10-2021 , 15:43   Re: entity problem
Reply With Quote #5

Thanks you all!

Last edited by lexzor; 04-11-2021 at 10:41.
lexzor is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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