Raised This Month: $32 Target: $400
 8% 

Checking where "+use" is used.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
t3hNox
Senior Member
Join Date: Oct 2009
Old 12-04-2010 , 13:04   Checking where "+use" is used.
Reply With Quote #1

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.
t3hNox is offline
Old 12-04-2010, 15:04
Seta00
This message has been deleted by Seta00. Reason: o nvm
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-04-2010 , 18:08   Re: Checking where "+use" is used.
Reply With Quote #2

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).
__________________
fysiks is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 12-04-2010 , 22:20   Re: Checking where "+use" is used.
Reply With Quote #3

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
}
__________________
Oh yeah

Last edited by Drak; 12-04-2010 at 22:26.
Drak is offline
Send a message via MSN to Drak
t3hNox
Senior Member
Join Date: Oct 2009
Old 12-05-2010 , 04:51   Re: Checking where "+use" is used.
Reply With Quote #4

Quote:
Originally Posted by Drak View Post
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.
t3hNox is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 12-05-2010 , 08:28   Re: Checking where "+use" is used.
Reply With Quote #5

Quote:
Originally Posted by t3hNox View Post
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)
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
t3hNox
Senior Member
Join Date: Oct 2009
Old 12-06-2010 , 09:06   Re: Checking where "+use" is used.
Reply With Quote #6

Ok. Thank you, Drak. I'll use prethink
t3hNox is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-06-2010 , 17:28   Re: Checking where "+use" is used.
Reply With Quote #7

Best method is to hook Ham_ObjectCaps.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 12-10-2010 , 17:50   Re: Checking where "+use" is used.
Reply With Quote #8

Thanks Exolent[jNr] for pointing out Ham_ObjectCaps.
Now I'm using it instead of prethink and everything works great.
t3hNox is offline
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 02:20.


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