• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Need help with changing ownership of a selected unit by chat command.

Status
Not open for further replies.

TerranMarineJn

T

TerranMarineJn

How can I change ownership of a selected unit by typing something like "-give color".

Let's say I want to give a unit of mine to player blue. So I type in the message "-give blue" and then the selected unit of mine is changed ownership to blue. However, only the player of that unit can change the ownership of that unit. So If I'm player red, I'm the only one that change my unit's ownership and no other players are able to change the ownership of my units. So like only player red is able to change ownership of their units, only player blue is only able to change ownership of his units, and so on.

Similar Example: So I want to give a unit of mine to player green, so I type in "give green" and the selected unit of mine is given to green.

How do I do this trigger in world editor?
 
To do all of this in a single trigger is a little bothersome, but possible.

First this should be the event:
  • Player - Player 1 (Red) types a chat message containing -give as A substring
  • Player - Player 2 (Blue) types a chat message containing -give as A substring
  • //and the rest of the players
Next, loop through all the units selected by the player, and if they don't own one of them, end the trigger with Skip Remaining Actions.

Next, get the substring of the entered chat message:
  • Set TempString = (Substring((Entered chat string), 7, 99))
And compare the string to each of the colors (red, green, blue, etc), then give the units to the appropriate player. This will sightly mess up if there are trailing spaces ("red " != "red") but that's probably not a big deal.
 
Fortunately the game will stop checking characters at the end of the string. Using the string length instead of a arbitrarily large number is still better coding practice though, of course.

Amusingly it doesn't check whether you specified 0 or negative values for the first argument, though. Nice way to get segfaults.
 
Amusingly it doesn't check whether you specified 0 or negative values for the first argument, though. Nice way to get segfaults.
Technically it starts at 0. GUI adds an offset for some... reason.

JASS:
function SubStringBJ takes string source,integer start,integer end returns string
    return SubString(source, start-1, end)
endfunction
 
Status
Not open for further replies.
Back
Top