Jump to content

Photo

Find form in cell

cell form find object

  • Please log in to reply
6 replies to this topic

#1
VampireMonkey

VampireMonkey

    Enthusiast

  • Supporter
  • PipPip
  • 242 posts

I'm working on a script that needs to find one specific form in a cell and then make it a objectreference.

 

While !Stop && !(Target.GetBaseObject() == OldBaseObject)


Target = Game.FindRandomReferenceOfTypeFromRef(OldBaseObject, CenterMarker, 51200) as ObjectReference


if !Target
Stop = True
endif
EndWhile

ObjectReference Property Target Auto
ObjectReference Property CenterMarker Auto
Form OldBaseObject

this is a small part of the bigger script, but this is the part i'm having trouble with, it can find the objecttype, but the "!(Target.GetBaseObject() == OldBaseObject)" doesn't seem to work at all

it will look for the type of object that "OldBaseObject" is pointing to, but not the specific baseobject/form.

 

 



#2
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,987 posts

What I noticed was that OldBaseObject was defined as a form but had no value.  Target was given a property value but you were trying to overwrite it.  So the script was looking for an empty form and trying to shove an empty reference into a already defined value.  Its confused.  I know I was.   :tongue:

 

After reading how the function FindRandomReferenceOfTypeFromRef works on the CK wiki, I put this together.  It is heavily commented and hopefully understood.  I do not know if it works. May be worth a try, at any rate.

Spoiler


#3
VampireMonkey

VampireMonkey

    Enthusiast

  • Supporter
  • PipPip
  • 242 posts

i didn't explain myself properly, here's the whole function:

Function ChangeBanners()
BannerCount = 9 ;there are 9 banners in the cell that has to be replaced

Stop = False

;finds the current banner in the cell
OldBannerRef = Game.FindClosestReferenceOfAnyTypeInListFromRef(BannerList, CustomMarker_BannerColorPicker, 51200) as ObjectReference
;get the base form of that banner
OldBanner = OldBannerRef.GetBaseObject() as Form
;get the type in int
OldBannerType = OldBanner.GetType() as Int

;get the banner form at this location in this list (selectbanner is defined in another part of this script)
NewBanner = BannerList.GetAt(SelectBanner)


;start loop of finding banners, placing them and of deleting old onces.
While (BannerCount != 0) && !Stop
BannerCount -= 1

;makes sure that the target is none, so the script doesn't jump over the selecting of new banner part
Target = None


;loop to find a new banner, "!(Target.GetBaseObject() == OldBanner)" doesn't seem to work, i have tried multiple ways of coding this part
While !Stop && !(Target.GetBaseObject() == OldBanner)

;find a banner of type, max distance of 51200 from a marker i have in the cell
Target = Game.FindRandomReferenceOfTypeFromRef(OldBanner, CustomMarker_BannerColorPicker, 51200) as ObjectReference


;if by any means the script can't find anything it needs to stop
if !Target
Stop = True
endif
EndWhile


;gets the position and angle of the oldbanner
float floatX = Target.GetPositionX()
float floatY = Target.GetPositionY()
float floatZ = Target.GetPositionZ()
float floatAngleX = Target.GetAngleX()
float floatAngleY = Target.GetAngleY()
float floatAngleZ = Target.GetAngleZ()

;places a new banner on the oldbanner
ObjectReference BannerRef = Target.PlaceAtMe(NewBanner).SetPosition(floatX, floatY, floatZ)
BannerRef.SetAngle(floatAngleX, floatAngleY, floatAngleZ)

;disables and deletes the oldbanner
Target.DisableNoWait()
Target.Delete()

EndWhile
;this should now happen 9 times on all 9 banners in the cell
EndFunction


;----------------------------------------------------------
; Banners
;----------------------------------------------------------


Bool Stop

int SelectBanner
int BannerCount
int OldBannerType

Form NewBanner
Form OldBanner

FormList Property BannerList Auto

ObjectReference Property Target Auto
ObjectReference Property OldBannerRef Auto
ObjectReference Property CustomMarker_BannerColorPicker Auto

The idea is that; there are banners i want to change in a cell, i want to change between a list of banners, i got the list part working. the part i don't have working is the part i mentioned in the OP,

how it is suppose to work is that, the script looks for the current banner in the cell and marks that form of banner.

then the script tries to get the banner in the cell as an objectreference, the problem is that the "!(Target.GetBaseObject() == OldBanner)" part doesn't work, it doesn't exclude banners that aren't of the new banner form, it is only suppose to pick oldbanners and not the new one it just replaced.

 



#4
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,987 posts

Have you tried adding any debug.trace statements to see what is being returned by what and being compared by what?  Perhaps by doing that you can see what is going on and have a better idea on how to tweak the script.



#5
VampireMonkey

VampireMonkey

    Enthusiast

  • Supporter
  • PipPip
  • 242 posts

i have, it finds the type, but it doesn't care which form the object is, i can't get it to differentiate between a newbanner and an oldbanner.



#6
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,987 posts

Maybe you need to rethink the process?

 

Looks like you have 9 known references that you want to change at user discretion.  The user selects a design/color and all 9 change to that.  Why not pre-place each design/color and link them to their own enable parent xmarker?  Enable/Disable each marker as needed.

 

I suppose that might get too crowded should you have quite a few designs...

 

Any possibility of doing it that is more fixed and less random?  Perhaps additional FormLists or maybe Arrays with while loops to cycle through the entries?



#7
VampireMonkey

VampireMonkey

    Enthusiast

  • Supporter
  • PipPip
  • 242 posts

i have thought of that, but that would be an absolute last resort, there are over 36 different banners, placing them at each different location, would result in 324banners in total, which is unpractical.







Also tagged with one or more of these keywords: cell, form, find, object

Page loaded in: 1.039 seconds