Jump to content
Sign in to follow this  
Griffon2-6

Warfare Fast-Travel Logic

Recommended Posts

I've been trying to modify the warfare fast-travel logic. I've spent approximately 12 hours trying to debug this single line of code:

if (sideJoined == East) then {_enemies = Resistance CountSide _livingUnits} else {_enemies = 0};

In essence, I want to check for Resistance troops only if the player is on the East side.

To debug, I've modified the lines like so:

player globalChat Format["sideJoined = %1", Str sideJoined]
if (sideJoined == East) then {_enemies = Resistance CountSide _livingUnits; player globalChat Format["sideJoined = %1", Str sideJoined]} else {_enemies = 0};

This would print "SIDEJOINED = EAST" to the screen twice upon a fasttravel check. Upon finishing the check, I have this line:

player globalChat Format["_enemies: %1, _unsafe: %2", Str _enemies, Str _unsafe]

So that I can check how many enemies have been detected. I've observed the following:

Both lines of "SIDEJOINED = EAST" print to screen, so it obviously is doing the check, and the "then" condition is reached.

However, the value of _enemies always comes up as a blank when converted into a string, UNLESS I initialize it with the value of 0. In that case, _enemies is always 0 regardless of any further assignments like the one shown in the "then" condition.

It seems as if the assignment isn't working, but all I've added to the stock BIS code was the if-then condition, which seems to be working fine. Seeing as how the stock code does work, these two in combination should also work. However, clearly, something's wrong here. Could anybody who's more experienced with scripting shed some light on this?

Here's the entire relevant chunk of code for reference:

#FastTravelSafetyCheck

{DeleteMarkerLocal _x} ForEach _fastTravelMarkers

menuButton = -1

;Check if destination is safe...
_unsafe = false
_checkRange = TOWNCAPTURERANGE * 2
if (_location != _base) then {_unsafe = [_location,sideJoined] Call HasHostileCamp} else {_checkRange = TOWNCAPTURERANGE * 5};

_objects = NearestObjects[_location,[eastSoldierBaseClass,westSoldierBaseClass,resistanceSoldierBaseClass,"Car","Motorcycle","Tank"],_checkRange]
_livingUnits = _objects Call GetLiveUnits
_enemies = 0
player globalChat Format["sideJoined = %1", Str sideJoined]
if (sideJoined == East) then {_enemies = Resistance CountSide _livingUnits; player globalChat Format["sideJoined = %1", Str sideJoined]} else {_enemies = 0};

if (sideJoined == West) then {_enemies = _enemies + (East CountSide _livingUnits)} else {_enemies = _enemies + (West CountSide _livingUnits)};
if (_enemies < 3 && !_unsafe) then {Goto "FastTravelInProgressMarkers";player globalChat Format["_enemies: %1, _unsafe: %2", Str _enemies, Str _unsafe]};

player globalChat Format["_enemies: %1, _unsafe: %2", Str _enemies, Str _unsafe]
_script = [_display DisplayCtrl IDCErrorMessage,1.5,0.75,Localize "STRWFUNSAFEDESTINATION",[1,0,0,1]] Spawn ShowGUIMessage
@ (ScriptDone _script)

Goto "Update"

Thanks for any help in advance.

Share this post


Link to post
Share on other sites

Sorry to bump, but does anybody have any insights on this? Please let me know if there's any other information needed to answer this question.

Share this post


Link to post
Share on other sites

What about:

if (sideJoined == East) then {_enemies = _enemies + (Resistance CountSide _livingUnits)} else {_enemies = 0};

:headscratch:

Share this post


Link to post
Share on other sites

Thanks for the reply. I gave that a try but still no luck. However, the behavior did change - now when I try to travel to a location where I know there are Resistance troops, my debug lines report that _enemies is equal to 0, but when I try to travel back to my base where there shouldn't be any enemies, it sometimes reports one or two enemies.

Is there any reason why what you posted might have worked better than what I had before?

Share this post


Link to post
Share on other sites

Ah.... I think I finally figured it out. Your code is actually working. I have to "declare" the _enemies variable first before using it in a conditional statement. What was confusing me was that even though everything said that the original code should be checking for enemies at the destination, the code was in fact checking the origin for enemies. So I guess the stock BIS code doesn't work properly after all...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×