|
发表于 2006-5-21 11:20:31
|
显示全部楼层
来自 中国–湖北–武汉
[原创] set_task() 函数用法
Post by http://forum.dt-club.net/images/dt/editor/color.gif
[url
http://forum.dt-club.net/images/dt/editor/color.gif大馒头]我知道set_task给函数传递参数的时候需要用数组,可是有时候,因为函数已经定义好了,而且函数参数不是数组,怎么办?[/url]
[color="Blue"]set_task ( Float:time,const function[],id = 0,parameter[]="",len = 0,flags[]="", repeat = 0 ) [color="Red"]用法:
例子1、[PHP]public client_putinserver(id)
{
set_task(0.5, "cl_1", id + 3333)
set_task(0.8, "cl_2", id + 3333)
return PLUGIN_CONTINUE
}
public cl_1(id)
{
server_print(" [TEST] - cl_1 : id = %d", id)
}
public cl_2(a)
{
server_print(" [TEST] - cl_2 : a = %d", a)
}
[/PHP]
结果:
[TEST] - cl_1 : id = 3334
[TEST] - cl_2 : a = 3334
你会发现,cl_1中的id与cl_2中的a总是相等,且都等于client_putinserver中的 id + 3333转递过去的 。到这里,本例子是否符合你的要求?
例子2、[PHP]public client_putinserver(id)
{
new param[3]
param[0] = 10 + id
param[1] = 100 + 2*id
param[2] = 1000 + 3*id
set_task(1.0, "func_A", id + 3333, param, 3)
return PLUGIN_CONTINUE
}
public cl_3(x, y, z)
{
server_print(" [TEST] - cl_3 : x+y+y = %d ; x = %d, y = %d , z = %d", x+y+z, x, y, z)
}
public func_A(para[])
{
cl_3(para[0], para[1],para[2])
}
[/PHP]
结果:
[TEST] - cl_3 : x+y+y = 1116 ; x = 11, y = 102 , z = 1003
例子3、[[color="Red"]错误用法]
[PHP]public client_putinserver(id)
{
new param[4]
param[0] = 10 + id
param[1] = 100 + 2*id
param[2] = 1000 + 3*id
param[3] = 2000 + 4*id
set_task(1.2, "cl_6", id + 3333, param, 4)
return PLUGIN_CONTINUE
}
public cl_6(x, y, z , k)
{
server_print(" [TEST] - cl_6 : x+y+y+k = %d ; x = %d, y = %d , z = %d , k = %d", x+y+z, x, y, z, k)
}[/PHP]
运行结果:
[TEST] - cl_6 : x+y+y+k = 4654 ; x = 1320, y = 3334 , z = 0 , k = 0
x是怎么得出来的,我还没有清楚,跟后面的参数个数有关。 |
|