AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   FM_Touch ? (https://forums.alliedmods.net/showthread.php?t=56636)

bwgrubbs1 06-17-2007 09:01

FM_Touch ?
 
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");     } }

Alka 06-17-2007 09:08

Re: FM_Touch ?
 
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)
 }
}

:D
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")
 }


bwgrubbs1 06-17-2007 09:55

Re: FM_Touch ?
 
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 06-17-2007 11:29

Re: FM_Touch ?
 
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.

_Master_ 06-17-2007 13:43

Re: FM_Touch ?
 
question: 2hp/s when triggered by "healer" (one touch is sufficient) or only when touching "healer" (must by touching healer to regenerate) ?

Alka 06-17-2007 14:12

Re: FM_Touch ?
 
Here ! :D
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*

bwgrubbs1 06-18-2007 15:03

Re: FM_Touch ?
 
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 06-19-2007 02:03

Re: FM_Touch ?
 
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 ?

Deviance 06-19-2007 02:13

Re: FM_Touch ?
 
Quote:

Originally Posted by bwgrubbs1 (Post 491797)
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 (Post 491797)
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()

bwgrubbs1 06-19-2007 02:32

Re: FM_Touch ?
 
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.


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

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