Determining Player Location

Post » Tue Jun 19, 2012 12:00 am

Hi guys, I'm messing around with Papyrus right now - what a welcome change! I'm lost as to locations, however, and am having no luck finding a list or way to go about it.

Essentially what I wish to do is determine if a player is in a certain hold. Such as Haafinger, Winterhold or Whiterun Hold. I understand that I must use something similar to this:
function mPlayerLocation()    if Game.GetPlayer.GetLocation() == "Haafinger"        ...    endifendfunction
However, I am at a total loss as to all this "LocType[x]" stuff. There seems to be no list to go to, and I've seen LocTypeInn, LocTypeDungeon, and other such uses. Maybe I'm just on the wrong track.

Another question, in a script I looked at it, the author used a LocationAlias that was not the name of the quest's alias.
LocationAlias Property Alias_Location Auto ; the alias's name is Location
Why is adding an Alias_ prefix acceptable?

Thanks guys, hopefully this will clear up a lot of the confusion I'm having in regards to aliases and how they're used, along with the primary concern here.
User avatar
butterfly
 
Posts: 3467
Joined: Wed Aug 16, 2006 8:20 pm

Post » Tue Jun 19, 2012 1:06 am

Hmm, I'd love to know this too. How strange.
User avatar
Jah Allen
 
Posts: 3444
Joined: Wed Jan 24, 2007 2:09 am

Post » Tue Jun 19, 2012 7:59 am

Look at an example from the wiki page (http://www.creationkit.com/GetLocation_-_LocationAlias):
Location myHouseLocation = Alias_MyHouse.GetLocation()

See any difference between it and your script? Right. As you can see in a Syntax field:
Location Function GetLocation() native
GetLocation returns a Location type data. In your script however it would have to be a string (because it's between quotation marks).

Also this is an alias script.

And the third thing is that you try to create a new function which you do in a wrong way... and you probably even didn't intend to do at all. Here you can see how it should be done: http://www.creationkit.com/Function_Reference.

That's how a frame of your script would look like.

Spoiler
ScriptName YourName extends AliasLocation Property CurrentLocation  AutoEvent OnNotSure; I think that only OnInit works with LocationAlias Scripts    ;Here goes whatever you would doEndEvent


HOWEVER it doesn't seem posible to get player's location using this method. Instead you should use http://www.creationkit.com/GetCurrentLocation_-_ObjectReference which is an ObjectReference script function. In other words it will work with objects and actors instead of aliases.

Scriptname PlayerLocationScriptWhatever extends ObjectReferenceLocation Property Haafinger  AutoEvent OnDontKnow    if Game.GetPlayer().GetCurrentLocation() == Haafinger        ;do whatever    endifEndEvent

Maybe a simpler way to do this would be to use an http://www.creationkit.com/IsLoaded_-_Location function. But anyway, you can see a couple of things here. You don't attempt to create a function. You use an Event. And you declare a Property which you later use. This property is of a correct type (Location) so it will work with output from the function.


About Aliases, that's how you use them in scripts. I think Properties named Alias_HereNameOfAlias are even automatically created. It's just to specify that this is, in fact... well, an Alias.

Also, why wouldn't it be acceptable? A Property doesn't have to be called the same as the thing it refers to.


I'm sure this post of mine is especially messy... But I hope it will help you.
User avatar
Riky Carrasco
 
Posts: 3429
Joined: Tue Nov 06, 2007 12:17 am

Post » Tue Jun 19, 2012 5:02 am

Thanks, Universal. I tried writing this again and have made... Some progress. I'm really lost as to how to check locations, since going by the location's ID is not working.
Location Property playerloc autoEvent onInit()    while true        playerloc = Game.GetPlayer().GetCurrentLocation()        ;WhiterunHoldLocation        ;WinterholdHoldLocation        ;HaafingerHoldLocation        if(playerloc.IsSameLocation(WhiterunHoldLocation))            Debug.Notification("You're in the hold of Whiterun")        endif    endwhileEndEvent
If I can't use the ID of the location, must I create an alias? If so, would I also need to create another LocationAlias for the player's location? This all seems like such a pain, an overcomplication of things.

If not, how can I declare a Location variable that stores WhiterunHoldLocation?
User avatar
Felix Walde
 
Posts: 3333
Joined: Sat Jun 02, 2007 4:50 pm

Post » Mon Jun 18, 2012 10:36 pm

You need to read up about properties on the wiki. Papyrus didn't have knowledge of anything outside the language, you must assign properties to scripts in the CK.
User avatar
Brooks Hardison
 
Posts: 3410
Joined: Fri Sep 07, 2007 3:14 am

Post » Tue Jun 19, 2012 5:40 am

What AliTheLord said.

This is easy once you get it. Properties are viariable linked to objects' IDs. Aliases are a bit similar but they only work with quests. Every time you try to use a Form in your script you have to declare a Property, while you declare Aliases only for quest targets, locations used in your quests and actors that participate in them.

I think your script should look like this.
Spoiler
Scriptname GettingLocLocation Property playerloc  autoLocation Property WhiterunHoldLocation  autoLocation Property WinterholdHoldLocation  autoLocation Property HaafingerHoldLocation  autoEvent onInit()    while true        playerloc = Game.GetPlayer().GetCurrentLocation()        if(playerloc.IsSameLocation(WhiterunHoldLocation))            Debug.Notification("You're in the hold of Whiterun")        endif        ; Here we can do this in a different way. Playerloc is a Location Property and WhiterunHoldLocation is a Location Property.        ; We can compare them directly, like this:        if playerloc == WhiterunHoldLocation            Debug.Notification("You're in the hold of Whiterun")        endif        ; Also if you would just want to tell the player where he is, you could do that:        Debug.MessageBox(playerloc)        ; You can use Properties like other variables.    endwhileEndEvent
Then you would have to attach actual IDs to those Properties.

I'm not sure about whis "while" loop. From what I've seen already this kind of thing was mostly done by an update.
Spoiler
Event OnInit()Registerforupdate(60); The update will happen every 60 seconds.EndEventEvent OnUpdate; Here you can check something, like location.EndEvent

Script of this kind should be, I think, attached to a quest that is "Start Game Enables" so it runs all the time.

But like Ali said, you'd be best reading scripting tutorials on creationkit.com. It will take only a short time but show you most of the stuff you need to know.
User avatar
Melis Hristina
 
Posts: 3509
Joined: Sat Jun 17, 2006 10:36 pm


Return to V - Skyrim