Jump to content

Function to detect if Player is in a playerOwned Settlement?


Recommended Posts

I haven't tested it, but it looks as if that function may do the trick. However, if you're actually able to get the workshop reference (through one of the various methods that have been discussed in this thread), I highly recommend that you redo the function yourself. That function gets the location of the ObjectReference passed into the function and uses that to find the workshop reference. Even if we assume that you can get the workshop from the players location anywhere within the settlement, it will save you calling an extra function (efficiency yo).

So basically, put this into a function:

 

Function IsPlayerOwnedWorkshop(WorkshopScript WorkshopRef)
	If (WorkshopRef && WorkshopRef.GetBaseValue(akAV = WorkshopRatings[WorkshopRatingPopulation].ResourceValue) > 0 && TargetRef.IsWithinBuildableArea(akRef = WorkshopRef) && (WorkshopRef.HasKeyword(akKeyword = WorkshopType02) == False || WorkshopRef.OwnedByPlayer))
		Return True
	Else
		Return False
	EndIf
EndFunction 

 



If you do have to rely upon the WorkshopParent IsFriendlyLocation() Function, then you'll be alright most of the time. As I said though, there's a couple settlements such as Somerville Place that has issues with that method.

Also, this method may not work with Home Plate, however, you've said that this isn't an issue.

I'm not sure how reliable DukePatrick's method is, but if it does work, it's less functions to call, so it would be more efficient again. Just from experience I'd imagine that it wouldn't capture the full picture, meaning that there would be some scenarios where it doesn't accurately reflect the players ownership. Workshops unfortunately have a million different scenarios to consider, some of which only become realised once you've released the mod and receive bug reports. I could definitely be wrong, though.

Link to comment
Share on other sites

Hey guys,

 

Thanks for your inputs and help :)

 

I have rapidly tested this "IsFriendlyLocation" bool function from the WorkshopParentScript on a test MagicEffect script:

Actor Property PlayerRef Auto
WorkshopParentScript Property WorkshopParent Auto

Event OnEffectStart(Actor akCaster, Actor akTarget)
	If WorkshopParent.IsFriendlyLocation(PlayerRef as ObjectReference)
		Debug.Notification("This place is FRIENDLY")
	Else
		Debug.Notification("This place is NOT friendly")
	EndIf
EndEvent

Here's the complete function extracted from the WorkshopParentScript - which as KernalsEgg pointed at, may return errors:

Function from the WorkshopParent Script

; returns true if the passed in reference is in a "friendly" location (meaning the buildable area of a friendly settlement)
; * population > 0
; * workshop settlement
; * 1.5 not type02 settlement
bool function IsFriendlyLocation(ObjectReference targetRef)
	Location locationToCheck = targetRef.GetCurrentLocation()
	;debug.trace(self + " IsFriendlyLocation: targetRef=" + targetRef + ", locationToCheck=" + locationToCheck)
	if locationToCheck == NONE
		;debug.trace(self + " IsFriendlyLocation: FALSE")
		return false
	else
		WorkshopScript workshopRef = GetWorkshopFromLocation(locationToCheck)
		if workshopRef && workshopRef.GetBaseValue(WorkshopRatings[WorkshopRatingPopulation].resourceValue) > 0 && targetRef.IsWithinBuildableArea(workshopRef) && ( workshopRef.HasKeyword(WorkshopType02) == false || workshopRef.OwnedByPlayer )
			;debug.trace(self + " IsFriendlyLocation: TRUE")
			return true
		else
			;debug.trace(self + " IsFriendlyLocation: FALSE")
			return false
		endif
	endif
endFunction

Though it would probably work for my purpose anyway, it sometimes returns false positive on ownership. Digging a bit more into the workshopscript, it t would seem that "OwnedByPlayer" can return true as soon as the location has been cleared even though you've never activated the WorkshopBench (thus never got the "ownership" message which then triggers radiant attacks).

 

Some locations (Graygarden for instance in my test, which does not have the WorkshopType02 keyword anyway) will return true on "OwnedByPlayer" and simultaneously false on the Condition Check "LocationHasPlayerOwnedWorkshop".

 

What's interesting for me though is that the WorkshopRatingPopulation will return > 0 when settlers were already in the location, like the robots in Graygarden and that fits my plans, I don't want to limit my objectives to settlements which only have new settlers.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...