AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Resolved] pfn_touch will not work for me? Help plz! (https://forums.alliedmods.net/showthread.php?t=47912)

hlstriker 11-29-2006 21:04

[Resolved] pfn_touch will not work for me? Help plz!
 
I am trying to make a function run when a player touches a spawned entity. Each time I touch the entity the function doesn't run though. Can someone please help me with my code and tell me why?

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <engine> #define PLUGIN "Speedeh" #define VERSION "1.0" #define AUTHOR "hlstriker" const MAX_NAME_LENGTH = 31; new startModel[] = "models/v_tfc_rpg.mdl"; new endModel[] = "models/esad_8ball.mdl"; new bool:startCreated; new bool:endCreated; new Float:hour; new Float:minute; new Float:second; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     register_concmd("amx_addstart", "setStart", ADMIN_BAN, " - adds a start point for the timer");     register_concmd("amx_addend", "setEnd", ADMIN_BAN, " - adds an end point for the timer"); } public plugin_precache() {     precache_model(startModel);     precache_model(endModel); } public setStart(id) {     if(startCreated) {         return PLUGIN_HANDLED;     }         // Get players origin for where to set starter     new Float:origin[3];     entity_get_vector(id, EV_VEC_origin, origin);         // Create the entity     new startEnt = create_entity("info_target");         // Set the class name for a touch     entity_set_string(startEnt, EV_SZ_classname, "startTimer");         // Set the model     entity_set_model(startEnt, startModel);         // Set new entities origin     entity_set_origin(startEnt, origin);         // Set Movetype Solidtype + Owner     entity_set_int(startEnt, EV_INT_solid, SOLID_NOT);     entity_set_int(startEnt, EV_INT_movetype, MOVETYPE_FLY);     entity_set_edict(startEnt, EV_ENT_owner, 33);         // Set Model's play sequence (Framerate 1.0 means normal speed + sequence 0 is the idle sequence)     entity_set_float(startEnt, EV_FL_framerate, 1.0);     entity_set_int(startEnt, EV_INT_sequence, 0);         //Set size of invisible box that is interactive w/ players (depending on solid type)     new Float:minStart[3];     minStart[0]=-10.0;     minStart[1]=-10.0;     minStart[2]=-10.0;     new Float:maxStart[3];     maxStart[0]=10.0;     maxStart[1]=10.0;     maxStart[2]=10.0;     entity_set_size(startEnt,minStart,maxStart);         startCreated = true;         return PLUGIN_CONTINUE; } public setEnd(id) {     if(endCreated) {         return PLUGIN_HANDLED;     }         // Get players origin for where to set starter     new Float:origin[3];     entity_get_vector(id, EV_VEC_origin, origin);         // Create the entity     new endEnt = create_entity("info_target");         // Set the class name for a touch     entity_set_string(endEnt, EV_SZ_classname, "endTimer");         // Set the model     entity_set_model(endEnt, endModel);         // Set new entities origin     entity_set_origin(endEnt, origin);         // Set Movetype Solidtype + Owner     entity_set_int(endEnt, EV_INT_solid, SOLID_NOT);     entity_set_int(endEnt, EV_INT_movetype, MOVETYPE_FLY);     entity_set_edict(endEnt, EV_ENT_owner, 33);         // Set Model's play sequence (Framerate 1.0 means normal speed + sequence 0 is the idle sequence)     entity_set_float(endEnt, EV_FL_framerate, 1.0);     entity_set_int(endEnt, EV_INT_sequence, 0);         //Set size of invisible box that is interactive w/ players (depending on solid type)     new Float:minEnd[3];     minEnd[0]=-10.0;     minEnd[1]=-10.0;     minEnd[2]=-10.0;     new Float:maxEnd[3];     maxEnd[0]=10.0;     maxEnd[1]=10.0;     maxEnd[2]=10.0;     entity_set_size(endEnt,minEnd,maxEnd);         endCreated = true;         return PLUGIN_CONTINUE; } public pfn_touch(ptr, ptd) {     new toucher[MAX_NAME_LENGTH];     new touched[MAX_NAME_LENGTH];     entity_get_string(ptr, EV_SZ_classname, toucher, MAX_NAME_LENGTH-1);     entity_get_string(ptd, EV_SZ_classname, touched, MAX_NAME_LENGTH-1);     if(equal(toucher,"startTimer") && equal(touched,"player"))     {         hour = 0.0;         minute = 0.0;         second = 1.0;         set_task(1.0, "timerCount", ptd, "", 0, "b");     }         return PLUGIN_CONTINUE; } public timerCount(ptd) {     second += 1.0         if(second == 60.0) {         second = 0.0         minute += 1.0     }         if(minute == 60.0) {         minute = 0.0         hour += 1.0     }         new strHour[3];     new strMinute[3];     new strSecond[3];         float_to_str(hour, strHour, 2);     float_to_str(minute, strMinute, 2);     float_to_str(second, strSecond, 2);         switch(hour) {         case 0.0: strHour = "00";         case 1.0: strHour = "01";         case 2.0: strHour = "02";         case 3.0: strHour = "03";         case 4.0: strHour = "04";         case 5.0: strHour = "05";         case 6.0: strHour = "06";         case 7.0: strHour = "07";         case 8.0: strHour = "08";         case 9.0: strHour = "09";     }         switch(minute) {         case 0.0: strMinute = "00";         case 1.0: strMinute = "01";         case 2.0: strMinute = "02";         case 3.0: strMinute = "03";         case 4.0: strMinute = "04";         case 5.0: strMinute = "05";         case 6.0: strMinute = "06";         case 7.0: strMinute = "07";         case 8.0: strMinute = "08";         case 9.0: strMinute = "09";     }         switch(second) {         case 0.0: strSecond = "00";         case 1.0: strSecond = "01";         case 2.0: strSecond = "02";         case 3.0: strSecond = "03";         case 4.0: strSecond = "04";         case 5.0: strSecond = "05";         case 6.0: strSecond = "06";         case 7.0: strSecond = "07";         case 8.0: strSecond = "08";         case 9.0: strSecond = "09";     }         set_hudmessage(200, 100, 0, -1.0, -5.0, 0, 0.0, 0.9, 0.0, 0.0, 4);     show_hudmessage(ptd, "%s:%s:%s", strHour, strMinute, strSecond);         return PLUGIN_CONTINUE; }

The Specialist 11-29-2006 22:40

Re: pfn_touch will not work for me? Help plz!
 
try using register touch instead of pfn_touch
Code:
  // plugin_init() register_touch("My_Ent","player","function_to_be_called")   public function_to_be_called() {          whatever }
:up:

hlstriker 11-29-2006 23:05

Re: pfn_touch will not work for me? Help plz!
 
Thanks, got it working :)

jim_yang 11-30-2006 00:11

Re: [Resolved] pfn_touch will not work for me? Help plz!
 
you can use this
format(strHour,2,"%02d",floatround(hour))
instead of switch stuff


All times are GMT -4. The time now is 07:01.

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