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

[TUT] Touch Stuff


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SAMURAI16
BANNED
Join Date: Sep 2006
Old 03-17-2007 , 08:52   [TUT] Touch Stuff
Reply With Quote #1

Today we will discuss about touch stuff.
We will talk about:
1. Touch with natives
2.
Forwards touch
3.
Block touch operation
4.
Fake touch

So, let's start


1. Touch with natives
Engine way:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>


public plugin_init() {
    
register_plugin("Touch Test","0.1","SAMURAI");
    
    
// now registers a touch action to a function. 
    
register_touch("touched","toucher","hook_touch"); 
}


public 
hook_touch(touched,toucher)
{
    if(
is_user_admin(toucher) && is_user_bot(touched))    
    {
        
client_print(0,print_chat,"kbooom")
    }
    


touched = Who are touched by Toucher

toucher = Who touch

If you want to filter touched / toucher
An example :
Only running hook_touch if a player touch something..
PHP Code:
register_touch("player","*","hook_touch"); 


2. Forwards touch:
Engine way:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>


public plugin_init() {
    
register_plugin("Touch test","0.1","SAMURAI");
    
    
}

// Called when two entities touch/collide. 
public pfn_touch(ptr,ptd)
{
    new 
classname[32]
    
entity_get_string(ptr,EV_SZ_classname,classname,31

    
    if ( 
equal(classname"hostage_entity") ) 
    {
        
client_print(0,print_chat,"damn touched");
        
// and other stuff
    
}




Fakemeta way:
PHP Code:
#include <amxmodx>
#include <fakemeta>

public plugin_init() {
    
register_plugin("Touch Test","0.1","SAMURAI");
    
    
register_forward(FM_Touch,"hook_touch");
}

public 
hook_touch(ptr,ptd)
{
    new 
classname[32]
    
pev(ptr,pev_classname,classname,31)
    
    
    if ( 
equal(classname"hostage_entity") ) 
    {
        
client_print(0,print_chat,"damn touched");
        
// and other stuff
    
}
    



3.
Block touch operation:

On Engine:
To block touch use return PLUGIN_HANDLED;

On Fakemeta:
use return FMRES_SUPERCEDE;

4. Fake Touch:
This will
simulates two entities colliding/touching.
Engine:
PHP Code:
fake_touch(Touched,Toucher
Fakemeta:
PHP Code:
dllfunc(DLLFunc_Touchtouchedtoucher


Last edited by SAMURAI16; 03-20-2007 at 11:14.
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-17-2007 , 12:02   Re: [TUT] Touch Stuff
Reply With Quote #2

I don't think I've ever seen anything as general as this, but for a list, it's nice.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
flyeni6
Senior Member
Join Date: Jun 2006
Location: CAli
Old 03-17-2007 , 12:07   Re: [TUT] Touch Stuff
Reply With Quote #3

so this is basically if 2 players touch?
flyeni6 is offline
Send a message via AIM to flyeni6
SAMURAI16
BANNED
Join Date: Sep 2006
Old 03-17-2007 , 12:08   Re: [TUT] Touch Stuff
Reply With Quote #4

2 players touch, one player and one entity or 2 entityes
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
flyeni6
Senior Member
Join Date: Jun 2006
Location: CAli
Old 03-17-2007 , 12:11   Re: [TUT] Touch Stuff
Reply With Quote #5

oohhh lol im such a newb.

good tutorial
flyeni6 is offline
Send a message via AIM to flyeni6
VEN
Veteran Member
Join Date: Jan 2005
Old 03-17-2007 , 12:48   Re: [TUT] Touch Stuff
Reply With Quote #6

Quote:
register_touch("touched","toucher","hook_touch");
You should mention that for 1st and 2nd parameter an actual classname should be specified.
VEN is offline
Peoples Army
SourceMod Donor
Join Date: Mar 2007
Old 03-19-2007 , 20:52   Re: [TUT] Touch Stuff
Reply With Quote #7

Quote:
Originally Posted by flyeni6 View Post
so this is basically if 2 players touch?
this is for entity's touching . which players are a class of entitys .
Peoples Army is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 03-20-2007 , 10:43   Re: [TUT] Touch Stuff
Reply With Quote #8

A little thing to add to the tutorial,that you can filter toucher/touched in register_touch.

Example:Only running hook_touch if a player touch something
Code:
register_touch("player","*","hook_touch");
__________________
schnitzelmaker is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 03-20-2007 , 11:07   Re: [TUT] Touch Stuff
Reply With Quote #9

thx for the note
- updated the tut*
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
mateo10
Veteran Member
Join Date: Jan 2006
Old 03-20-2007 , 11:11   Re: [TUT] Touch Stuff
Reply With Quote #10

One question,
why doesn't this work?
Code:
#include <amxmodx> #include <fun> #include <engine> public plugin_init() {     register_plugin("Nadepassing", "1.00", "MaTTe");     register_touch("player", "hegrenade", "hegrenade_touch"); } public hegrenade_touch(touched, toucher) {     new model[99]     entity_get_string(toucher, EV_SZ_model, model, 99);     new owner = entity_get_edict(toucher, EV_ENT_owner);         new touchedname[32], ownername[32];     get_user_name(touched, touchedname, 31);     get_user_name(owner, ownername, 31);         if(equal(model, "w_hegrenade.mdl")) {         client_print(0, print_chat, "%s passed the grenade to %s", ownername, touchedname);         remove_entity(toucher);         give_item(touched, "weapon_hegrenade");     }    }

Last edited by mateo10; 03-20-2007 at 11:48.
mateo10 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 01:44.


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