AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking where "+use" is used. (https://forums.alliedmods.net/showthread.php?t=144476)

t3hNox 12-04-2010 13:04

Checking where "+use" is used.
 
Hi. Sorry I don't have any code because I don't know where to start. Basically what I would like to do is to check if +use is not used for pushing buttons, defusing bomb, taking hostages, starting a car or other similar things and then execute my code. Otherwise if it is used for anything mentioned before then simply allow it to work and do not execute my code. It would be enough if someone could just show any plugin that has such functionality.
Thank you.

fysiks 12-04-2010 18:08

Re: Checking where "+use" is used.
 
Are you saying it's possible to do those things you mentioned without using +use? If yes, it must be some sort of trigger entity in the map and you should be able to hook when a player touches the trigger (I think).

Drak 12-04-2010 22:20

Re: Checking where "+use" is used.
 
You want your code to be executed, when the "+use" key doesn't activate ANYTHING?
What fysiks said, you can hook "Ham_Use" or a similar name, check if the hooked function was called. Another (much easier) method is to; before you check when they pushed the use key. Do a trace line (get_user_aiming) and see if there looking at a "usable" entity.

Here's the second method:
Code:

public client_PreThink(id)
{
        if(!is_user_alive(id))
                return
       
        if(!(entity_get_int(id,EV_INT_button) & IN_USE && !(entity_get_int(id,EV_INT_oldbuttons) & IN_USE)))
                return
       
        new Index,Body
        get_user_aiming(id,Index,Body,200); // not sure how far HL checks when doing the use key
       
        // Filter out any entity's
        // I filter out other players, and "trigger_*" entity's as you cannot "+use" them
        if(is_valid_ent(Index))
        {
                static Classname[33]
                entity_get_string(Index,EV_SZ_classname,Classname,32)
               
                if(!equali(Classname,"player") || !(containi(Classname,"trigger_") != -1))
                        return
        }
       
        // Your code
}


t3hNox 12-05-2010 04:51

Re: Checking where "+use" is used.
 
Quote:

Originally Posted by Drak (Post 1363403)
You want your code to be executed, when the "+use" key doesn't activate ANYTHING?

Yes, exactly. Sorry that my first post was not very clear.
I was also thinking about Ham_Use but I have no idea about "..check if the hooked function was called.." part. Should I check if it returs anything when it is called by a player and if not then execute my code ?
As far as I know PreThink would consume more resources than the method with Ham_Use so I'd like to give it a try.

Drak 12-05-2010 08:28

Re: Checking where "+use" is used.
 
Quote:

Originally Posted by t3hNox (Post 1363540)
Yes, exactly. Sorry that my first post was not very clear.
I was also thinking about Ham_Use but I have no idea about "..check if the hooked function was called.." part. Should I check if it returs anything when it is called by a player and if not then execute my code ?
As far as I know PreThink would consume more resources than the method with Ham_Use so I'd like to give it a try.

The resource usage is minimal. Your best bet would be "PreThink" because you have to register "Ham_Use" on every entity you wish to be checked. While prethink, you can check if there facing any entity, and filter out the ones there allowed to see (players, etc)

t3hNox 12-06-2010 09:06

Re: Checking where "+use" is used.
 
Ok. Thank you, Drak. I'll use prethink :)

Exolent[jNr] 12-06-2010 17:28

Re: Checking where "+use" is used.
 
Best method is to hook Ham_ObjectCaps.

t3hNox 12-10-2010 17:50

Re: Checking where "+use" is used.
 
Thanks Exolent[jNr] for pointing out Ham_ObjectCaps.
Now I'm using it instead of prethink and everything works great.


All times are GMT -4. The time now is 10:24.

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