• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Need Fix!

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi! The_Witcher made this code for me, since i know nothing about JASS.

In my map, NPC sells "Talk", when "Talk" is sold, the dialog starts. The thing is that after the coversation ends, the Player can't "Talk" again to the same NPC.

Somewhere in this vJASS code there's a function to disable the "Talk" selling or something like that, I need someone to check it and tell me how to disable the "Disabling" of "Talk" after having "Talked" xD

JASS:
library DialogSystem initializer onInit


    //function AddLineToDialog takes string text, unit fromUnit, player toPlayer returns nothing

    //function StartPlayerDialog takes player toPlayer returns nothing
    
    

    globals
        private string array texts[12][50]
        private unit array partner[12][50]
        private integer array count
        private integer array pointer
        private boolean array talking
        private multiboard array DialogBoard
    endglobals

    function AddLineToDialog takes string text, unit fromUnit, player toPlayer returns nothing
        local integer id = GetPlayerId(toPlayer)
        set texts[id][count[id]] = text
        set partner[id][count[id]] = fromUnit
        set count[id] = count[id] + 1
    endfunction

    function StartPlayerDialog takes player toPlayer returns nothing
        local multiboarditem mbitem
        local integer id = GetPlayerId(toPlayer)
        local integer i = 0
        set pointer[id] = 0
        set talking[id] = true
        loop
            exitwhen i >= count[id]
            call PauseUnit(partner[id][i], true)
            set i = i + 1
        endloop
        set mbitem = MultiboardGetItem(DialogBoard[id], 0, 0)
        call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][0]) + "|r:")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 1, 0)
        call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][1]) + "|r:")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 1, 1)
        call MultiboardSetItemValue(mbitem, "")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 0, 1)
        call MultiboardSetItemValue(mbitem, texts[id][0])
        call MultiboardReleaseItem(mbitem)
        call AddIndicator(partner[id][0], 255, 255, 255, 255)
    
        if GetLocalPlayer() == toPlayer then
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 1500, 1.0)
            call MultiboardMinimize( DialogBoard[id], false)
            call ClearSelection()
        endif
    endfunction

    private function EscPress takes nothing returns boolean
        local integer id = GetPlayerId(GetTriggerPlayer())
        local multiboarditem mbitem
        local integer i = 0
        if talking[id] then
            set pointer[id] = pointer[id] + 1
            if pointer[id] < count[id] then
                set mbitem = MultiboardGetItem(DialogBoard[id], 0, 0)
                call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][pointer[id] - 1]) + "|r:")
                call MultiboardReleaseItem(mbitem)
                set mbitem = MultiboardGetItem(DialogBoard[id], 1, 0)
                call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][pointer[id]]) + "|r:")
                call MultiboardReleaseItem(mbitem)
                set mbitem = MultiboardGetItem(DialogBoard[id], 0, 1)
                call MultiboardSetItemValue(mbitem, texts[id][pointer[id] - 1])
                call MultiboardReleaseItem(mbitem)
                set mbitem = MultiboardGetItem(DialogBoard[id], 1, 1)
                call MultiboardSetItemValue(mbitem, texts[id][pointer[id]])
                call MultiboardReleaseItem(mbitem)
                call AddIndicator(partner[id][pointer[id]], 255, 255, 255, 255)
            else
                loop
                    exitwhen i >= count[id]
                    call PauseUnit(partner[id][i], false)
                    set i = i + 1
                endloop
                set talking[id] = false
                set count[id] = 0
                if GetLocalPlayer() == GetTriggerPlayer() then
                    call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 2250, 1.0)
                    call MultiboardMinimize( DialogBoard[id], true)
                endif
            endif
        endif
        return false
    endfunction

    private function Start takes nothing returns nothing
        local integer i = 0
        local trigger t = CreateTrigger()
        local multiboarditem mbitem
        call DestroyTimer(GetExpiredTimer())
        loop
            exitwhen i >= 12
            set count[i] = 0
            set talking[i] = false
            call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_END_CINEMATIC)
            set DialogBoard[i] = CreateMultiboard()            
            call MultiboardSetRowCount(DialogBoard[i], 2)
            call MultiboardSetColumnCount(DialogBoard[i], 2)
            call MultiboardSetTitleText(DialogBoard[i], "Game Dialogs")

            set mbitem = MultiboardGetItem(DialogBoard[i], 0, 0)
            call MultiboardSetItemWidth(mbitem, 0.06)
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 1, 0)
            call MultiboardSetItemWidth(mbitem, 0.06)
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 0, 1)
            call MultiboardSetItemWidth(mbitem, 0.64)
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 1, 1)
            call MultiboardSetItemWidth(mbitem, 0.64)
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 0, 0)
            call MultiboardSetItemIcon(mbitem, "ReplaceableTextures\\CommandButtons\\BTN_CMD_Talk.blp")
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 1, 0)
            call MultiboardSetItemIcon(mbitem, "ReplaceableTextures\\CommandButtons\\BTN_CMD_Talk.blp")
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 0, 1)
            call MultiboardSetItemStyle(mbitem, true, false)
            call MultiboardReleaseItem(mbitem)
            set mbitem = MultiboardGetItem(DialogBoard[i], 1, 1)
            call MultiboardSetItemStyle(mbitem, true, false)
            call MultiboardReleaseItem(mbitem)            
            
            if GetLocalPlayer() == Player(i) then
                call MultiboardDisplay(DialogBoard[i], true)
            endif
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Condition(function EscPress))
    endfunction
    
    private function onInit takes nothing returns nothing
        call TimerStart(CreateTimer(),0.01,false,function Start)
    endfunction

endlibrary

One of the triggers that use it

  • Roger 1 Dialog System
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Selling unit) Equal to Roger 0000 <gen>
      • (Item-type of (Sold Item)) Equal to Talk
      • ((Buying unit) is A Hero) Equal to True
    • Actions
      • Unit - Make (Selling unit) face (Buying unit) over 0.00 seconds
      • Unit - Make (Buying unit) face (Selling unit) over 0.00 seconds
      • Custom script: call AddLineToDialog( "Hi! |cffffd700Roger|r! How's it going?", GetBuyingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Hi! Gsu'h told me to explain you some stuff.", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "As you already know, you have to press [Esc] to continue with the conversation...", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "During this time, though you are paused, you are vulnerable to damage", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Also, forget about just killing everything. This game involves more than that.", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Be aware of the night, wich is dark enough to need some light source, like a torch...", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Notice that most units don't show the Green Health Bar, and Items aren't that obvious to detect", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "As an example, those torchs over there can be picked. Try doing it after we finish talking", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "You should also check your |cffffd700Main Skills|r, you can now find in your command panel.", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "These will be neccesary for quests, fights, and finding secrets", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Now go explore. Good luck! Hope you the best of |cffffd700Elomvah|r blessings ;)", GetSellingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call AddLineToDialog( "Okay thanks!", GetBuyingUnit(), GetOwningPlayer(GetBuyingUnit()))
      • Custom script: call StartPlayerDialog(GetOwningPlayer(GetBuyingUnit()))
      • Unit - Add Main skills to (Buying unit)
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
Done (Edited the first post).
I think that the problem is that both units gets paused when talking, after finishing, the hero becomes unpaused, but the NPC remains paused...

I think that's it =)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Hmm, it seems the code was created for human players (the end of the dialog is performed when the player press the escape key).

So, i suppose the owner of selling unit is a neutral or computer player ?
You could try to use force ui cancel (player action) with this player.
If it doesn't work then we will have to edit the library, let us know.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
The NPC are Neutral Passive (So far, all the NPC models are Villagers), and the players heroes are Human too.

When I buy "Talk" from any NPC, the dialog starts, the cam gets zoomed in, both units are paused - (Here's one problem. NPC units souldn't get paused, since more than 1 hero can speak with the same NPC at the same time) - and whenever I press Esc the Next Dialog Line appears. After the dialog ends, the Camera zooms out and (Here's the another problem) the hero gets unpaused, but the NPC remains paused (I guess it's like that, because the NPC inventory dissapears)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Ok there is a quick dirty fix which should work :

JASS:
function StartPlayerDialog takes player toPlayer returns nothing
        local multiboarditem mbitem
        local integer id = GetPlayerId(toPlayer)
        local integer i = 0
        set pointer[id] = 0
        set talking[id] = true
        loop
            exitwhen i >= count[id]
            if GetPlayerController(toPlayer) == MAP_CONTROL_USER then
               call PauseUnit(partner[id][i], true)
            endif
            set i = i + 1
        endloop
        set mbitem = MultiboardGetItem(DialogBoard[id], 0, 0)
        call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][0]) + "|r:")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 1, 0)
        call MultiboardSetItemValue(mbitem, "|cffffd700" + GetUnitName(partner[id][1]) + "|r:")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 1, 1)
        call MultiboardSetItemValue(mbitem, "")
        call MultiboardReleaseItem(mbitem)
        set mbitem = MultiboardGetItem(DialogBoard[id], 0, 1)
        call MultiboardSetItemValue(mbitem, texts[id][0])
        call MultiboardReleaseItem(mbitem)
        call AddIndicator(partner[id][0], 255, 255, 255, 255)
    
        if GetLocalPlayer() == toPlayer then
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 1500, 1.0)
            call MultiboardMinimize( DialogBoard[id], false)
            call ClearSelection()
        endif
    endfunction

Now units will be paused only if the owner is an human player, but not if it's a neutral or computer one (note that it will pause even if the human player slot is empty but i can add a line to handle that)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Mmmm... The NPC remains paused after talking =/

Here's the map so you can test it for yourself.
 

Attachments

  • Gsu'h Will V003.w3x
    847.5 KB · Views: 56
Level 20
Joined
Jul 14, 2011
Messages
3,213
Ok :) I guess I'll just wait... I have a lot of stuff to do in the same map :p I'll PM you if i get an answer. Thanks!
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I've downloaded your map, and make sure that any unit is not paused (with the dialog system, i simply "deleted" the pauseunit line), but even with a new wisp of a different player, like player blue, i can't buy a new guy.
So are you sure there is not something wrong with your tests ? (like you pause the unit somewhere else, have only one unit stock, and so one)

If your tests are correct plz provide a map where i can immediatly test.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
1 Test: I made a copy of one of the units, and bought as many talks as I wanted, just because he hadn't any trigger to call the StartDialog function, but obviously, there was no dialog :p

2 Test: The units inventory dissapears after talking, that's why I think they become paused, or something.

3 Test: Changed the type of the units to "Unit" since it was "Building" and the same happens.

The amount of talks and Units/Heroes to buy are infinite.
 
Status
Not open for further replies.
Top