| 02-19-2008, 04:58 AM | #1 |
Oooo, it's scary in here! I rarely touch the scripting forum. So, I know next to nothing about JASS, but I'm trying to learn at least a few things. Hopefully someone can help me out with what I think is a pretty simple script. Most games that allow players to change alliances use the "-ally blue" type commands. They require both players to ally each other, but sometime a player will miss the chat message and then one player forgets he is allied and whatever..... So I want to make a system that allows one player (Player 1 Red) to type -ally blue, and then player 2 will get a pop-up message that says "Player 1 would like to ally" with options Accept or Decline. No changes actually take place until Player 2 clicks Accept. Then they both ally each other. The Decline option sends Player 1 a message saying "Player 2 has declined your request for an alliance". I'd like to use GetPlayerName to use their actual name for the dialogs. GUI will make it messy so I want to try to make it clean and include these points: -A player types a chat message "-ally blue" -Check to make sure they are not already allied and return a message to the triggering player if the are -Make a dialog box with options "Accept" and "Decline" -If Accept, then triggering player allies player 2, and player 2 allies triggering player -If Decline, send a message to the triggering player saying player 2 declines Thank you to anyone who is able to help. If I do get some help here I can see what I can learn from it. I hope that's not too confusing or too much work. |
| 02-19-2008, 09:08 AM | #2 |
Well, this would be very easy with cohadar's Dialog System. Using his system, I'd do it in a fashion such as this: JASS:library AllyDialogs uses Dialogs initializer Init globals //Config private constant string ALLYPHRASESTART = "-ally" //must be lowercase private constant string UNALLYPHRASESTART = "-unally" //must be lowercase private constant real XOFF = 0.00 private constant real YOFF = 0.00 private constant real DISPLAYTIME = 5.00 endglobals private struct Info player AllyInit = null player AllyAccept = null boolean Flag = false endstruct globals //Library globals private trigger Ally = CreateTrigger() private trigger UnAlly = CreateTrigger() private Info array Infos endglobals private function GetIdFromName takes string Name returns integer set Name = StringCase(Name, false) if Name == "red" then return 0 elseif Name == "blue" then return 1 elseif Name == "teal" then return 2 elseif Name == "purple" then return 3 elseif Name == "yellow" then return 4 elseif Name == "orange" then return 5 elseif Name == "green" then return 6 elseif Name == "pink" then return 7 elseif Name == "grey" or Name == "gray" then //2 different spellings return 8 elseif Name == "light blue" then return 9 elseif Name == "dark green" then return 10 elseif Name == "brown" then return 11 endif return 0 endfunction private function NameGet takes integer PId returns string if PId == 0 then return "|CFFFF0303"+GetPlayerName(Player(PId))+|r elseif PId == 1 then return "|CFF0042FF"+GetPlayerName(Player(PId))+|r elseif PId == 2 then return "|CFF1CB619"+GetPlayerName(Player(PId))+|r elseif PId == 3 then return "|CFF540081"+GetPlayerName(Player(PId))+|r elseif PId == 4 then return "|CFFFFFF01"+GetPlayerName(Player(PId))+|r elseif PId == 5 then return "|CFFFE8A0E"+GetPlayerName(Player(PId))+|r elseif PId == 6 then return "|CFF20C000"+GetPlayerName(Player(PId))+|r elseif PId == 7 then return "|CFFE55BB0"+GetPlayerName(Player(PId))+|r elseif PId == 8 then return "|CFF959697"+GetPlayerName(Player(PId))+|r elseif PId == 9 then return "|CFF7EBFF1"+GetPlayerName(Player(PId))+|r elseif PId == 10 then return "|CFF106246"+GetPlayerName(Player(PId))+|r elseif PId == 11 then return "|CFF4E2A04"+GetPlayerName(Player(PId))+|r endif return "Player "+I2S(PId) endfunction private function Clicked takes nothing returns nothing local Dialog D = GetTriggerDialog() local Info I = Infos[integer(D)] local string State = "unall" if I.Flag then set State = "all" endif if D.GetResult == HK_Y then call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_PASSIVE, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_HELP_REQUEST, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_HELP_RESPONSE, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_SHARED_XP, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_SHARED_SPELLS, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_PASSIVE, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_HELP_REQUEST, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_HELP_RESPONSE, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_SHARED_XP, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_SHARED_SPELLS, I.Flag) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "Your request to "+State+"y with "+NameGet(GetPlayerId(I.AllyAccept))+" has been accepted. You are now"+State+"ied with "+NameGet(GetPlayerId(I.AllyAccept))+".") call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have accepted a request to "+State+"y with "+NameGet(GetPlayerId(I.AllyInit))+". You are now"+State+"ied with "+NameGet(GetPlayerId(I.AllyInit))+".") else call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "Your request to "+State+"y with "+NameGet(GetPlayerId(I.AllyAccept))+" has been denied.") call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have denied a request to "+State+"y with "+NameGet(GetPlayerId(I.AllyInit))+".") endif call I.destroy() call D.destroy() endfunction private function InitAlly takes nothing returns nothing local string S = GetEventPlayerChatString() local Dialog D = NewDialog() local Info I = Info.create() local player P = GetTriggerPlayer() local integer PId = GetIdFromName(SubString(S, StringLength(ALLYPHRASESTART)+1, StringLength(S))) call D.SetMessage(NameGet(GetPlayerId(P))+" wants to ally with you.|nDo you accept?") call D.AddButton("|cffffcc00Y|res", HK_Y) call D.AddButton("|cffffcc00N|ro", HK_N) call D.AddAction(function Clicked) set I.AllyInit = P set I.AllyAccept = Player(PId) set I.Flag = true set Infos[integer(D)] = I call D.Show(I.AllyAccept) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have requested to ally with "+NameGet(PId)+".") endfunction private function InitUnAlly takes nothing returns nothing local string S = GetEventPlayerChatString() local Dialog D = NewDialog() local Info I = Info.create() local player P = GetTriggerPlayer() local integer PId = GetIdFromName(SubString(S, StringLength(UNALLYPHRASESTART)+1, StringLength(S))) call D.SetMessage(NameGet(GetPlayerId(P))+" wants to unally with you.|nDo you accept?") call D.AddButton("|cffffcc00Y|res", HK_Y) call D.AddButton("|cffffcc00N|ro", HK_N) call D.AddAction(function Clicked) set I.AllyInit = P set I.AllyAccept = Player(PId) set I.Flag = false set Infos[integer(D)] = I call D.Show(I.AllyAccept) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have requested to unally with "+NameGet(PId)+".") endfunction private function AllyConditions takes nothing returns boolean return StringCase(Substring(GetEventPlayerChatString(), 0, StringLength(ALLYPHRASESTART)), false) == ALLYPHRASESTART endfunction private function UnAllyConditions takes nothing returns boolean return StringCase(Substring(GetEventPlayerChatString(), 0, StringLength(UNALLYPHRASESTART)), false) == UNALLYPHRASESTART endfunction private function Init takes nothing returns nothing local integer I = -1 loop set I = I+1 exitwhen I>11 call TriggerRegisterPlayerChatEvent(Ally, Player(I), ALLYPHRASESTART, false) call TriggerRegisterPlayerChatEvent(UnAlly, Player(I), UNALLYPHRASESTART, false) endloop call TriggerAddCondition(Ally, Condition(function AllyConditions)) call TriggerAddAction(Ally, function InitAlly) call TriggerAddCondition(UnAlly, Condition(function UnAllyConditions)) call TriggerAddAction(UnAlly, function InitUnAlly) endfunction endlibrary Sorry if it's not perfect... I wish I had a compiler to check this with. |
| 02-19-2008, 11:57 PM | #3 |
Thank you very much for your help! I got ABC and the Dialog systems and put those in, but i get quite a few compile errors while saving. I've managed to fix some, and here's the place where most of the unresolved errors come up: JASS:function AllyDialogs___Clicked takes nothing returns nothing local integer D= GetTriggerDialog() local integer I= AllyDialogs___Infos[(D)] local string State= "unall" if s__AllyDialogs___Info_Flag[i] then set State = "all" endif if Dialog.getMethod(GetResult,D) == HK_Y then call SetPlayerAlliance(s__AllyDialogs___Info_AllyInit[i] , s__AllyDialogs___Info_AllyAccept[i] , ALLIANCE_PASSIVE , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyInit[i] , s__AllyDialogs___Info_AllyAccept[i] , ALLIANCE_HELP_REQUEST , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyInit[i] , s__AllyDialogs___Info_AllyAccept[i] , ALLIANCE_HELP_RESPONSE , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyInit[i] , s__AllyDialogs___Info_AllyAccept[i] , ALLIANCE_SHARED_XP , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyInit[i] , s__AllyDialogs___Info_AllyAccept[i] , ALLIANCE_SHARED_SPELLS , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyAccept[i] , s__AllyDialogs___Info_AllyInit[i] , ALLIANCE_PASSIVE , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyAccept[i] , s__AllyDialogs___Info_AllyInit[i] , ALLIANCE_HELP_REQUEST , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyAccept[i] , s__AllyDialogs___Info_AllyInit[i] , ALLIANCE_HELP_RESPONSE , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyAccept[i] , s__AllyDialogs___Info_AllyInit[i] , ALLIANCE_SHARED_XP , s__AllyDialogs___Info_Flag[i]) call SetPlayerAlliance(s__AllyDialogs___Info_AllyAccept[i] , s__AllyDialogs___Info_AllyInit[i] , ALLIANCE_SHARED_SPELLS , s__AllyDialogs___Info_Flag[i]) call DisplayTimedTextToPlayer(s__AllyDialogs___Info_AllyInit[i] , AllyDialogs___XOFF , AllyDialogs___YOFF , AllyDialogs___DISPLAYTIME , "Your request to " + State + "y with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyAccept[i])) + " has been accepted. You are now" + State + "ied with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyAccept[i])) + ".") call DisplayTimedTextToPlayer(s__AllyDialogs___Info_AllyInit[i] , AllyDialogs___XOFF , AllyDialogs___YOFF , AllyDialogs___DISPLAYTIME , "You have accepted a request to " + State + "y with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyInit[i])) + ". You are now" + State + "ied with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyInit[i])) + ".") else call DisplayTimedTextToPlayer(s__AllyDialogs___Info_AllyInit[i] , AllyDialogs___XOFF , AllyDialogs___YOFF , AllyDialogs___DISPLAYTIME , "Your request to " + State + "y with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyAccept[i])) + " has been denied.") call DisplayTimedTextToPlayer(s__AllyDialogs___Info_AllyInit[i] , AllyDialogs___XOFF , AllyDialogs___YOFF , AllyDialogs___DISPLAYTIME , "You have denied a request to " + State + "y with " + AllyDialogs___NameGet(GetPlayerId(s__AllyDialogs___Info_AllyInit[i])) + ".") endif call s__AllyDialogs___Info_destroy(I) call s__Dialog_destroy(D) endfunction First, is says undeclared variable "Dialog" and then a few lines later under the else it has undeclared I and undeclared State. I also get a lot of "Statement outside of function" maybe related to a syntax problem. Or maybe I have imported the other systems incorrectly? They each have their own trigger. Again, thanks for the help and hopefully I can get this figured out. EDIT: Sorry, something else. I don't need dialog boxes to unally. If one player types "-unally blue" then both players should be at war with each other without asking permission. |
| 02-25-2008, 04:59 AM | #4 |
Well, if you don't need there to be a dialog for un-allying, then there's a fair amount of code you don't need. I'd also need to see the uncompiled code that's giving you those errors. Can you post the most recent uncompiled code you have? I'll remove the excess un-allying dialog crap and see if I can spot those other errors. |
| 02-25-2008, 11:42 PM | #5 |
Hey! Thanks, I'll post what I have. Here are the systems I have, each in its own trigger: ABC 5.1 http://wc3campaigns.net/showthread.php?t=95872 Dialog System 2.1b http://wc3campaigns.net/showthread.php?t=97425 And here is the Ally System. I fixed the NameGet function ebcause it was missing some quotes and then I marked in comments where the errors show up. Maybe I didn't implement the ABC and Dialog systems correctly because there are a lot of undeclared variable errors. Uh oh! My noob is showing! JASS:library AllyDialogs initializer Init uses Dialogs globals //Config private constant string ALLYPHRASESTART = "-ally" //must be lowercase private constant string UNALLYPHRASESTART = "-unally" //must be lowercase private constant real XOFF = 0.00 private constant real YOFF = 0.00 private constant real DISPLAYTIME = 5.00 endglobals private struct Info player AllyInit = null player AllyAccept = null boolean Flag = false endstruct globals //Library globals private trigger Ally = CreateTrigger() private trigger UnAlly = CreateTrigger() private Info array Infos endglobals private function GetIdFromName takes string Name returns integer set Name = StringCase(Name, false) if Name == "red" then return 0 elseif Name == "blue" then return 1 elseif Name == "teal" then return 2 elseif Name == "purple" then return 3 elseif Name == "yellow" then return 4 elseif Name == "orange" then return 5 elseif Name == "green" then return 6 elseif Name == "pink" then return 7 elseif Name == "grey" or Name == "gray" then //2 different spellings return 8 elseif Name == "light blue" or Name == "lightblue" then //2 different spellings return 9 elseif Name == "dark green" or Name == "darkgreen" then //2 different spellings return 10 elseif Name == "brown" then return 11 endif return 0 endfunction private function NameGet takes integer PId returns string if PId == 0 then return "|CFFFF0303"+GetPlayerName(Player(PId))+"|r" elseif PId == 1 then return "|CFF0042FF"+GetPlayerName(Player(PId))+"|r" elseif PId == 2 then return "|CFF1CB619"+GetPlayerName(Player(PId))+"|r" elseif PId == 3 then return "|CFF540081"+GetPlayerName(Player(PId))+"|r" elseif PId == 4 then return "|CFFFFFF01"+GetPlayerName(Player(PId))+"|r" elseif PId == 5 then return "|CFFFE8A0E"+GetPlayerName(Player(PId))+"|r" elseif PId == 6 then return "|CFF20C000"+GetPlayerName(Player(PId))+"|r" elseif PId == 7 then return "|CFFE55BB0"+GetPlayerName(Player(PId))+"|r" elseif PId == 8 then return "|CFF959697"+GetPlayerName(Player(PId))+"|r" elseif PId == 9 then return "|CFF7EBFF1"+GetPlayerName(Player(PId))+"|r" elseif PId == 10 then return "|CFF106246"+GetPlayerName(Player(PId))+"|r" elseif PId == 11 then return "|CFF4E2A04"+GetPlayerName(Player(PId))+"|r" endif return "Player "+I2S(PId) endfunction private function Clicked takes nothing returns nothing local Dialog D = GetTriggerDialog() local Info I = Infos[integer(D)] local string State = "unall" if I.Flag then set State = "all" endif //Undeclared variable dialog and syntax error if D.GetResult == HK_Y then call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_PASSIVE, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_HELP_REQUEST, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_HELP_RESPONSE, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_SHARED_XP, I.Flag) call SetPlayerAlliance(I.AllyInit, I.AllyAccept, ALLIANCE_SHARED_SPELLS, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_PASSIVE, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_HELP_REQUEST, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_HELP_RESPONSE, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_SHARED_XP, I.Flag) call SetPlayerAlliance(I.AllyAccept, I.AllyInit, ALLIANCE_SHARED_SPELLS, I.Flag) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "Your request to "+State+"y with "+NameGet(GetPlayerId(I.AllyAccept))+" has been accepted. You are now"+State+"ied with "+NameGet(GetPlayerId(I.AllyAccept))+".") call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have accepted a request to "+State+"y with "+NameGet(GetPlayerId(I.AllyInit))+". You are now"+State+"ied with "+NameGet(GetPlayerId(I.AllyInit))+".") //missing end function and a syntax error and statement outside of funstion else //Undeclared variable I and undeclared variable State call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "Your request to "+State+"y with "+NameGet(GetPlayerId(I.AllyAccept))+" has been denied.") call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have denied a request to "+State+"y with "+NameGet(GetPlayerId(I.AllyInit))+".") //syntax error and error outside of function endif //undeclared variable D call I.destroy() call D.destroy() //statement outside of function and syntax error endfunction private function InitAlly takes nothing returns nothing local string S = GetEventPlayerChatString() //undeclared function NewDialog and cannot convert null to integer local Dialog D = NewDialog() local Info I = Info.create() local player P = GetTriggerPlayer() local integer PId = GetIdFromName(SubString(S, StringLength(ALLYPHRASESTART)+1, StringLength(S))) call D.SetMessage(NameGet(GetPlayerId(P))+" wants to ally with you.|nDo you accept?") call D.AddButton("|cffffcc00Y|res", HK_Y) call D.AddButton("|cffffcc00N|ro", HK_N) call D.AddAction(function Clicked) set I.AllyInit = P set I.AllyAccept = Player(PId) set I.Flag = true set Infos[integer(D)] = I call D.Show(I.AllyAccept) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have requested to ally with "+NameGet(PId)+".") endfunction private function InitUnAlly takes nothing returns nothing local string S = GetEventPlayerChatString() //undeclared function NewDialog and cannot convert null to integer local Dialog D = NewDialog() local Info I = Info.create() local player P = GetTriggerPlayer() local integer PId = GetIdFromName(SubString(S, StringLength(UNALLYPHRASESTART)+1, StringLength(S))) call D.SetMessage(NameGet(GetPlayerId(P))+" wants to unally with you.|nDo you accept?") call D.AddButton("|cffffcc00Y|res", HK_Y) call D.AddButton("|cffffcc00N|ro", HK_N) call D.AddAction(function Clicked) set I.AllyInit = P set I.AllyAccept = Player(PId) set I.Flag = false set Infos[integer(D)] = I call D.Show(I.AllyAccept) call DisplayTimedTextToPlayer(I.AllyInit, XOFF, YOFF, DISPLAYTIME, "You have requested to unally with "+NameGet(PId)+".") endfunction private function AllyConditions takes nothing returns boolean //undeclared function substring return StringCase(Substring(GetEventPlayerChatString(), 0, StringLength(ALLYPHRASESTART)), false) == ALLYPHRASESTART endfunction private function UnAllyConditions takes nothing returns boolean //undeclared function substring return StringCase(Substring(GetEventPlayerChatString(), 0, StringLength(UNALLYPHRASESTART)), false) == UNALLYPHRASESTART endfunction private function Init takes nothing returns nothing local integer I = -1 loop set I = I+1 exitwhen I>11 call TriggerRegisterPlayerChatEvent(Ally, Player(I), ALLYPHRASESTART, false) call TriggerRegisterPlayerChatEvent(UnAlly, Player(I), UNALLYPHRASESTART, false) endloop call TriggerAddCondition(Ally, Condition(function AllyConditions)) call TriggerAddAction(Ally, function InitAlly) call TriggerAddCondition(UnAlly, Condition(function UnAllyConditions)) call TriggerAddAction(UnAlly, function InitUnAlly) endfunction endlibrary |
