Raised This Month: $51 Target: $400
 12% 

Problem with pev_iuser1 not saving variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
headshot910
Member
Join Date: Apr 2012
Old 03-16-2020 , 14:10   Problem with pev_iuser1 not saving variable
Reply With Quote #1

PHP Code:
public fw_SetModel(entitymodel[])
{
    if(!
is_valid_ent(entity))
        return 
FMRES_IGNORED;
    static 
szClassName[33]
    
entity_get_string(entityEV_SZ_classnameszClassNamecharsmax(szClassName))
    if(!
equal(szClassName"weaponbox"))
        return 
FMRES_IGNORED;
    static 
iOwner
    iOwner 
entity_get_edict(entityEV_ENT_owner)
    if(
equal(model"models/w_aug.mdl"))
    {
        static 
iStoredSVDID
        iStoredSVDID 
find_ent_by_owner(-1wententity)
        if(!
is_valid_ent(iStoredSVDID))
            return 
FMRES_IGNORED;
        if(
g_has_balrog5[iOwner])
        {
            
entity_set_int(iStoredSVDIDEV_INT_impulseWEAPONKEY)
            
g_has_balrog5[iOwner] = false        
            
            
//It should save here
            
set_pev(entitypev_iuser1skin[iOwner])
            
            
entity_set_model(entityskin[iOwner]?balrog5_W_MODELB:balrog5_W_MODEL)    
            
            
client_print(iOwner,print_chat,"You dropped %s Balrog-V",pev(entitypev_iuser1)?"BLUE":"RED")
            return 
FMRES_SUPERCEDE;
        }
    }
    return 
FMRES_IGNORED;
}
public 
fw_balrog5_AddToPlayer(balrog5id)
{
    if(!
is_valid_ent(balrog5) || !is_user_connected(id))
        return 
HAM_IGNORED;
    if(
entity_get_int(balrog5EV_INT_impulse) == WEAPONKEY)
    {
        
g_has_balrog5[id] = true
        entity_set_int
(balrog5EV_INT_impulse0)
        
        
//But NO, it's not loading :(
        
skin[id] = pev(balrog5pev_iuser1)
        
client_print(id,print_chat,"You picked up %s Balrog-V",pev(balrog5pev_iuser1)?"BLUE":"RED")
        return 
HAM_HANDLED;
    }
    return 
HAM_IGNORED;

Hi i'm trying to save variable "skin" of player to dropped entity but when i picked up, it's seem like nothing different and the skin variable back to player'id default value.
I already search on forum and try on Touch but it's seem like nothing work for me.
Please help!
__________________
Hi!
I'm here!

Last edited by headshot910; 03-16-2020 at 14:14.
headshot910 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-16-2020 , 16:28   Re: Problem with pev_iuser1 not saving variable
Reply With Quote #2

I didn't read your code, but your problem may be because you don't know how weaponbox entities work. A "weaponbox" entity is exactly what the name says: a box that contains a weapon entity.
In fw_SetModel you set iuser1 on the box itself.
In fw_balrog5_AddToPlayer you try to retrieve iuser1 from the weapon that was in the box.
The box and the weapon are 2 different entities.

You should instead set your flag on the weapon from the box. Touch should also work, as long as you hook touch with the weaponbox and not the weapon.
__________________
HamletEagle is offline
headshot910
Member
Join Date: Apr 2012
Old 03-17-2020 , 00:04   Re: Problem with pev_iuser1 not saving variable
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
I didn't read your code, but your problem may be because you don't know how weaponbox entities work. A "weaponbox" entity is exactly what the name says: a box that contains a weapon entity.
In fw_SetModel you set iuser1 on the box itself.
In fw_balrog5_AddToPlayer you try to retrieve iuser1 from the weapon that was in the box.
The box and the weapon are 2 different entities.

You should instead set your flag on the weapon from the box. Touch should also work, as long as you hook touch with the weaponbox and not the weapon.
Can you demonstrate some code base on mine? Thank you
__________________
Hi!
I'm here!
headshot910 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-18-2020 , 19:44   Re: Problem with pev_iuser1 not saving variable
Reply With Quote #4

You would need to add more checking in AddPlayerItem but this is the basic idea that HamletEagle was suggesting.

PHP Code:

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

const XO_CWEAPONBOX 4;

new const 
m_rgpPlayerItems_CWeaponBox] = { 34 35, ... };
 
public 
plugin_init()
{
    
register_forwardFM_SetModel "SetModel" );
    
RegisterHamHam_AddPlayerItem "player" "AddPlayerItem" );
}
    
public 
SetModeliEntity , const szModel[] )
{
    static 
szClass32 ] , iWeaponEntity iRandom iPlayer;
    
peviEntity pev_classname szClass charsmaxszClass ) );
    
    if ( 
equalszClass "weaponbox" ) )
    {
        for ( new 
sizeofm_rgpPlayerItems_CWeaponBox ) ; i++ )
        {
            if ( ( 
iWeaponEntity get_pdata_cbaseiEntity m_rgpPlayerItems_CWeaponBox] , XO_CWEAPONBOX ) ) > )
            {
                
iRandom random1000 );
                
set_peviWeaponEntity pev_iuser1 iRandom );
                
                
iPlayer peviEntity pev_owner );
                
client_printiPlayer print_chat "Dropped weapon with pev_iuser1 = %d" iRandom );
                break;
            }
        }
    }
}

public 
AddPlayerItemiPlayer iEntity )
{
    new 
pev_iuser1_value peviEntity pev_iuser1 );
    
    if ( 
pev_iuser1_value )
    {
        
client_printiPlayer print_chat "Picked up weapon with pev_iuser1 = %d" pev_iuser1_value );
    }

__________________

Last edited by Bugsy; 03-18-2020 at 19:58.
Bugsy 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 02:05.


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