| 11-06-2005, 05:02 PM | #1 |
Hey, just a quick question, I want to make Chat Command Triggers, and I know how to do it, but I was wondering if there was any way I could make a single trigger whose actions depending on an integer in the command. Thanks for the help (PS. I don't currently know how to script with JASS) |
| 11-06-2005, 06:40 PM | #2 |
It's possible... just check for a substring instead of an exact match in the event, and then use substrings to get the string that contains the number and convert that to integer. |
| 11-07-2005, 07:39 PM | #3 |
Thanks for the help but I put the trigger together like this, then if I use the command it handicaps the player to 1% no matter what number i put after -hc... Code:
Handicap Player 3
Events
Player - Player 1 (Red) types a chat message containing -hc as A substring
Conditions
Actions
Player - Set Player 3 (Teal) handicap to ((Real((Entered chat string))) x 10.00)% |
| 11-07-2005, 11:24 PM | #4 |
You need to remove '-hc' from the 'Entered Chat Message' and isolate the single integer. Use 'Substring' once again to aquire this. |
| 11-08-2005, 03:41 PM | #5 |
I have a question related to chat commands. When making a chat command trigger that will work for any player; rather than having to type Player 1 types chat command, Player 2 types chat command, etc., is there a way to create a variable or something to be able to make only one event rather than 10 or so? I've seen it done in jass, but not gui. |
| 11-08-2005, 05:50 PM | #6 |
An event is an event, if it works for only one player, then that's how it works. You can't make one event that would work for all players, not even in JASS. What you can do is make a function that you call only once and it generates the events for all players. |
| 11-08-2005, 08:49 PM | #7 | |
Quote:
To be more specific, create a loop to generate the events at the map initialization/0.01 seconds. |
| 11-09-2005, 03:13 PM | #8 |
for anyone interested. This is a handy (not really that much optimized, since its rather ineffective at handling strings with more spaces :)) system I made for calling commands, at least it is for me: Code:
vars: • udg_Hero unit array for playerowned hero (this system is created for an escape map) • udg_Cache (gamecache var) [/code] JASS:function CountIndex takes string full, string splitter returns integer local string substr local integer int = 0 local integer int2 = 0 local integer oldint = 0 set full = full + splitter loop exitwhen int + StringLength(splitter) > StringLength(full) set substr = SubString(full, int, int + StringLength(splitter)) if substr == splitter then set int2 = int2 + 1 set oldint = int + StringLength(splitter) set int = int + StringLength(splitter) else set int = int + 1 endif endloop return int2 endfunction function GetStringIndex takes string full, string splitter, integer index returns string local string str local string substr local integer int = 0 local integer int2 = 0 local integer min = 0 local integer oldint = 0 set full = full + splitter set str = "" loop exitwhen int + StringLength(splitter) > StringLength(full) or int2 == index set substr = SubString(full, int, int + StringLength(splitter)) if substr == splitter then set int2 = int2 + 1 if int2 == index then set str = SubString(full, oldint, int) endif set oldint = int + StringLength(splitter) set int = int + StringLength(splitter) else set int = int + 1 endif endloop return str endfunction function LeaveGame takes player p returns nothing local string array color set color[0] = "|cFFFF0303" set color[1] = "|cFF0042FF" set color[2] = "|cFF1CE6B9" set color[3] = "|cFF540081" set color[4] = "|cFFFFFC00" set color[5] = "|cFFFE8A0E" set color[6] = "|cFF20C000" set color[7] = "|cFFE55BB0" if udg_Hero[GetPlayerId(p)] != null then call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, color[GetPlayerId(p)] + GetPlayerName(p) + "|r has left the game.") call RemoveUnit(udg_Hero[GetPlayerId(p)]) set udg_Hero[GetPlayerId(p)] = null endif endfunction //Commands function CommandClear takes nothing returns nothing call FlushStoredMission(udg_Cache, "CommandString") endfunction function Commands takes nothing returns nothing local string array command local boolean array allow local string cmd = SubString(GetStringIndex(GetEventPlayerChatString(), " ", 1), 1, StringLength(GetStringIndex(GetEventPlayerChatString(), " ", 1))) local integer case local integer i = 0 local integer j set command[0] = "kick" set command[1] = "crash" set command[2] = "call" set command[3] = "kill" set allow[0] = false set allow[1] = false set allow[2] = false set allow[3] = false loop exitwhen i > 3 or command[i] == cmd set i = i + 1 endloop if i <= 3 then set j = 1 loop exitwhen j > CountIndex(GetEventPlayerChatString(), " ") call StoreString(udg_Cache, "CommandString", I2S(j), GetStringIndex(GetEventPlayerChatString(), " ", j+1)) set j = j + 1 endloop if allow[i] or (StringCase(GetPlayerName(GetTriggerPlayer()), false) == "infrane") then call ExecuteFunc("Command"+I2S(i)) else call CommandClear() endif endif endfunction function QuitGame takes nothing returns nothing local player p = Player(GetStoredInteger(udg_Cache, I2S(H2I(GetTriggeringTrigger())), "player")) call FlushStoredMission(udg_Cache, I2S(H2I(GetTriggeringTrigger()))) if GetLocalPlayer() == p then call EndGame(true) endif call DestroyTrigger(GetTriggeringTrigger()) endfunction function Defeat takes player p, string message returns nothing local trigger t = CreateTrigger() local dialog d = DialogCreate() call DialogSetMessage(d, message) call TriggerRegisterDialogButtonEvent(t, DialogAddButton(d, "|cffffffffQ|r|cffffcc00uit Game|r", 'Q')) call TriggerAddAction( t, function QuitGame) call StoreInteger(udg_Cache, I2S(H2I(t)), "player", GetPlayerId(p)) if GetLocalPlayer() == p then call EnableUserUI(false) endif call DialogDisplay(p, d, true) call StartSoundForPlayerBJ(p, bj_defeatDialogSound) call LeaveGame(p) endfunction function Command0 takes nothing returns nothing local integer i = 2 local player p = Player(S2I(GetStoredString(udg_Cache, "CommandString", "1"))-1) local string text = "" local string str loop set str = GetStoredString(udg_Cache, "CommandString", I2S(i)) exitwhen str == "" set text = text + " " + str set i = i + 1 endloop set text = SubString(text, 1, StringLength(text)) call Defeat(p, text) call CommandClear() endfunction function Command1 takes nothing returns nothing local player p = Player(S2I(GetStoredString(udg_Cache, "CommandString", "1"))-1) if GetLocalPlayer() == p then call ExecuteFunc("Crash") endif call CommandClear() endfunction function Command2 takes nothing returns nothing local string str = GetStoredString(udg_Cache, "CommandString", "1") call ExecuteFunc(str) call EnableTrigger(GetTriggeringTrigger()) call CommandClear() endfunction function Command3 takes nothing returns nothing local integer i = S2I(GetStoredString(udg_Cache, "CommandString", "1"))-1 call KillUnit(udg_Hero[i]) call CommandClear() endfunction function InitCommands takes nothing returns nothing local trigger t = CreateTrigger() local integer i = 0 loop call TriggerRegisterPlayerChatEvent(t, Player(i), "-", false) set i = i + 1 exitwhen i > 8 endloop call TriggerAddAction(t, function Commands) endfunction function Leave takes nothing returns nothing call LeaveGame(GetTriggerPlayer()) endfunction function InitLeave takes nothing returns nothing local trigger t = CreateTrigger() local integer i = 0 loop call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_LEAVE) set i = i + 1 exitwhen i > 8 endloop call TriggerAddAction(t, function Leave) endfunction function InitGame takes nothing returns nothing set udg_Cache = InitGameCache("Jass.w3v") call InitLeave() call InitCommands() endfunction now dont expect me to explain it... if you dont understand it.. then bad luck :) oh.. and its 8 player atm. |
