Raised This Month: $ Target: $400
 0% 

FM_Touch ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-17-2007 , 09:01   FM_Touch ?
Reply With Quote #1

How would i add something like this to my code...if you are touching an entity, then i want it to continuously call a function.

Code:
    register_forward(FM_Touch, "fwdTouch", 0);

how do i set it up in there to call this function

Code:
public give_health(id) {     new temp = get_user_health(id);     if(temp >= 99)     {         set_user_health(id, 100);     }     else     {         temp += 2;         set_user_health(id, temp);     }     return PLUGIN_HANDLED; }

from in here ?

Code:
public fwdTouch(ptr, ptd) {     //only if i am touching a certain entity.     //specifically one that I created.     else if( equal(szClassname, "healer", 0) )     {         //NOT sure...where do i put this...         //or is there a way to do this with set_pev         //set_task(1.0,"give_health",ptd,"",0,"b");     } }
bwgrubbs1 is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-17-2007 , 09:08   Re: FM_Touch ?
Reply With Quote #2

Something like this!
Code:
#include <amxmodx>
#include <fakemeta>
 
#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"
 
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR)
 register_forward(FM_Touch,"fwd_touch")
}
 
public fwd_touch(ent,id)
{
 new g_classname[32]
 pev(ent, pev_classname, g_classname, 31)
 
 /*static health
 health = pev(id,pev_health)*/
 
 if(equali(g_classname, "class_name"))
 {
  set_pev(id,pev_health,100)
 }
}

Or if you want to call a contiousy a function a set_task wher you check class!
Code:
 if(equali(g_classname, "class_name"))
 {
  set_task(1.0,"give_health",id,_,_,"b")
 }
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 06-17-2007 at 09:11.
Alka is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-17-2007 , 09:55   Re: FM_Touch ?
Reply With Quote #3

ok...clarification...how would i make it so when they touch the entity it will heal them until 100 hp by 2 hp every second, and then remove the task.
bwgrubbs1 is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-17-2007 , 11:29   Re: FM_Touch ?
Reply With Quote #4

What it does now is, when you touch the entity it auto sets your hp to 100, then if you fall or take dmg it auto heals you again...and never stops.
bwgrubbs1 is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-17-2007 , 13:43   Re: FM_Touch ?
Reply With Quote #5

question: 2hp/s when triggered by "healer" (one touch is sufficient) or only when touching "healer" (must by touching healer to regenerate) ?
_Master_ is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-17-2007 , 14:12   Re: FM_Touch ?
Reply With Quote #6

Here !
Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
 
#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"
 
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR)
 register_forward(FM_Touch,"fwd_touch")
}
 
public fwd_touch(ent,id)
{
 new g_classname[32]
 pev(ent, pev_classname, g_classname, 31)
 
 
 if(equali(g_classname, "class_name"))
 {
  if(get_user_health(id) >= 100)
   return 1;
  else
   set_task(1.5,"give_health",id,_,_,"b")
 }
 return 1;
}
 
public give_health(id)
{
 new health = get_user_health(id)
 
 if(health > 99 )
 {
  set_user_health(id,100)
  remove_task(id)
 }
 
 set_user_health(id,health + 2)
 
 return 1;
}
Don't forget to change class name of entity!
*Updated*
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 06-17-2007 at 14:44.
Alka is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-18-2007 , 15:03   Re: FM_Touch ?
Reply With Quote #7

Ok...this does the heal...but for some reason it does it like instantly if you are touching the healer constantly...and if you touch the healer then walk away it keeps giving you hp but a lot faster than 2 hp per 2 seconds...more like 2 hp every 1/2 second. I want it to where ONLY when touching the healer does it heal you @ 2 hp per second...and if you stop touching healer then...it stops healing you.

At least now it removes the task like i asked...so if you are not touching the healer and you take dmg or something then it doesnt auto-heal anymore. Thanks for that...now i've been rackin my brain to figure out the heal at 2/hp per second ONLY if touching healer.
bwgrubbs1 is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-19-2007 , 02:03   Re: FM_Touch ?
Reply With Quote #8

OK...here is what I have.

Code:
if(equali(szClassname, "healer")) {     if(get_user_health(id) >= 100)         return 1;     else         set_task(2.0,"give_health",id,_,_,"b"); }

Code:
public give_health(id) {     new hp = get_user_health(id);     if(hp >= 99)     {         client_print(id, print_chat, "Debug: Setting user hp to 100");         set_user_health(id, 100);         remove_task(id);         return 1;     }     client_print(id, print_chat, "Debug: Adding 2 hp. Current HP = %d", hp);     set_user_health(id, hp+2);     return 1; }

Works...BUT...doesn't call the function every 2 seconds.

I get this in console.


Debug: Adding 2 hp. Current HP = 81
Debug: Adding 2 hp. Current HP = 83
Debug: Adding 2 hp. Current HP = 85
Debug: Adding 2 hp. Current HP = 87
Debug: Adding 2 hp. Current HP = 89
Debug: Adding 2 hp. Current HP = 91
Debug: Adding 2 hp. Current HP = 93
Debug: Adding 2 hp. Current HP = 95
Debug: Adding 2 hp. Current HP = 97
Debug: Setting user hp to 100

REAL FAST...but it does take 2 second to start.

ALSO. If you die, and you land on the block it does this...


Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
...SPAMS THIS HARD CORE...until this

Debug: Adding 2 hp. Current HP = 1
Debug: Adding 2 hp. Current HP = 3
Debug: Adding 2 hp. Current HP = 5
Debug: Adding 2 hp. Current HP = 7
Debug: Adding 2 hp. Current HP = 9
...
Debug: Adding 2 hp. Current HP = 99
Debug: Setting user hp to 100

Help fix those two things ?
bwgrubbs1 is offline
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 06-19-2007 , 02:13   Re: FM_Touch ?
Reply With Quote #9

Quote:
Originally Posted by bwgrubbs1 View Post
Works...BUT...doesn't call the function every 2 seconds.

I get this in console.


Debug: Adding 2 hp. Current HP = 81
Debug: Adding 2 hp. Current HP = 83
Debug: Adding 2 hp. Current HP = 85
Debug: Adding 2 hp. Current HP = 87
Debug: Adding 2 hp. Current HP = 89
Debug: Adding 2 hp. Current HP = 91
Debug: Adding 2 hp. Current HP = 93
Debug: Adding 2 hp. Current HP = 95
Debug: Adding 2 hp. Current HP = 97
Debug: Setting user hp to 100

REAL FAST...but it does take 2 second to start.
change
Code:
if(equali(szClassname, "healer"))
to
Code:
if(equali(szClassname, "healer") && !task_exists(id))

Quote:
Originally Posted by bwgrubbs1 View Post
ALSO. If you die, and you land on the block it does this...


Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
Debug: Adding 2 hp. Current HP = -122
...SPAMS THIS HARD CORE...until this

Debug: Adding 2 hp. Current HP = 1
Debug: Adding 2 hp. Current HP = 3
Debug: Adding 2 hp. Current HP = 5
Debug: Adding 2 hp. Current HP = 7
Debug: Adding 2 hp. Current HP = 9
...
Debug: Adding 2 hp. Current HP = 99
Debug: Setting user hp to 100
Add
Code:
if(!is_user_alive(id)) {     remove_task(id)     return PLUGIN_CONTINUE }
to give_health()
Deviance is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 06-19-2007 , 02:32   Re: FM_Touch ?
Reply With Quote #10

WOW...thank you

it is now doing it every two seconds...but now...if you leave the healer it still gives hp...i want it to only give hp it touching the healer.
bwgrubbs1 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 10:42.


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