Jump to content

Creating zone "ingame"


McBack
Followers 0

Recommended Posts

If you dont want to read all difficult source code, try this:

1) Put this code into author functions (after line -- #Author Functions Go Here# --)

function GetNewZone(refPt, name, distance, direction, radius)
 local dist = Wherigo.Distance(distance, 'm') 
 local newZp = Wherigo.TranslatePoint(refPt, dist, direction)	  
 dist = Wherigo.Distance(radius, 'm') 
 local pts = {
Wherigo.TranslatePoint(newZp, dist, 45), 
Wherigo.TranslatePoint(newZp, dist, 135),
Wherigo.TranslatePoint(newZp, dist, 225),
Wherigo.TranslatePoint(newZp, dist, 315),
 }
 local tempz = Wherigo.Zone{
Cartridge = cartCWGhideandseek,
Name = name,
OutOfRangeName = "",
InRangeName = "",		
Description = [[]],
Visible = false,
Active = false,
DistanceRange = Wherigo.Distance(-1, "m"),
ShowObjects = "OnEnter",
ProximityRange = Wherigo.Distance(10, "m"),
AllowSetPositionTo = false,
Points = pts,
 }
 return tempz
end

 

Now if you want to create a zone on the fly, use this syntax:

GetNewZone(refPt, name, distance, direction, radius) where:

refPt - reference position from where you want to measure distance

name - name of the zone

distance - from reference position to center of zone (in metres)

direction - azimuth from reference position to center of new zone

radius - radius of a new zone

 

For example, if you want to create a zone 50 meter from your current position to the west, with name NewZone and radius 10 metres:

GetNewZone(Player.ObjectLocation, "NewZone", 50, 270, 10)

 

You cant write this code in official builder, use some simple text editor like notepad or for example PSPad with LUA syntax highlight.

Link to comment
You cant write this code in official builder, use some simple text editor like notepad or for example PSPad with LUA syntax highlight.

It will shortly (next release, I hope) be possible to do all this in Earwigo, without having to "abandon" the builder. There will be a CodeMirror box with Lua syntax highlighting for your "Author Script" function definitions, and you can already put the call in any event handler with a "Lua statement" element.

Link to comment

I see some others have contributed as well. I also saw me2d09 supplied a slightly modified function I created in Whack-A-Lackey. I've had my lunch break at work and was able to finish what I wanted to write, though I didn't get a chance to test my modifications. Now, if only I can get back to editing that announcement post I began writing on Sunday...

 

-----------

 

Here are some specific functions from Whack-A-Lackey and how to use them. I made the functions generic enough so people can copy and paste them into their own cartridges with limited modification.

 

First, you will need to create a ZonePoint within your game. A ZonePoint stores a coordinate pair and altitude. You will need to know and manipulate ZonePoints if you want to create zones.

ReferencePoint = ZonePoint(40.07888,10.79488, 0)

 

I had to edit this function to get it to do more along the line of what you wanted (I didn't test it). It will take in a ZonePoint (where you want to place the new zone), the zone's name, and a number representing the distance radius between the zone's center and edge. While the function will generate a square zone, you should be able to see how to edit it to make it more circular.

function GetNewZone(newZp, name, radius)
 -- create a list of zone points
 local dist = Wherigo.Distance(radius, 'ft')
 local pts = {
Wherigo.TranslatePoint(newZp, dist, 45),
Wherigo.TranslatePoint(newZp, dist, 135),
Wherigo.TranslatePoint(newZp, dist, 225),
Wherigo.TranslatePoint(newZp, dist, 315),
 }


 -- create the new zone
 local tempz = Wherigo.Zone{
Cartridge = cartWhackALackey,
Name = name,
OutOfRangeName = "",
InRangeName = "",		
Description = [[]],
Visible = false,
Active = false,
DistanceRange = Wherigo.Distance(-1, "feet"),
ShowObjects = "OnEnter",
ProximityRange = Wherigo.Distance(30, "feet"),
AllowSetPositionTo = false,
Points = pts,
 }

 return tempz
end

 

So far, I have shown you how to create a zone in-game. Now, let's focus on changing a zone's size.

 

One thing you'll have to remember is that a zone will not be updated without making it inactive. A good rule of thumb is to make it inactive, then change its properties, then make it active again. This will force the Player to recalculate and display the zone in its new location and/or dimensions. If you also plan to toggle the visibility, make sure to activate the zone before toggling visibility. The Garmin Oregon does not process a visibility change if the zone is inactive. This is in fact a Garmin problem, so Groundspeak can't do anything to correct it.

 

To change a zone's dimensions, you'll have to replace its Points collection. I haven't tested this code, but I bet you could make a function based off the above code.

function ResizeZone(z, radius)
 -- create a list of zone points
 local dist = Wherigo.Distance(radius, 'ft')
 local pts = {
Wherigo.TranslatePoint(z.OriginalPoint, dist, 45),
Wherigo.TranslatePoint(z.OriginalPoint, dist, 135),
Wherigo.TranslatePoint(z.OriginalPoint, dist, 225),
Wherigo.TranslatePoint(z.OriginalPoint, dist, 315),
 }

 -- resize the zone
 z.Points = pts
end

 

The trouble with the above code is I don't know if it'll work with dynamically-created zones. My previous function didn't set the zone's OriginalPoint property. Instead, all you have is a zone's Points collection. You don't know the zone's shape (you might, but a generic function won't), so you won't know its center point. You'll have to play around with it.

Link to comment

The Garmin Oregon does not process a visibility change if the zone is inactive. This is in fact a Garmin problem, so Groundspeak can't do anything to correct it.

Ack! I wish I had read that earlier...I just published my 1st Wherigo and I have Activate before Visible when I'm shutting down a zone which has already been completed.

 

Like I've always said, never get v1.0 of anything! Looks like I've got a quick re-build to submit before anyone downloads my cartridge.

 

Thanks for sharing that bit of knowledge.

Link to comment
Ack! I wish I had read that earlier...I just published my 1st Wherigo and I have Activate before Visible when I'm shutting down a zone which has already been completed.

If you're shutting down a zone, it shouldn't matter (because you're making the zone inactive). However, following this logic, the zone will be visible the next time it is activated. So, in this respect, you should be fine.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Followers 0
×
×
  • Create New...