function IsStringInteger takes string s returns boolean local string charset = "0123456789" local string char local string cschar local integer i = 0 local integer i2 = 0 local boolean b
loop exitwhen i > StringLength(s) set char = SubString(s,i,i + 1) set b = false set i2 = 0 loop exitwhen i2 > StringLength(charset) set cschar = SubString(s,i2,i2 + 1) set b = b or char == cschar set i2 = i2 + 1 endloop if b == false then return b endif set i = i + 1 endloop return true endfunction
function Trig_water_Actions takes nothing returns nothing local string s = GetEventPlayerChatString() local player p = GetTriggerPlayer() local string r local string g local string b local integer ri local integer gi local integer bi local string c local integer i = 7
loop set c = SubString(s,i,i + 1) exitwhen c == " " set r = r + c set i = i + 1 endloop
loop set c = SubString(s,i,i + 1) exitwhen c == " " set g = g + c set i = i + 1 endloop
loop set c = SubString(s,i,i + 1) exitwhen c == " " set b = b + c set i = i + 1 endloop
if IsStringInteger(r) and IsStringInteger(g) and IsStringInteger(b) then set ri = R2I(S2R(r) * 2.55) set gi = R2I(S2R(g) * 2.55) set bi = R2I(S2R(b) * 2.55) if ri > 255 then set ri = 255 endif if gi > 255 then set gi = 255 endif if bi > 255 then set bi = 255 endif if GetLocalPlayer() != p then set r = " " set g = " " set b = " " endif if r != " " and g != " " and b != " " then call SetWaterBaseColor(ri,gi,bi,255) endif else call DisplayTextToPlayer(p,0.,0.,"Неверен формат ввода команды.") endif
set p = null endfunction
//=========================================================================== function InitTrig_water takes nothing returns nothing local integer i = 0 set gg_trg_water = CreateTrigger() loop exitwhen i > 11 call TriggerRegisterPlayerChatEvent(gg_trg_water,Player(i),"-water",false) set i = i + 1 endloop call TriggerAddCondition(gg_trg_water,Condition(function Trig_water_Conditions)) call TriggerAddAction(gg_trg_water,function Trig_water_Actions) endfunction
1) gg_trg_water создаётся изначально, чтобы ты ЭТО юзал, а не лишний хендл создавал. 2) Играющих игроков 12, а не 16... 3) Всегда делай "проверку на дураков", как у меня IsStingInteger, иначе есть немалые шансы "полететь".