HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

another jass problem - WaitForPlayerEvent

07-31-2006, 07:33 PM#1
Linera
on second thought, i was wrong...

it exits after X secs but i can't get it to return the correct integer depending on if it exits my time or ESC

here is my entire script:
Hidden information:
Collapse JASS:
//Standard Functions
function MyBool takes nothing returns boolean
    return true
endfunction

function WaitForPlayerEvent_H2P takes handle h returns player
    return h
endfunction

function WaitForPlayerEvent_H2F takes handle h returns force
    return h
endfunction

function WaitForPlayerEvent_PE2I takes playerevent p returns integer
    if true then
        return p
    endif
    return 0
endfunction

function WaitForPlayerEvent_Enum takes nothing returns nothing
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, GetEnumPlayer(), ConvertPlayerEvent(bj_forceCountPlayers))
endfunction

function WaitForPlayerEvent takes handle whichForceOrPlayer, playerevent whichPlayerEvent, boolexpr condition, real interval returns nothing
    local trigger bj_temp = bj_delayedSuspendDecayTrig
    local trigger t
    local triggercondition c
    local player whichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
    local force whichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
    if whichForceOrPlayer == null or whichPlayerEvent == null then
        set whichForce = null
        return
    elseif interval < 0 then
        set interval = 0
    endif
    set t = CreateTrigger()
    set bj_delayedSuspendDecayTrig = t
    set bj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
    call ForForce(whichForce, function WaitForPlayerEvent_Enum)
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
    if condition != null then
        set c = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
    endif
    set bj_delayedSuspendDecayTrig = bj_temp
    loop
        call TriggerSleepAction(interval)
        exitwhen GetTriggerExecCount(t) != 0
    endloop
    if condition != null then
        call TriggerRemoveCondition(t, c)
        set c = null
    endif
    call DestroyTrigger(t)
    set t = null
    set whichForce = null
endfunction

function WaitForPlayerEventWait takes handle whichForceOrPlayer, playerevent whichPlayerEvent, boolexpr condition, real interval, real time returns integer
    local trigger bj_temp = bj_delayedSuspendDecayTrig
    local trigger t
    local triggercondition c
    local player whichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
    local force whichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
    local timer ti
    local integer i

    set ti = CreateTimer()
    call TimerStart(ti, time, false, null)

    if whichForceOrPlayer == null or whichPlayerEvent == null then
        set whichForce = null
        return
    elseif interval < 0 then
        set interval = 0
    endif
    set t = CreateTrigger()
    set bj_delayedSuspendDecayTrig = t
    set bj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
    call ForForce(whichForce, function WaitForPlayerEvent_Enum)
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
//  call TriggerRegisterTimerExpireEventBJ(bj_delayedSuspendDecayTrig, ti)
    if condition != null then
        set c = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
    endif
    set bj_delayedSuspendDecayTrig = bj_temp
    loop
        call TriggerSleepAction(interval)
        set i = 1
        exitwhen GetTriggerExecCount(t) != 0
        //exitwhen TimerGetRemaining(ti)==0
    endloop
    if condition != null then
        call TriggerRemoveCondition(t, c)
        set c = null
    endif
    call DestroyTrigger(t)
    set t = null
    set whichForce = null
return i
endfunction

//End of Standard Functions

function Start_Fade takes player p returns nothing
    if (GetLocalPlayer() == p) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.01, "Panda-n-Cub.blp", 100.00, 100.00, 100.00, 0 )
    endif
endfunction

function Stop_Fade takes player p returns nothing
    if (GetLocalPlayer() == p) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 0.01, "Panda-n-Cub.blp", 100.00, 100.00, 100.00, 0 )
    endif
endfunction

//=============================================
// The Parser (Takes a String, Seperates words, Returns word you wanted)
// by DKSlayer
//=============================================
function Parser takes string ChatMsg, integer Word returns string
   //Required Variables
   local string array Chkstr
   local integer Last = 0
   local integer A = 1
   local integer I = 0
   local integer Length = 1

   //Finds the Length of String
   loop
     exitwhen((SubStringBJ(ChatMsg,1,Length) == ChatMsg))
     set Length = Length + 1
   endloop

   //Pulls Words and places them each in there own Variable
   loop
     if(SubStringBJ(ChatMsg,A,A) == " ") then
       set Chkstr[i] = SubStringBJ(ChatMsg, (Last + 1), (A - 1))
       set Last = A
       set I = I + 1
     elseif(A == Length) then
       set Chkstr[i] = SubStringBJ(ChatMsg, (Last + 1), A)
     endif
     set A = A + 1
     exitwhen(A>Length)
     exitwhen((Word+1)==I)
   endloop

   //Returns wanted word
   return Chkstr[Word]

endfunction

//Set up a new quest
function SetupQuest takes string title, string description, string path returns quest
    local quest q
    
    set q = CreateQuest()
    call QuestSetTitle(q,title)
    call QuestSetCompleted(q, false)
    call QuestSetDiscovered(q, true)
    call QuestSetEnabled(q, false)
    call QuestSetRequired(q, true)
    call QuestSetDescription(q, description)
    call QuestSetIconPath(q, path)
return q
endfunction

//Sets Quest Objectives
function SetQuestObjectives takes quest q, string questrequirment returns questitem
    local questitem qi    

    set qi = QuestCreateItem(q)
    call QuestItemSetDescription(qi,questrequirment)
    call QuestItemSetCompleted(qi, false)
return qi
endfunction

function StartQuest takes player p, string t, integer wordcount returns integer
    local integer lines = 15
    local integer currentline = 1
    local integer currentword = 0
    local string temp1 = ""
    local string temp2 = ""
    local integer done = 0


// BEGIN PARSER SCRIPT //

   local string array Chkstr
   local integer Last = 0
   local integer A = 1
   local integer I = 0
   local integer Length = 1

   //Finds the Length of String
   loop
     exitwhen((SubStringBJ(t,1,Length) == t))
     set Length = Length + 1
   endloop

   //Pulls Words and places them each in there own Variable
   loop
     if(SubStringBJ(t,A,A) == " ") then
       set Chkstr[i] = SubStringBJ(t, (Last + 1), (A - 1))
       set Last = A
       set I = I + 1
     elseif(A == Length) then
       set Chkstr[i] = SubStringBJ(t, (Last + 1), A)
     endif
     set A = A + 1
     exitwhen(A>Length)
     exitwhen((wordcount)==I)
   endloop
    
// END PARSER SCRIPT //
call Start_Fade(p)

    loop
        exitwhen (currentword>wordcount)
        loop
            exitwhen (done==1)
        if (StringLength(temp1)<27) then
            set temp2 = temp1
            set temp1 = temp1 + Chkstr[currentword] + " "
            if (Chkstr[currentword] == "<br>") then
               set temp1 = temp2
               if (temp1 == "") then
                   set temp1 = " "
               endif
               set done = 1
               set currentword = currentword+1
               exitwhen (done==1)
            endif
            set currentword = currentword+1
        else
            set temp1 = temp2
            set done = 1
            set currentword = currentword-1
        endif
        endloop
    call DisplayTimedTextToForce( GetForceOfPlayer(p), 10000000000, temp1 )
    set currentline = currentline+1

    set temp1=""

    if (currentline == lines and currentword<wordcount) then
        call DisplayTimedTextToPlayer( p, 0, 0, 1000000000.00, "(|c00FF0000Press ESC to continue.|r)")
        call WaitForPlayerEvent(p, EVENT_PLAYER_END_CINEMATIC, Condition(function MyBool), 1.00)
        call ClearTextMessagesBJ( GetForceOfPlayer(p) )
        set currentline = 1
    endif

    if (currentword>=wordcount) then
        call DisplayTimedTextToPlayer( p, 0, 0, 1000000000.00, "(|c00FF0000Press ESC to Accept.|r)")
        call WaitForPlayerEventWait(p, EVENT_PLAYER_END_CINEMATIC, Condition(function MyBool), 1.00, 30.00)
        call ClearTextMessagesBJ( GetForceOfPlayer(p) )
        call Stop_Fade(p)
        return 1
    endif

    set done=0
    endloop
return 0
endfunction


Here is the script in question:
Hidden information:
Collapse JASS:
function MyBool takes nothing returns boolean
    return true
endfunction

function WaitForPlayerEvent_H2P takes handle h returns player
    return h
endfunction

function WaitForPlayerEvent_H2F takes handle h returns force
    return h
endfunction

function WaitForPlayerEvent_PE2I takes playerevent p returns integer
    if true then
        return p
    endif
    return 0
endfunction

function WaitForPlayerEvent_Enum takes nothing returns nothing
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, GetEnumPlayer(), ConvertPlayerEvent(bj_forceCountPlayers))
endfunction

function WaitForPlayerEventWait takes handle whichForceOrPlayer, playerevent whichPlayerEvent, boolexpr condition, real interval, real time returns integer
    local trigger bj_temp = bj_delayedSuspendDecayTrig
    local trigger t
    local triggercondition c
    local player whichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
    local force whichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
    local timer ti
    local integer i

    set ti = CreateTimer()
    call TimerStart(ti, time, false, null)

    if whichForceOrPlayer == null or whichPlayerEvent == null then
        set whichForce = null
        return
    elseif interval < 0 then
        set interval = 0
    endif
    set t = CreateTrigger()
    set bj_delayedSuspendDecayTrig = t
    set bj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
    call ForForce(whichForce, function WaitForPlayerEvent_Enum)
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
//  call TriggerRegisterTimerExpireEventBJ(bj_delayedSuspendDecayTrig, ti)
    if condition != null then
        set c = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
    endif
    set bj_delayedSuspendDecayTrig = bj_temp
    loop
        call TriggerSleepAction(interval)
        set i = 1
        exitwhen GetTriggerExecCount(t) != 0
        //exitwhen TimerGetRemaining(ti)==0
    endloop
    if condition != null then
        call TriggerRemoveCondition(t, c)
        set c = null
    endif
    call DestroyTrigger(t)
    set t = null
    set whichForce = null
return i
endfunction
08-02-2006, 05:52 AM#2
Linera
Still can't find a way to do this, please help.
08-04-2006, 08:06 PM#3
Linera
I guess no one wants to help me. So I give up.

My great rpg idea will go to waste as no one wants to help me.
08-04-2006, 08:16 PM#4
The)TideHunter(
I would gladly help, but i have no idea what that function is surposed to do, how to use it, when to use how, and alot of other things, we need to know the scenario before we can adjust to it.
08-04-2006, 08:19 PM#5
Linera
all its suppose to do is wait for player to press ESC, but if the player doesn't press ESC in 30 secs its suppose to exit.

if it exits from player pressing esc its to return an integer of 1
if it exits from 30 secs passing its to return an integer of 0

its for accepting or declining the quest.