• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Matching a string + Matching the triggering player - Help!

Status
Not open for further replies.
Level 2
Joined
Feb 25, 2013
Messages
7
Hello folks!

I'm trying to help out a friend, and my plans were to build a map too. What I was trying to figure out was, how to check for an entered string + checking for a player.

Specified a bit more (I'm just using the normal trigger editor, but this is what I got)

Race Choose
- Events
Map Initialization​
- Conditions

- Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions

(Matched chat string) Equal to '-orc'

(Triggering player) Equal to Player 1 (Red)​

Then - Actions

Unit - Create 1 Great Hall for Player 1 (Red) at (Player 1 (Red) Start Location) facing Default building facing degrees

Unit - Create 5 Peon for Player 1 (Red) at (Player 1 (Red) Start Location) facing Default building facing degrees​
Else - Actions​


So, basically: If a person types '-orc', it should spawn a Great Hall and 5 Peons at the triggering player's start location.

I just can't get it to work :ogre_rage:

Anyone who's able to help me?


(Sorry for the weird code. Didn't know how to put it in, so I just put it in like that.

Thanks on forehand
- Stormman67
 
Level 7
Joined
Jan 30, 2011
Messages
267
the structure of a gui trigger is this:
1. an amount of events (in your case 1 event, map initialization)
2. conditions, that have to be fulfilled when the trigger is being executed
3. actions, that are being executed when the trigger is being executed (only if the conditions are fulfilled)

you want your trigger to fire when someone types "-orc"
so the event you need is player chat event, not map initialization (map initialization is, when the load screen opens)

this is the event you need
  • chat trigger orc
    • Events
      • Player - Player 1 (Red) types a chat message containing -orc as exact match
you have to copy the event for every player that should be able to type the -orc command
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You can copy triggers by right-clicking the trigger name above "Events" and selecting "Copy as Text".
Then write [trigger] here on the hive, press CTRL + C (or right-click and select "copy") and close the trigger by writing [/trigger].
Full tutorial (if needed).

The event should be "Player - Player 1 (Red) types a chat message containing - as A substring" (for all players).
The condition should be "Entered Chat String equal to (...)".

Alternative: (it's in JASS, but GUI-friendly)
Copy this code:
JASS:
function FindNearestMine takes real x, real y, real dist returns unit
    local group g = CreateGroup()
    local real tempDist
    local unit u
    
    set bj_meleeNearestMineDist = 4000001
    set bj_meleeNearestMine = null
    call GroupEnumUnitsInRange( g, x, y, dist, null )
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        
        set tempDist = (GetUnitX(u) - x) * (GetUnitX(u) - x) + (GetUnitY(u) - y) * (GetUnitY(u) - y)
        if tempDist < bj_meleeNearestMineDist then
            set bj_meleeNearestMineDist = tempDist
            set bj_meleeNearestMine = u
        endif
        call GroupRemoveUnit(g, u)
    endloop
    
    call DestroyGroup(g)
    set g = null
    
    return bj_meleeNearestMine
endfunction

function SetupUnits takes nothing returns nothing
    local unit      nearestMine
    local real      startX = GetStartLocationX( GetPlayerStartLocation(udg_Player) )
    local real      startY = GetStartLocationY( GetPlayerStartLocation(udg_Player) )
    local real      peonX
    local real      peonY
    local real      angle
    local unit      townHall = null

    set nearestMine = FindNearestMine( startX, startY, bj_MELEE_MINE_SEARCH_RADIUS )
    if (nearestMine != null) then
        // Spawn Town Hall at the start location.
        set townHall = CreateUnit( udg_Player, udg_TownhallType, startX, startY, bj_UNIT_FACING )
        
        // Spawn Peasants near the mine.
        set angle = Atan2( startY - GetUnitY(nearestMine), startX - GetUnitX(nearestMine))
        set peonX = GetUnitX(nearestMine) + 320. * Cos( angle )
        set peonY = GetUnitY(nearestMine) + 320. * Sin( angle )
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 0.00 * 64., peonY + 1.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 1.00 * 64., peonY + 0.15 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX - 1.00 * 64., peonY + 0.15 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 0.60 * 64., peonY - 1.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX - 0.60 * 64., peonY - 1.00 * 64., bj_UNIT_FACING)
    else
        // Spawn Town Hall at the start location.
        set townHall = CreateUnit(udg_Player, udg_TownhallType, startX, startY, bj_UNIT_FACING)
        
        // Spawn Peasants directly south of the town hall.
        set peonX = startX
        set peonY = startY - 224.00
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 2.00 * 64., peonY + 0.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 1.00 * 64., peonY + 0.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX + 0.00 * 64., peonY + 0.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX - 1.00 * 64., peonY + 0.00 * 64., bj_UNIT_FACING)
        call CreateUnit(udg_Player, udg_BuilderType, peonX - 2.00 * 64., peonY + 0.00 * 64., bj_UNIT_FACING)
    endif

    call SetPlayerState(udg_Player, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)

    if GetLocalPlayer() == udg_Player then
        call SetCameraPosition(peonX, peonY)
        call SetCameraQuickPosition(peonX, peonY)
    endif
    
    set townHall = null
    set nearestMine = null
endfunction
Copy it in the map header
Vap82G1.jpg

Create 3 variables:
  • "Player": player variable.
  • "BuilderType": unit-type variable.
  • "TownhallType": unit-type variable.

To spawn 5 builders for a player, these are the required actions:
  • Actions
    • Set Player = (Triggering player)
    • Set TownhallType = Great Hall
    • Set BuilderType = Peon
    • Custom script: call SetupUnits()
  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Set Player = (Triggering player)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to -human
        • Then - Actions
          • Set TownhallType = Castle
          • Set BuilderType = Peasant
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Entered chat string) Equal to -orc
            • Then - Actions
              • Set TownhallType = Fortress
              • Set BuilderType = Peon
            • Else - Actions
      • Custom script: call SetupUnits()
 
Level 2
Joined
Feb 25, 2013
Messages
7
the structure of a gui trigger is this:
1. an amount of events (in your case 1 event, map initialization)
2. conditions, that have to be fulfilled when the trigger is being executed
3. actions, that are being executed when the trigger is being executed (only if the conditions are fulfilled)

you want your trigger to fire when someone types "-orc"
so the event you need is player chat event, not map initialization (map initialization is, when the load screen opens)

this is the event you need
  • chat trigger orc
    • Events
      • Player - Player 1 (Red) types a chat message containing -orc as exact match
you have to copy the event for every player that should be able to type the -orc command


- How I wanted to do it was like this: 'Somebody' types -orc. Then I want it to check, if the triggering player is red. If the player is Red, it spawns the specified units at the triggering player's spawn location

Then, further down I want to check if the player is blue, and if it's blue, it spawns the units at the triggering player's spawn so I don't have to put it like "Red types in chat" bla bla, so on.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Set Player = (Triggering player)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to -human
        • Then - Actions
          • Set TownhallType = Castle
          • Set BuilderType = Peasant
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Entered chat string) Equal to -orc
            • Then - Actions
              • Set TownhallType = Fortress
              • Set BuilderType = Peon
            • Else - Actions
      • Custom script: call SetupUnits()

this is what u want then
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
- How I wanted to do it was like this: 'Somebody' types -orc. Then I want it to check, if the triggering player is red. If the player is Red, it spawns the specified units at the triggering player's spawn location

Then, further down I want to check if the player is blue, and if it's blue, it spawns the units at the triggering player's spawn so I don't have to put it like "Red types in chat" bla bla, so on.
I think you're mistaken: you do need "Red types in chat" and "Blue types in chat" (and this for all players).
You do not need to check whether the player is Red, Blue or whatever - this can be done automatically by creating the units at the Player's (triggering player) starting location.

Anyway, did you try out that thingy I said before? :)
It should mimic the regular melee init, but then for any townhall/peasant you like and at any time you like.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Maybe you are confused with having multiple events.

The Trigger gets evaluated when one of the events fires. Assume you have a trigger with the following events:
  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
Whenever one of the Players 1, 2 or 3 types in a chat command containing "-" the trigger will start running, the conditions will be checked and if all conditions are fullfilled the actions are executed.

Example:

  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Unit - Create 1 Peon for (Triggering Player) at (Starting location of (Triggering Player))
Assume Player 2 types in "-asdasd" then the trigger will start running, the conditions will be checked (there are no conditions -> all are fullfilled) and the actions are executed. Now "Triggering Player" can be considered a variable containing the Player who triggered the event, in this case "Triggering Player" is equal to "Player 2".

Long story short:
- Events: Whenever one of the event fires, the trigger will start running
- Conditions: When all the conditions are true, the trigger will proceed with executing the actions
 
Level 2
Joined
Feb 25, 2013
Messages
7
Maybe you are confused with having multiple events.

The Trigger gets evaluated when one of the events fires. Assume you have a trigger with the following events:
  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
Whenever one of the Players 1, 2 or 3 types in a chat command containing "-" the trigger will start running, the conditions will be checked and if all conditions are fullfilled the actions are executed.

Example:

  • Choose Race
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Unit - Create 1 Peon for (Triggering Player) at (Starting location of (Triggering Player))
Assume Player 2 types in "-asdasd" then the trigger will start running, the conditions will be checked (there are no conditions -> all are fullfilled) and the actions are executed. Now "Triggering Player" can be considered a variable containing the Player who triggered the event, in this case "Triggering Player" is equal to "Player 2".

Long story short:
- Events: Whenever one of the event fires, the trigger will start running
- Conditions: When all the conditions are true, the trigger will proceed with executing the actions



Oh, so what I can do basically, is set up an Event for all 10 players that I want, and if a player types in that string, e.g. -orc, I should put it to spawning units for Triggering Player?
 
Status
Not open for further replies.
Top