• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Trigger xD

Status
Not open for further replies.
Level 18
Joined
May 11, 2012
Messages
2,103
what is wrong in here that it won't run...

  • Give Gold or Wood
    • Events
      • Player - Player 1 (Red) types a chat message containing -give gold to as A substring
      • Player - Player 2 (Blue) types a chat message containing -give gold to as A substring
      • Player - Player 3 (Teal) types a chat message containing -give gold to as A substring
      • Player - Player 4 (Purple) types a chat message containing -give gold to as A substring
      • Player - Player 5 (Yellow) types a chat message containing -give gold to as A substring
      • Player - Player 6 (Orange) types a chat message containing -give gold to as A substring
      • Player - Player 7 (Green) types a chat message containing -give gold to as A substring
      • Player - Player 8 (Pink) types a chat message containing -give gold to as A substring
      • Player - Player 1 (Red) types a chat message containing -give wood to as A substring
      • Player - Player 2 (Blue) types a chat message containing -give wood to as A substring
      • Player - Player 3 (Teal) types a chat message containing -give wood to as A substring
      • Player - Player 4 (Purple) types a chat message containing -give wood to as A substring
      • Player - Player 5 (Yellow) types a chat message containing -give wood to as A substring
      • Player - Player 6 (Orange) types a chat message containing -give wood to as A substring
      • Player - Player 7 (Green) types a chat message containing -give wood to as A substring
      • Player - Player 8 (Pink) types a chat message containing -give wood to as A substring
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 1, 13)) Equal to -give gold to
        • Then - Actions
          • Set TempString = (Entered chat string)
          • Set SubString = (Substring(TempString, 13, 22))
          • For each (Integer TempInt) from 1 to PlayerSlotStatusInteger, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SubString Equal to ( player + (String(TempInt)))
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                  • Set GiveGoldorWood_TrigPlayer[1] = (Triggering player)
                  • Set GiveGoldorWood_TrigPlayer[2] = (Player(TempInt))
                  • Set PlayerGroup = (Player group(GiveGoldorWood_TrigPlayer[1]))
                  • Game - Display to PlayerGroup the text: |c00FFD700Specify t...
                  • Custom script: call DestroyForce(udg_PlayerGroup)
                  • Custom script: set udg_PlayerGroup = null
                  • Trigger - Turn on Specifying the Amount of Gold <gen>
                  • Trigger - Add to Specifying the Amount of Gold <gen> the event (Player - GiveGoldorWood_TrigPlayer[1] types a chat message containing <Empty String> as An exact match)
                • Else - Actions
          • Set TempString = <Empty String>
          • Set SubString = <Empty String>
        • Else - Actions
          • Set TempString = (Entered chat string)
          • Set SubString = (Substring(TempString, 13, 22))
          • For each (Integer TempInt) from 1 to PlayerSlotStatusInteger, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SubString Equal to ( player + (String(TempInt)))
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                  • Set GiveGoldorWood_TrigPlayer[1] = (Triggering player)
                  • Set GiveGoldorWood_TrigPlayer[2] = (Player(TempInt))
                  • Set PlayerGroup = (Player group(GiveGoldorWood_TrigPlayer[1]))
                  • Game - Display to PlayerGroup the text: |c00FFD700Specify t...
                  • Custom script: call DestroyForce(udg_PlayerGroup)
                  • Custom script: set udg_PlayerGroup = null
                  • Trigger - Turn on Specifying the Amount of Wood <gen>
                  • Trigger - Add to Specifying the Amount of Wood <gen> the event (Player - GiveGoldorWood_TrigPlayer[1] types a chat message containing <Empty String> as An exact match)
                • Else - Actions
          • Set TempString = <Empty String>
          • Set SubString = <Empty String>
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
first this makes no sense
  • Trigger - Add to Specifying the Amount of Wood <gen> the event (Player - GiveGoldorWood_TrigPlayer[1] types a chat message containing <Empty String> as An exact match)
you shouldnt need to add an event when using substrings.

this
  • (Substring((Entered chat string), 1, 13)) Equal to -give gold to
should be 10 not 13

and change the number 22 in ur trigger to string length of tempString.

you know this will give the gold to all players doing it this way right ?

also check my example of substrings in my tutorial it should help a lot.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
because of Looping will it give gold to everyone?

first this makes no sense
  • Trigger - Add to Specifying the Amount of Wood <gen> the event (Player - GiveGoldorWood_TrigPlayer[1] types a chat message containing <Empty String> as An exact match)
why this doesn't makes sense? It adds event to type the amount of resource to give...

yes looping will cause it to give gold to everyone.
the event makes no sense because with substrings u never need that event. so its a useless event.

edit: wait u dont even give gold or wood to any player in this trigger....

edit2: heres a give gold trigger. to give gold u type in -give gold 1 125
the number 1 after gold is the player number. the 125 is the gold ur giving.
  • give gold
    • Events
      • Player - Player 1 (Red) types a chat message containing -give gold as A substring
      • Player - Player 2 (Blue) types a chat message containing -give gold as A substring
      • Player - Player 3 (Teal) types a chat message containing -give gold as A substring
      • Player - Player 4 (Purple) types a chat message containing -give gold as A substring
      • Player - Player 5 (Yellow) types a chat message containing -give gold as A substring
      • Player - Player 6 (Orange) types a chat message containing -give gold as A substring
      • Player - Player 7 (Green) types a chat message containing -give gold as A substring
      • Player - Player 8 (Pink) types a chat message containing -give gold as A substring
    • Conditions
    • Actions
      • Set tempString = (Entered chat string)
      • Set tempTrigPlayer = (Triggering player)
      • Set tempInt = (Integer((Substring(tempString, 12, 12))))
      • Set tempInt2 = (Integer((Substring(tempString, 14, (Length of tempString)))))
      • Custom script: set udg_tempPlayer = Player( udg_tempInt - 1)
      • Player - Set tempTrigPlayer Current gold to ((Player 1 (Red) Current gold) - tempInt2)
      • Player - Add tempInt2 to tempPlayer Current gold
      • Set tempString = <Empty String>
edit 3: heres the one for lumber
  • give wood
    • Events
      • Player - Player 1 (Red) types a chat message containing -give wood as A substring
      • Player - Player 2 (Blue) types a chat message containing -give wood as A substring
      • Player - Player 3 (Teal) types a chat message containing -give wood as A substring
      • Player - Player 4 (Purple) types a chat message containing -give wood as A substring
      • Player - Player 5 (Yellow) types a chat message containing -give wood as A substring
      • Player - Player 6 (Orange) types a chat message containing -give wood as A substring
      • Player - Player 7 (Green) types a chat message containing -give wood as A substring
      • Player - Player 8 (Pink) types a chat message containing -give wood as A substring
    • Conditions
    • Actions
      • Set tempString = (Entered chat string)
      • Set tempTrigPlayer = (Triggering player)
      • Set tempInt = (Integer((Substring(tempString, 12, 12))))
      • Set tempInt2 = (Integer((Substring(tempString, 14, (Length of tempString)))))
      • Custom script: set udg_tempPlayer = Player( udg_tempInt - 1)
      • Player - Set tempTrigPlayer Current lumber to ((Player 1 (Red) Current lumber) - tempInt2)
      • Player - Add tempInt2 to tempPlayer Current lumber
      • Set tempString = <Empty String>
 
Last edited:
Level 18
Joined
May 11, 2012
Messages
2,103
this is how it looks now, can't give u rep pff...

JASS:
function Trig_Give_Gold_Func004C takes nothing returns boolean
    if ( not ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) < udg_TempInt ) ) then
        return false
    endif
    return true
endfunction

function Trig_Give_Gold_Actions takes nothing returns nothing
    set udg_TempString = GetEventPlayerChatString()
    set udg_SubString = SubStringBJ(udg_TempString, 13, 13)
    set udg_TempInt = S2I(SubStringBJ(udg_TempString, 16, StringLength(udg_TempString)))
    if ( Trig_Give_Gold_Func004C() ) then
        set udg_TempInt = GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
        call SetPlayerStateBJ( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) - udg_TempInt ) )
    else
        call SetPlayerStateBJ( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) - udg_TempInt ) )
    endif
    set udg_PlayerGroup = GetForceOfPlayer(GetTriggerPlayer())
    call DisplayTextToForce( udg_PlayerGroup, ( "|c00FFD700You sent " + ( ( udg_PlayerColors[S2I(udg_SubString)] + GetPlayerName(ConvertedPlayer(S2I(udg_SubString))) ) + ( " " + ( ( "|c00ff0303" + I2S(udg_TempInt) ) + " |c00FFD700Gold from your stash" ) ) ) ) )
    call DestroyForce(udg_PlayerGroup)
    set udg_PlayerGroup = null
    // ------------------------------------------------------
    call AdjustPlayerStateBJ( udg_TempInt, ConvertedPlayer(S2I(udg_SubString)), PLAYER_STATE_RESOURCE_GOLD )
    set udg_PlayerGroup = GetForceOfPlayer(ConvertedPlayer(S2I(udg_SubString)))
    call DisplayTextToForce( udg_PlayerGroup, ( "|c00FFD700You received " + ( ( "|c00ff0303" + I2S(udg_TempInt) ) + ( " |c00ff0303Gold from" + ( udg_PlayerColors[GetConvertedPlayerId(ConvertedPlayer(S2I(udg_SubString)))] + GetPlayerName(GetTriggerPlayer()) ) ) ) ) )
    call DestroyForce(udg_PlayerGroup)
    set udg_PlayerGroup = null
    set udg_TempString = ""
    set udg_SubString = ""
endfunction

//===========================================================================
function InitTrig_Give_Gold takes nothing returns nothing
    set gg_trg_Give_Gold = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(0), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(1), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(2), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(3), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(4), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(5), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(6), "-give gold", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Give_Gold, Player(7), "-give gold", false )
    call TriggerAddAction( gg_trg_Give_Gold, function Trig_Give_Gold_Actions )
endfunction
 
Status
Not open for further replies.
Top