Yes, that method will work, and is called Recursion (when a functon calls itself).
Here is a simpler example:
Code:
#include <amxmodx>
// variable to keep track of each players loop times
new g_iLoops[33] = 0
public plugin_init()
{
register_clcmd( "do_slap_loop", "SlapLoop" )
}
public SlapLoop( id )
{
g_iLoops[id] = 10
new victimID[2]
victimID[0] = id
set_task( 1.0, "MyLoopFunc", 0, victimID, 1 )
return PLUGIN_HANDLED
}
public MyLoopFunc( aCmdArgs[] )
{
new victimID = aCmdArgs[0]
// do stuff here...
user_slap( victimID, 5 ) // Slap victim with 5 hp
// Minus 1 from loops
--g_iLoops[victimID]
// Call self again in 1 second..
if( g_iLoops[victimID] > 0 )
set_task( 1.0, "MyLoopFunc", 0, aCmdArgs, 2 )
return
}