Jump to content

Scripting Help?


blazeda59

Recommended Posts

I'm working on a little script to teleport the player to a random location but I'm having some trouble figuring out how to teleport once the game has chosen the location. This is what I have so far.

Form Property LocationList const auto
Form Property LocationMarker Auto Const

Event OnEffectStart(Actor akTarget, Actor akCaster)

		Form myLocationList
		FormList myFormList = LocationList as FormList

		if myFormList
			; picks location from list at random
			int pickIndex = Utility.RandomInt(0, myFormList.GetSize()-1)
			myLocationList = myFormList.GetAt(pickIndex)
		endif

EndEvent

Scripting is not my strong point but as far as I can tell that is selecting a random location from my list. But now how do I place my marker there and then move the player to the marker?? Any help would be great.

Link to comment
Share on other sites

Well the only way I can think of off the top of my head would be to have an array of ObjectReferences (these represent your random locations) and once you've selected an index you'd simple move the player to that object e.g:

Scriptname RandomLocation extends Actor
;Note that it doesn't matter what it extends you just need an event to throw a trigger

ObjectReference[] property xMarkLocations auto ;Should stick to using only xMarkers/COCMarkers

Event OnActivate(ObjectReference akActionRef)
     if akActionRef == Game.getPlayer()
          (Game.getPlayer()).moveTo(getRandomLocation())
     endif
endEvent

ObjectReference Function getRandomLocation()
     return xMarkLocations[Utility.RandomInt(0,xMarkLocations.length-1)]
endFunction
Link to comment
Share on other sites

Thanks for your reply. I think I get what your doing there. Like I said scripting is not really my thing but I was hoping to get it to just select a location from a list rather than having to go around placing new markers everywhere I want the player to teleport too. I was looking at both the Artillery and WorkshopObject scripts for reference as the WorkshopObject script uses the same method to create furniture markers and then load random idle animations from a FormList to play. The artillery script also places markers for the targeting so I know I can do it the way I want. It has something to do with the ObjectReferences defined in those scripts but I'm not sure how it does it because I get lost reading code.

Link to comment
Share on other sites

Nah formlist are much better than objectreference arrays, as you can make them inside the CK they have an infinite maxlength and can be shared easily.

 
FormList Property LocationMarkers Auto Const ;should contain only contain placed markers 

Event OnEffectStart(Actor akTarget, Actor akCaster)
        Objectreference targetposmarker
        If (LocationMarkers.size() == 0) 
             debug.traceandbox("critical: no locations given")
             return
        endif
        targetposmarker = LocationMarkers.getat(Utility.RandomInt(0,LocationMarkers.size() -1)) as Objectreference
        If (targetposmarker ==  None)
             debug.traceandbox("critical: location not valid")
             return
        endif
        (Game.getPlayer()).moveTo(targetposmarker)
EndEvent
Edited by ubuntufreakdragon
Link to comment
Share on other sites

Thanks for clearing that up after changing "Size" to "GetSize" everything is working now but I have a new problem. I still have to go around and either place new XMarkers or use existing ones for the location. Which is sort of what I'm trying to avoid. Ideally I'd like to use the games location markers as the locations and then place an XMarker using the script at them that the player will then move to. Sort of the way the artillery gets it target from the smoke grenade. I've tried a few things but cant get the script to find the locations to place the marker now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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