Raised This Month: $52 Target: $400
 13% 

Objectcaps & Entity PlayerUse


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 08-30-2013 , 18:52   Objectcaps & Entity PlayerUse
Reply With Quote #1

Greetings.

Idk if anyone needs this, but I did anyway.

Basically not all ents are useable, sure you can hook use on them, but it wont register when a player hits his use key on it. You can change this however by messing a bit with the function objectcaps.

What is objectcaps?
PHP Code:
virtual int        ObjectCapsvoid ) { return FCAP_ACROSS_TRANSITION; } 
Basically objectcaps defines some basic capabilities for any given entity. The function returns a bitmask where you can use the following bits:
From the sdk:
PHP Code:
// These are caps bits to indicate what an object's capabilities (currently used for save/restore and level transitions)
#define        FCAP_CUSTOMSAVE                0x00000001
#define        FCAP_ACROSS_TRANSITION         0x00000002        // should transfer between transitions
#define        FCAP_MUST_SPAWN                0x00000004        // Spawn after restore
#define        FCAP_DONT_SAVE                 0x80000000        // Don't save this
#define        FCAP_IMPULSE_USE               0x00000008        // can be used by the player
#define        FCAP_CONTINUOUS_USE            0x00000010        // can be used by the player
#define        FCAP_ONOFF_USE                 0x00000020        // can be used by the player
#define        FCAP_DIRECTIONAL_USE           0x00000040        // Player sends +/- 1 when using (currently only tracktrains)
#define        FCAP_MASTER                    0x00000080        // Can be used to "master" other entities (like multisource) 
And thus if you flip e.g. the FCAP_IMPULSE_USE bit on your return, you will be able to register a player's use on the entity. Below is an example with info_target.

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

#define        FCAP_CUSTOMSAVE                0x00000001
#define        FCAP_ACROSS_TRANSITION        0x00000002        // should transfer between transitions
#define        FCAP_MUST_SPAWN                0x00000004        // Spawn after restore
#define        FCAP_DONT_SAVE                0x80000000        // Don't save this
#define        FCAP_IMPULSE_USE            0x00000008        // can be used by the player
#define        FCAP_CONTINUOUS_USE            0x00000010        // can be used by the player
#define        FCAP_ONOFF_USE                0x00000020        // can be used by the player
#define        FCAP_DIRECTIONAL_USE        0x00000040        // Player sends +/- 1 when using (currently only tracktrains)
#define        FCAP_MASTER                    0x00000080

public plugin_init()
{
    
RegisterHam(Ham_ObjectCaps,"info_target","OnObjectCaps")
    
RegisterHam(Ham_Use,"info_target","OnUse")
}

public 
OnObjectCaps()
{
    
SetHamReturnInteger(FCAP_IMPULSE_USE)    
    return 
HAM_OVERRIDE
}

public 
OnUse(thisidcaller)
{
    
client_print(idcaller,print_chat,"Use!")

Attached Files
File Type: sma Get Plugin or Get Source (ObjectcapsTest.sma - 500 views - 1.1 KB)

Last edited by teh ORiON; 08-30-2013 at 20:19.
teh ORiON is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-30-2013 , 20:10   Re: Objectcaps & Entity PlayerUse
Reply With Quote #2

This is a nice tip, your example is wrong though.

It is like you return this :

SetHamReturnInteger( FCAP_IMPULSE_USE )

because iCap is never set to something else, so you should first use ExecuteHam to get default return, or you should hook it as post and use HamGetOrigReturnInt or however it this native is called, and then set its return.
__________________
- tired and retired -
ConnorMcLeod is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 08-30-2013 , 20:16   Re: Objectcaps & Entity PlayerUse
Reply With Quote #3

Yeah, was using it for something else, forgot to change it. At least in the case of CPointEntity the return is 0, so doesn't matter getting the return I guess.

Last edited by teh ORiON; 08-30-2013 at 20:20.
teh ORiON is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Traphouse
Old 01-29-2018 , 06:18   Re: Objectcaps & Entity PlayerUse
Reply With Quote #4

Hey, sorry for reviving the thread!
First of all, this tutorial was useful for me, so I gotta thank you. So Ham_ObjectCaps can be used for multiple things, one of them being hooking IN_USE button? It would be nice adding more examples for the rest of the bits.

If I use
Code:
SetHamReturnInteger(FCAP_IMPULSE_USE)
will Ham_Use be triggered with a custom class-name, such as for ex: ent_newitem ?
__________________
Elite Admin System (A better admin system)
CS Battle Royale (PUBG)
Knife Bounty
Contact/Ticket System

I don't sip the lean, used to love codeine cuz I love to dream
edon1337 is offline
Send a message via Skype™ to edon1337
Reply


Thread Tools
Display Modes

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 23:34.


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