AlliedModders

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

yagami 10-23-2022 21:05

remove_entity
 
I have a dispenser here, I just added a cvar[CVAR_VIP_LVL1_PRICE] so now the vip are able to place two dispensers but now I don't know how to remove these dispensers
because when I try to destroy, both are removed together I wanted only one at a time

How do I remove one at a time?

PHP Code:

public xBuyDispenser(id)
{
    if(!
is_user_alive(id) && is_user_connected(id))
        return 
PLUGIN_CONTINUE

    
if(!(pev(idpev_flags) & FL_ONGROUND))
    {
        
client_print_color(idprint_team_default"%s ^3Tente ficar em um chão ^1PLANO ^3para poder comprar um ^4Dispenser^3."PREFIX_CHAT)
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
    
}
    
    
    if(
g_IsVip[id])
    {
      if(
g_DispPlayerCount[id] >= get_pcvar_num(g_Cvar[CVAR_LIMIT_PER_PLAYER_VIP]))
        {
        
client_print_color(idprint_team_default"%s ^3You have already reached the limit of ^4Dispenser ^3."PREFIX_CHAT)
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
        
}
    } 
    else
    {
        if(
g_DispPlayerCount[id] >= get_pcvar_num(g_Cvar[CVAR_LIMIT_PER_PLAYER]))
        {
        
client_print_color(idprint_team_default"%s ^3You have already reached the limit of ^4Dispenser ^3."PREFIX_CHAT)
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
        
}
    } 

    

    
/*if((xLimitGlobal[0] >= get_pcvar_num(g_Cvar[CVAR_LIMIT_GLOBAL]) && get_user_team(id) == 1) || (xLimitGlobal[1] >= get_pcvar_num(g_Cvar[CVAR_LIMIT_GLOBAL]) && get_user_team(id) == 2))
    {
        client_print_color(id, print_team_default, "%s ^3Your team has reached the limit of ^4Dispenser^3.", PREFIX_CHAT)
        client_cmd(id, "spk %s", g_DispSndFail)

        return PLUGIN_HANDLED
    }*/


    
    
static iMoneyiMoney cs_get_user_money(id)
    static 
iPriceDispiPriceDisp get_pcvar_num(g_Cvar[CVAR_LVL1_PRICE])

    if(
iMoney iPriceDisp)
    {
        
client_print_color(idprint_team_default"%s ^3You don't have enough money! ^4$: %s^3."PREFIX_CHATxAddPoint(iPriceDisp))
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
    
}

    if(
g_PlayerMovingDisp[id])
    {
        
client_print_color(idprint_team_default"%s ^3You already have a ^4Dispenser ^3activated, put it on to buy more."PREFIX_CHAT)
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
    
}
    else
    {
        if(
get_pcvar_num(g_Cvar[CVAR_INSTANT_PLANT]))
        {
            static 
Float:fOrigin[3]
            
get_origin_from_dist_player(id100.0fOrigin)

            if(
xCreateDispanser(fOriginid))
            {
                
client_print_color(idprint_team_default"%s ^4Dispenser ^3planted!"PREFIX_CHAT)
                
cs_set_user_money(idiMoney iPriceDisp)
            }
            else
            {
                
client_cmd(id"spk %s"g_DispSndFail)
            }
        }
        else
        {
            
CreateDispMoveEffect(id)
            
cs_set_user_money(idiMoney iPriceDisp)
        }
    }

    return 
PLUGIN_HANDLED
}

public 
xDestroyDispenser(id)
{
    if(!
g_DispPlayerCount[id])
    {
        
client_print_color(idprint_team_default"%s ^3You don't have any ^4Dispenser ^3to be destroyed."PREFIX_CHAT)
        
client_cmd(id"spk %s"g_DispSndFail)

        return 
PLUGIN_HANDLED
    
}

    static 
entent FM_NULLENT

    
while((ent find_ent_by_class(entdispenser_classname)))
    {
        if(
pev(entDISPENSER_OWNER) != id
            continue

        if(
pev_valid(ent)) 
        {
            static 
iLevelxGiveMoney
            iLevel 
pev(entDISPENSER_LEVEL)

            
xGiveMoney 0

            
switch(iLevel)
            {
                case 
1: { xGiveMoney = (get_pcvar_num(g_Cvar[CVAR_LVL1_PRICE])) / 2; }
                case 
2: { xGiveMoney = (get_pcvar_num(g_Cvar[CVAR_LVL2_PRICE])) / 2; }
                case 
3: { xGiveMoney = (get_pcvar_num(g_Cvar[CVAR_LVL3_PRICE])) / 2; }
                case 
4: { xGiveMoney = (get_pcvar_num(g_Cvar[CVAR_LVL4_PRICE])) / 2; }
            }

            
g_DispPlayerCount[id] --
            
//xLimitTeamAtt(id)

            
cs_set_user_money(idcs_get_user_money(id) + xGiveMoney)
            
client_print_color(idprint_team_default"%s ^3You got it: ^4$: %s ^3of money for destroying your ^4Dispenser ^3Lvl: ^4%d^3."PREFIX_CHAT,
            
xAddPoint(xGiveMoney), iLevel)
            
xRemoveEntFix(ent)
        }
    }

    return 
PLUGIN_HANDLED
}

/*
public xLimitTeamAtt(id)
{
    static xMyTeam; xMyTeam = get_user_team(id)

    if(xMyTeam == 1)
        xLimitGlobal[0] --
    else
        xLimitGlobal[1] --
}*/


public xRemoveEntFix(ent)
{
    
set_pev(entpev_flagspev(entpev_flags) | FL_KILLME)
    
set_pev(entpev_nextthinkget_gametime() + 0.5)
    
}

public 
BreakAllPlayerDispensers(id)
{
    static 
entent FM_NULLENT

    
while((ent find_ent_by_class(entdispenser_classname)))
    {
        if(
pev(entDISPENSER_OWNER) != id)
            continue
        
        if(
pev_valid(ent))
        {
            
//xLimitTeamAtt(id)
            
xRemoveEntFix(ent)
            
g_DispPlayerCount[id] --
        }
    }



jimaway 10-24-2022 10:12

Re: remove_entity
 
break the while loop in public xDestroyDispenser(id) after xRemoveEntFix(ent) line

if you want the dispencers to be removed in a specific order you will have to store the ent id-s in a global array

yagami 10-24-2022 11:22

Re: remove_entity
 
Quote:

Originally Posted by jimaway (Post 2791525)
break the while loop in public xDestroyDispenser(id) after xRemoveEntFix(ent) line

if you want the dispencers to be removed in a specific order you will have to store the ent id-s in a global array

My biggest problem is not knowing where to start or how to begin

jimaway 10-24-2022 15:27

Re: remove_entity
 
start by just breaking the while loop like i told you see if that works for your needs

yagami 10-24-2022 16:02

Re: remove_entity
 
Quote:

Originally Posted by jimaway (Post 2791535)
start by just breaking the while loop like i told you see if that works for your needs

I just solved it here thank you very much


All times are GMT -4. The time now is 15:33.

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