Code: Select all
globals
trigger trgChat=CreateTrigger() //The trigger that will be activated upon every chat command
endglobals
function ChatCommands takes nothing returns nothing
local string str=StringCase(GetEventPlayerChatString(),false)//A string variable holding the text writted, I turned it into a lower-case string to ease the "detection" of the written string.
local group grp=CreateGroup() //A group variable to hold all our picked units.
local unit unt //A unit variable to hold our picked unit.
if str=="-repick"then //An example for a command that doesn't require picked units.
//enter repick code here
elseif str=="-test"then //Another example for a command that doesn't require picked units, this can go on for ever, you can add as many "elseif" as you want to make every string command you want.
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Test worked") //An action that happens after you used the string command
endif //Stops to check for a command that doesn't demmand a picked unit.
call GroupEnumUnitsSelected(grp,GetTriggerPlayer(),null) //setting our group variable to hold our picked units
loop //looping our group for all the units we picked
set unt=FirstOfGroup(grp) //setting the unit variable to the first/next unit we picked
exitwhen unt==null //exitwhen the next unit is null, meaning there is no other unit
if str=="-godly all"then //An example for a command that requires picked units
//enter godly code here
elseif str=="-kill"then //Another example for a command that requires picked units
call KillUnit(unt) //An action that happens after using the string command.
endif //Stops to check for any string commands
call RemoveLocation(GetUnitLoc(unt)) //Removing Leaks
call GroupRemoveUnit(grp,unt) //Removing Leaks
endloop //Ending the loop and going for the next unit.
call DestroyGroup(grp) //Removing Leaks
set str="" //Removing Leaks
set grp=null //Removing Leaks
set unt=null //Removing Leaks
endfunction
function main takes nothing returns nothing
call TriggerRegisterPlayerChatEvent(trgChat,Player(0),"-",false) //Each time Player(0) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(1),"-",false) //Each time Player(1) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(2),"-",false) //Each time Player(2) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(3),"-",false) //Each time Player(3) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(4),"-",false) //Each time Player(4) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(5),"-",false) //Each time Player(5) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(6),"-",false) //Each time Player(6) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(7),"-",false) //Each time Player(7) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(8),"-",false) //Each time Player(8) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(9),"-",false) //Each time Player(9) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(10),"-",false) //Each time Player(10) writes a string containing "-", it will be triggered
call TriggerRegisterPlayerChatEvent(trgChat,Player(11),"-",false) //Each time Player(11) writes a string containing "-", it will be triggered
call TriggerAddAction(trgChat,function ChatCommands) //The function that will be caleld once the trigger is triggerd.
endfunction