AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] Touch Stuff (https://forums.alliedmods.net/showthread.php?t=52679)

SAMURAI16 03-17-2007 08:52

[TUT] Touch Stuff
 
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



Hawk552 03-17-2007 12:02

Re: [TUT] Touch Stuff
 
I don't think I've ever seen anything as general as this, but for a list, it's nice.

flyeni6 03-17-2007 12:07

Re: [TUT] Touch Stuff
 
so this is basically if 2 players touch?

SAMURAI16 03-17-2007 12:08

Re: [TUT] Touch Stuff
 
2 players touch, one player and one entity or 2 entityes

flyeni6 03-17-2007 12:11

Re: [TUT] Touch Stuff
 
oohhh lol im such a newb.

good tutorial

VEN 03-17-2007 12:48

Re: [TUT] Touch Stuff
 
Quote:

register_touch("touched","toucher","hook_touch");
You should mention that for 1st and 2nd parameter an actual classname should be specified.

Peoples Army 03-19-2007 20:52

Re: [TUT] Touch Stuff
 
Quote:

Originally Posted by flyeni6 (Post 453513)
so this is basically if 2 players touch?

this is for entity's touching . which players are a class of entitys .

schnitzelmaker 03-20-2007 10:43

Re: [TUT] Touch Stuff
 
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");

SAMURAI16 03-20-2007 11:07

Re: [TUT] Touch Stuff
 
thx for the note
- updated the tut*

mateo10 03-20-2007 11:11

Re: [TUT] Touch Stuff
 
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");     }   }


All times are GMT -4. The time now is 11:09.

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