- Joined
- Nov 30, 2007
- Messages
- 1,202
Basically the bug accours when I unally someone that is already unallied to me. The problem is that the function:
isn't running? Because the Word[1] is being carried over to the next time i make a command "-d" # (# = GetPlayer). Even if I type in a error, for example: "-d" without #, the previous Word[1] is being carried over from the last time someone declared war on a enemy.
This debug part should read "(null)" "(null)" "(null)" after every decleration of war, even those that are invalid (already unallied), but it doesn't print anything if I declare war on a enemy. It only works when I declare war on a ally for some reason... Why?
You can find this actionblock under the function: War
*EDIT Solved it by moving the ClearFunction() into the SetWord so it clears before it sets new Words instead.
JASS:
call ClearWords()
This debug part should read "(null)" "(null)" "(null)" after every decleration of war, even those that are invalid (already unallied), but it doesn't print anything if I declare war on a enemy. It only works when I declare war on a ally for some reason... Why?
You can find this actionblock under the function: War
JASS:
call ClearWords() // This and below does not happen when I declare war on somebody im already hostile towards
set i = 0
loop
exitwhen i > 3
call BJDebugMsg(Word[i])
set i = i + 1
endloop
*EDIT Solved it by moving the ClearFunction() into the SetWord so it clears before it sets new Words instead.
JASS:
library Diplomacy initializer init
// Notes:
// * Func ClearWords might be unnecessary
// * The command triggers may be merged into one single event.
// * "and" infusing could be a seperate function?
// call AddAnd takes string s returns string
// *
globals
private constant real DISPLAY_TIME = 10.
private constant integer PENDING_TIME = 30
private boolean array PendingOffer
private integer array PenDexPointer
private integer array PenDexTime
private integer PenDexMax = -1
private string array Faction
private force Active = CreateForce()
private string array Word
private trigger PendingTimer
endglobals
private function SetWords takes string ss returns nothing
local string s = StringCase(ss, false)
local integer i = 1
local integer j = 0
loop
exitwhen i > StringLength(s)
if (SubString(s,i, i+1) == " ") then
set j = j + 1
else
set Word[j] = Word[j] + SubString(s,i,i+1)
endif
set i = i + 1
endloop
if Word[1] == "dark" or Word[1] == "light" then
set Word[1] = Word[1] + " " + Word[2]
set i = 2
loop
exitwhen Word[i+1] == null
set Word[i] = Word[i+1]
set i = i + 1
endloop
endif
endfunction
private function ClearWords takes nothing returns nothing
local integer i = 0
loop
exitwhen Word[i] == null
set Word[i] = null
set i = i + 1
endloop
endfunction
private function GetPlayer takes string s returns integer
if (s == "red" or s == "sparta") then
return 0
elseif (s == "blue" or s == "athens") then
return 1
elseif (s == "teal" or s == "argos") then
return 2
elseif (s == "purple" or s == "thebes") then
return 3
elseif (s == "yellow" or s == "epirus") then
return 4
elseif (s == "orange" or s == "macedon") then
return 5
elseif (s == "green" or s == "thessaly") then
return 6
elseif (s == "pink" or s == "crete") then
return 7
elseif (s == "gray" or s == "grey" or s == "persia") then
return 8
elseif (s == "light blue" or s == "lightblue" or s == "lb" or s == "thrace") then
return 9
elseif (s == "dark green" or s == "darkgreen" or s == "dg" or s == "rhodes") then
return 10
elseif (s == "brown" or s == "troy") then
return 11
elseif (s == "all") then
return 12
endif
return 13
endfunction
private function Reveal takes nothing returns boolean
local integer p
local string array s
local integer array c
local string msg
local integer i = 0
local integer j = 0
local integer m = 0
call SetWords(GetEventPlayerChatString())
set p = GetPlayer(Word[1])
if (IsPlayerInForce(Player(p), Active) == true and GetPlayer(Word[1]) < 12) then
set s[0] = Faction + "\n"
set s[1] = "Allied: "
set s[2] = "Neutral: "
set s[3] = "Hostile: "
set c[1] = 0
set c[2] = 0
set c[3] = 0
loop
exitwhen i > 11
if (IsPlayerInForce(Player(i), Active)) then
if (IsPlayerAlly(Player(p), Player(i)) == true and GetPlayerAlliance(Player(i), Player(p), ALLIANCE_SHARED_VISION) == true and p != i) then
set s[1] = s[1] + Faction[i] + ", "
set c[1] = c[1] + 1
elseif (IsPlayerAlly(Player(p), Player(i)) == true and GetPlayerAlliance(Player(i), Player(p), ALLIANCE_SHARED_VISION) == false) then
set s[2] = s[2] + Faction[i] + ", "
set c[2] = c[2] + 1
elseif (IsPlayerEnemy(Player(p), Player(i))) then
set s[3] = s[3] + Faction[i] + ", "
set c[3] = c[3] + 1
endif
endif
set i = i + 1
endloop
if (c[1] > 0 or c[2] > 0 or c[3] > 0) then
set i = 1
loop
exitwhen i > 3
if (c[i] > 0) then
set s[i] = SubString(s[i], 0, StringLength(s[i]) - 2) + ".\n"
else
set s[i] = ""
endif
set i = i + 1
endloop
set msg = s[0] + s[1] + s[2] + s[3]
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0,0, DISPLAY_TIME, msg)
endif
endif
call ClearWords()
return false
endfunction
private function War takes nothing returns boolean
local integer i = 0
local integer j = 0
local integer p1 = GetPlayerId(GetTriggerPlayer())
local integer p2
local string msg = Faction[p1] + " declares war on "
local boolean display
call SetWords(GetEventPlayerChatString())
set p2 = GetPlayer(Word[1])
if (p2 < 12 and IsPlayerAlly(Player(p1), Player(p2)) == true and Player(p1) != Player(p2)) then // Unally One Player
call SetPlayerAllianceStateBJ(Player(p1), Player(p2), bj_ALLIANCE_UNALLIED)
call SetPlayerAllianceStateBJ(Player(p2), Player(p1), bj_ALLIANCE_UNALLIED)
set msg = msg + Faction[p2] + "."
set display = true
elseif(p2 == 12) then // Unally All Players
loop
exitwhen i > 11
if (IsPlayerAlly(Player(p1), Player(i)) == true and Player(p1) != Player(i)) then
call SetPlayerAllianceStateBJ(Player(p1), Player(i), bj_ALLIANCE_UNALLIED)
call SetPlayerAllianceStateBJ(Player(i), Player(p1), bj_ALLIANCE_UNALLIED)
set msg = msg + Faction[i] + ", "
set j = j + 1
endif
set i = i + 1
endloop
set msg = SubString(msg, 0, StringLength(msg)-2) + "."
if (j > 0) then
set display = true
endif
if (j > 1) then
set i = 0
loop
exitwhen i > StringLength(msg)
if (SubString(msg,i,i+1) == " ") then
set j = i
endif
set i = i + 1
endloop
set msg = SubString(msg, 0, j-1) + " and " + SubString(msg, j+1, StringLength(msg))
endif
endif
if (display == true) then
set i = 0
loop
exitwhen i > 11
call DisplayTimedTextToPlayer(Player(i), 0,0, DISPLAY_TIME, msg)
set i = i + 1
endloop
endif
call ClearWords() // This and below does not happen when I declare war on somebody im already hostile towards
set i = 0
loop
exitwhen i > 3
call BJDebugMsg(Word[i])
set i = i + 1
endloop
return false
endfunction
private function Peace takes nothing returns boolean
call BJDebugMsg("PEACE")
return false
endfunction
private function Ally takes nothing returns boolean
call BJDebugMsg("ALLY")
return false
endfunction
private function Leaves takes nothing returns boolean
call ForceRemovePlayer(Active, GetTriggerPlayer())
return false
endfunction
private function Periodic takes nothing returns boolean
local integer i = 0
if (PenDexMax == -1) then
call DisableTrigger(PendingTimer)
call BJDebugMsg("Disabled")
endif
loop
exitwhen i > PenDexMax
if (PenDexTime[i] == 0) then
//call RemovePenDex(i)
else
set PenDexTime[i] = PenDexTime[i] - 1
endif
set i = i + 1
endloop
return false
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local trigger t4 = CreateTrigger()
local trigger t5 = CreateTrigger()
local integer p = 0
loop
exitwhen p > 11
// if player playing and not computer
call ForceAddPlayer(Active, Player(p))
call TriggerRegisterPlayerChatEvent(t1, Player(p), "-diplomacy", false)
call TriggerRegisterPlayerChatEvent(t1, Player(p), "-diplo", false)
call TriggerRegisterPlayerChatEvent(t1, Player(p), "-d", false)
call TriggerRegisterPlayerChatEvent(t2, Player(p), "-war", false)
call TriggerRegisterPlayerChatEvent(t2, Player(p), "-unally", false)
call TriggerRegisterPlayerChatEvent(t3, Player(p), "-na", false)
call TriggerRegisterPlayerChatEvent(t3, Player(p), "-neutral", false)
call TriggerRegisterPlayerChatEvent(t3, Player(p), "-peace", false)
call TriggerRegisterPlayerChatEvent(t4, Player(p), "-ally", false)
call TriggerRegisterPlayerChatEvent(t4, Player(p), "-alliance", false)
call TriggerRegisterPlayerEventLeave(t5, Player(p))
//endif
set p = p + 1
endloop
call TriggerAddCondition( t1, Condition( function Reveal ))
call TriggerAddCondition( t2, Condition( function War ))
call TriggerAddCondition( t3, Condition( function Peace ))
call TriggerAddCondition( t4, Condition( function Ally ))
call TriggerAddCondition( t5, Condition( function Leaves ))
set t1 = null
set t2 = null
set t3 = null
set t4 = null
set t5 = null
set PendingTimer = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(PendingTimer, 1.00 )
call TriggerAddCondition( PendingTimer, Condition( function Periodic ))
set Faction[0] = "|c00FF0303Sparta|r"
set Faction[1] = "|c000042FFAthens|r"
set Faction[2] = "|c001CE6B9Argos|r"
set Faction[3] = "|c00540081Thebes|r"
set Faction[4] = "|c00FFFC01Epirus|r"
set Faction[5] = "|c00fEBA0EMacedon|r"
set Faction[6] = "|c0020C000Thessaly|r"
set Faction[7] = "|c00E55BB0Crete|r"
set Faction[8] = "|c00959697Persia|r"
set Faction[9] = "|c007EBFF1Thrace|r"
set Faction[10] = "|c00106246Rhodes|r"
set Faction[11] = "|c004E2A04Troy|r"
endfunction
endlibrary
Last edited: