Warcraft III resources & community, 2003–2006 · archived

GetNextChatMsg

not rated
Submitted by Cubasis40Text Parsing0 downloads
Waits and returns the next chat message written by player. Is useful for asking the player something (dialog?) and/or debug. Pass it 0 to have no timeout. Pass it "" if you wanna catch just any msg instead of one including a substring.

EDITED: Added Timeout feature, and store Msg now on the triggers handle.

Source

function H2I takes handle h returns integer
   return h
   return 0
endfunction

function GetNextChatMsg_Child takes nothing returns nothing
   if( GetTriggerExecCount(GetTriggeringTrigger()) == 1 ) then
      call StoreString( InitGameCache("chatevent.w3v"), I2S(H2I(GetTriggeringTrigger())), "string", GetEventPlayerChatString() )
   endif
endfunction

function GetNextChatMsg takes player WhichPlayer, real TimeOut, string SubS returns string
   local gamecache GC = InitGameCache("chatevent.w3v")
   local trigger trig = CreateTrigger()
   local string s = I2S(H2I(trig))
   local string Msg = ""
   local timer t

   if (SubString

   if (TimeOut > 0)then
      set t = CreateTimer()
      call TimerStart(t, TimeOut, false, null)
   endif

   call TriggerRegisterPlayerChatEvent( trig, WhichPlayer, SubS, false )
   call TriggerAddAction( trig, function GetNextChatMsg_Child )

   loop
      call TriggerSleepAction(0)
      if (GetTriggerExecCount(trig) > 0) then
         set Msg = GetStoredString( GC, s, "string" )
      endif
      exitwhen Msg != "" or ( TimeOut>0 and TimerGetRemaining(t)==0 )
   endloop

   call DestroyTrigger(trig)
   set trig = null
   if ( Msg == "" ) then
      call DestroyTimer(t)
      set t = null
      return ""
   endif

   set Msg = GetStoredString( GC, s, "string" )
   call FlushStoredMission( GC, s )
   return Msg
endfunction

Comments

0

No comments.