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

How to get methodmap reference


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dbogdan
Junior Member
Join Date: Jan 2016
Old 12-22-2018 , 01:08   How to get methodmap reference
Reply With Quote #1

Hello,
I have this methodmap which represents a box.

PHP Code:
methodmap Box StringMap
{
    public 
Box(char[] model) {
        
int box CreateEntityByName("prop_dynamic_override"); 
        
        
char mdl[128];
        
Format(mdlsizeof mdl"models/xmas/%s.mdl"model);
        
SetEntityModel(boxmdl);
        
        
DispatchSpawn(box);
        
DispatchKeyValue(box"classname"BOX_CLASSNAME);

        
StringMap map = new StringMap();
        
map.SetValue("base"box);
        
map.SetValue("health"BOX_HEALTH);
        
        
SDKHook(boxSDKHook_OnTakeDamageBox_OnTakeDamage);
        
        return 
view_as<box>(map);        
    }
    
    
property int Health
    
{
        public 
get()
        {
            
int health;
            
this.GetValue("health"health);

            return 
health;
        }
        
        public 
set(int health)
        {
            if(
health 1)
            {
                
this.Break();
            }
            
            
this.SetValue("health"health);
        }
    }
    
    public 
void Break()
    {
        
int box this.GetValue("base");
        
        
SetVariantString("OnUser1 !self:break::0.1:1");
        
AcceptEntityInput(box"AddOutput");
        
AcceptEntityInput(box"FireUser1");
}
public 
Action Box_OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    if(!
IsValidEntity(victim)) {
        return 
Plugin_Handled;
    }

 
// Here I need the box object reference.

My problem is:
How I could obtain the box methodmap object reference in the Box_OnTakeDamage?

Last edited by dbogdan; 12-22-2018 at 05:31.
dbogdan is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 12-22-2018 , 06:37   Re: How to get methodmap reference
Reply With Quote #2

view_as<Box>(victim)
__________________
Pelipoika is offline
dbogdan
Junior Member
Join Date: Jan 2016
Old 12-22-2018 , 06:54   Re: How to get methodmap reference
Reply With Quote #3

Quote:
Originally Posted by Pelipoika View Post
view_as<Box>(victim)
What do you mean?
The box is based on StringMap not on the created entity..

Last edited by dbogdan; 12-22-2018 at 06:55.
dbogdan is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 12-22-2018 , 07:26   Re: How to get methodmap reference
Reply With Quote #4

I don't know what you want then
__________________

Last edited by Pelipoika; 12-22-2018 at 07:26.
Pelipoika is offline
dbogdan
Junior Member
Join Date: Jan 2016
Old 12-22-2018 , 07:31   Re: How to get methodmap reference
Reply With Quote #5

In the Box constructor I created an entity and then I hook OnTakeDamage on it.
So on OnTakeDamage hook I want to get the object that contains the entity.
dbogdan is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-22-2018 , 08:37   Re: How to get methodmap reference
Reply With Quote #6

This is an insane misuse of MethodMaps, but you'll need to keep an array mapping the entity index to the StringMap (Box) Handle, along with using OnEntityDestroyed to clean up. At least as you're creating networked entities you can get away with a small fixed array for it.
__________________
asherkin is offline
dbogdan
Junior Member
Join Date: Jan 2016
Old 12-22-2018 , 08:55   Re: How to get methodmap reference
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
This is an insane misuse of MethodMaps
Do you have any suggest how I could do it better?
I tried to make it look as a OOP, I thought its ok like this.

Last edited by dbogdan; 12-22-2018 at 08:56.
dbogdan 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 06:46.


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