Raised This Month: $ Target: $400
 0% 

Entity Use (Like a button)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-22-2015 , 19:03   Re: Entity Use (Like a button)
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta_util>

const MAXPLAYERS 32;

new const 
szClassname[] = "my_button";
new const 
szButtonModel[] = "/models/w_c4.mdl";

new 
ButtonEntity;

#define IsPlayer(%1)    (1<=%1<=MAXPLAYERS)

public plugin_precache()
{
    
precache_modelszButtonModel );
}

public 
plugin_init() 
{
    
RegisterHamHam_Use "func_button" "HamUse_Button" );
    
    
register_clcmd"say button""Cmd_Button" );
}

public 
Cmd_Buttonid )
{
    
CreateButtonid );
}

public 
HamUse_ButtoniEntity iPlayer iActivator iUseType Float:fValue )
{
    new 
szName32 ];
    
    if ( ( 
iEntity == ButtonEntity ) && ( iUseType == ) && ( fValue == 1.0 ) && IsPlayeriPlayer ) )
    {
        
get_user_nameiPlayer szName charsmaxszName ) );
        
client_printprint_chat "%s used the button" szName );
    }
}

public 
CreateButtonid )
{
    
ButtonEntity engfuncEngFunc_CreateNamedEntity engfuncEngFunc_AllocString "func_button" ) );
    
set_pevButtonEntity pev_classname szClassname );
    
set_pevButtonEntity pev_solid SOLID_BBOX );
    
set_pevButtonEntity pev_movetype MOVETYPE_NONE );
    
engfuncEngFunc_SetModel ButtonEntity szButtonModel );

    new 
Float:fOrigin];
    
fm_get_aim_originid fOrigin );
    
fOrigin] += 20.0;
    
engfuncEngFunc_SetOrigin ButtonEntity fOrigin );

__________________

Last edited by Bugsy; 10-22-2015 at 19:07.
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 10-23-2015 , 13:24   Re: Entity Use (Like a button)
Reply With Quote #2

Thanks bugsy...

Can someone give me a link for a tutorial about fakemeta/hamsandwich that include entities... like this topic for example?
https://forums.alliedmods.net/showthread.php?t=43321
This has been useful for beginning... I need more advanced, I just can't find one :/

Last edited by redivcram; 10-24-2015 at 17:19.
redivcram is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-23-2015 , 15:26   Re: Entity Use (Like a button)
Reply With Quote #3

engfunc( EngFunc_AllocString , "func_button" ) should be cached, given that the value won't change and that allocating a string is an expensive operation.
__________________

Last edited by HamletEagle; 10-23-2015 at 15:28.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-23-2015 , 18:59   Re: Entity Use (Like a button)
Reply With Quote #4

That brings up a good point. My above code is for demonstration of creating 1 entity.

If you will be spawning more than 1 then:
  • You will need to track multiple entity ID's. You could use an array for this.
  • You should cache the EngFunc_AllocString value.
  • The Ham_Use function would need some modification to handle multiple button entities.
  • You should destroy entities that are no longer used.
__________________

Last edited by Bugsy; 10-23-2015 at 19:10.
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 22:18.


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