diff --git a/data/npc/web_commands.txt b/data/npc/web_commands.txt index 990b0d3fc..9493394ce 100644 --- a/data/npc/web_commands.txt +++ b/data/npc/web_commands.txt @@ -8,24 +8,26 @@ //= commands every 2 seconds. //===== Additional Comments: ================================= //= 1.0 First Version. +//= 1.1 Fixed code to prevent single-run senarios. //============================================================ - script Commands -1,{ OnInit: start: -initnpctimer; -end; + initnpctimer; + end; + OnTimer2000: -set $@nb2,query_sql("SELECT COUNT(*) FROM cp_commands WHERE done=0",$@count); -if($@count != 0) { - set $@nb,query_sql("SELECT command,id,account_id FROM cp_commands WHERE done=0",$@command$,$@id,$@account_id); - if(compare($@command$,"@")) { - attachrid($@account_id[0]); - atcommand $@command$[0]; - } else charcommand $@command$[0]; - query_sql("UPDATE cp_commands SET done='1' WHERE command='"+$@command$[0]+"' AND id='"+$@id[0]+"'"); -} else -finish: -stopnpctimer; -goto start; -} \ No newline at end of file + .@nb2 = query_sql("SELECT COUNT(*) FROM cp_commands WHERE done=0",.@count); + if(.@count != 0) { + .@nb = query_sql("SELECT command,id,account_id FROM cp_commands WHERE done=0 ORDER BY id LIMIT 1",.@command$,.@id,.@account_id); + if(compare(.@command$,"@")) { + attachrid(.@account_id[0]); + atcommand .@command$[0]; + } else charcommand .@command$[0]; + query_sql("UPDATE cp_commands SET done='1' WHERE command='"+.@command$[0]+"' AND id='"+.@id[0]+"'"); + .@nb = 0; .@nb2 = 0; .@count = 0; .@command$ = 0; .@id = 0; .@account_id = 0; + } + stopnpctimer; + goto start; +}