Home   Help Search Login Register  

Author Topic: Creating Waypoints by script  (Read 2465 times)

0 Members and 1 Guest are viewing this topic.

Offline Meatball0311

  • Members
  • *
Creating Waypoints by script
« on: 18 Nov 2007, 08:26:40 »
Situation - man named "ins14"
Marker - marker named "ins14pos1"

I dont understand what I am doing wrong?

;declaring variables
_ins14 = ins14
_ins14gp = ins14gp

;using getmarkerpos
_ins14pos1 = getMarkerPos "ins14pos1"

;using addWaypoint
_wp114 = _ins14gp addWaypoint [_ins14pos1, 0]

;setting waypoint type
_wp114 setWaypointType "MOVE"

;using setCurrentWaypoint
_ins14gp setCurrentWaypoint [_ins14gp, 0]

*EDIT*
I also tried this.  I did not get any errors, but my man still did not move to waypoint?

ins14gp addWaypoint [getMarkerPos "ins14pos1", 0]
[ins14gp, 0] setWaypointType "MOVE"
ins14gp setCurrentWaypoint [ins14gp, 0]

How do I get the unit to move to the waypoint?  And what is the waypoints name?

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: Creating Waypoints by script
« Reply #1 on: 18 Nov 2007, 08:53:54 »
i think main prob wud b da setcurrentwaypoint

wat u shud do is

_ins14gp setCurrentWaypoint _wp114

as da [_ins14gp, 0] is da 1st wp in da groups array of waypoints (note dat each group is created automaticly w/ a WP on its starting position...) in case u know dat ur created waypoint is da 1st 1 u wud write _ins14gp setCurrentWaypoint [_ins14gp, 1]

also make sure dat ins14gp is da group of da unit ;)

btw. in OFPEC its enough 2 ask da question in da forum... no need 2 also PM som1 bout it (even tho dat u will get answer if u pm :P)

LCD OUT
« Last Edit: 18 Nov 2007, 08:56:15 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Creating Waypoints by script
« Reply #2 on: 18 Nov 2007, 10:40:30 »
What LCD says is correct: It's alright to use AddWaypoint [groupName, 0] <- that will create the "next" waypoint regardless. However, as he says, the first waypoint created (that you can see in the editor) is waypoint # 1, not 0. 0 is always automatically created on the starting point of the group (try making a waypoint that's se to "Always Visible" and you'll see a crossed over waypoint underneath your group).

Secondly, I believe your waypoint might not be entirely set up properly: try adding another line which declares the statements of the WP:

Code: [Select]
_wp setWayPointStatements ["true", "this sidechat ""Waypoint reached, moving on."""];
Also, when you create a waypoint, it will return the name of the waypoint in its correct format (_wp114 = addWaypoint etc. _wp114 = your created waypoint) -> So you don't need to guess what order the waypoint is in and so forth. Just use the code piece that LCD showed you there :) Although by all accounts, it shouldn't be necessary, since if this really IS the first waypoint created, it'll automatically be the currently selected WP anyway!

Good luck!

Wolfrug out.

 
"When 900 years YOU reach, look as good you will not!"

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: Creating Waypoints by script
« Reply #3 on: 18 Nov 2007, 11:16:36 »
as much as i know.... da setwaypointstatement is not realy neccesary... :P

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Meatball0311

  • Members
  • *
Re: Creating Waypoints by script
« Reply #4 on: 18 Nov 2007, 15:43:00 »
Ok, I am still having the problem that the unit is not moving to the waypoint

ins14gp = group this (in the init field of unit named ins14)

ins14pos1 = name of marker placed on map

_ins14 = ins14
_ins14gp = ins14gp
_wp114 = _ins14gp addWaypoint [getMarkerPos "ins14pos1", 1]
_ins14gp setCurrentWaypoint _wp114
[_wp114, 1] setWaypointType "MOVE"

**I donot get any errors, but unit is not moving to waypoint _wp114**

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: Creating Waypoints by script
« Reply #5 on: 18 Nov 2007, 15:49:20 »
Quote
[_wp114, 1] setWaypointType "MOVE"

dis is wrong.... dis line shud b

_wp114 setWaypointType "MOVE"

if den it doesnt work den bug is not in da script... its somin w/ da unit... either its not called like dat (typo in da name... somin like dat) or u got a stop command on da unit... 2 make sure deres a wp... group urself 2 da unit and check if waypoint apears... :D

Quote
_ins14gp addWaypoint [getMarkerPos "ins14pos1", 1]

dis line can stay like it was b4 (_ins14gp addWaypoint [getMarkerPos "ins14pos1", 0]) as da number after da position indicates placement radius (so it will b within 1 meter of da position....)  watever number dats dere will b fine...

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Meatball0311

  • Members
  • *
Re: Creating Waypoints by script
« Reply #6 on: 18 Nov 2007, 16:47:06 »
_ins14 = ins14
_ins14gp = ins14gp
_wp114 = _ins14gp addWaypoint [getMarkerPos "ins14pos1", 1]
_ins14gp setCurrentWaypoint _wp114
_wp114 setWaypointType "MOVE"

**I get no errors and the unit does not move to waypoint.  I grouped myself to the unit and I can hear him giving the orders to move to waypoint and the waypoint appears, but still no movement.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: Creating Waypoints by script
« Reply #7 on: 18 Nov 2007, 17:10:41 »
strange...

dis is time 2 chekc ur mission and scripts... 2 make sure u didnt accidently gave hime a stop order... like

dostop unit
or
unit stop true

or watever...

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Meatball0311

  • Members
  • *
Re: Creating Waypoints by script
« Reply #8 on: 18 Nov 2007, 17:52:21 »
Ok I got it to work.  The problem was for some reason they were not moving because they were placed behind a wall.  So I moved them and they now go to the waypoint.

_ins14 = ins14
_ins14gp = ins14gp
_wp114 = _ins14gp addWaypoint [getMarkerPos "ins14pos1", 0]
[ins14gp, 1] setWPPos getMarkerPos "ins14pos1"
_ins14gp setCurrentWaypoint _wp114
_wp114 setWaypointType "SAD"

**EDIT**
How do you give him a second waypoint to go to AFTER they complete the first one?

« Last Edit: 19 Nov 2007, 15:26:25 by Meatball »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Creating Waypoints by script
« Reply #9 on: 19 Nov 2007, 20:12:29 »
That's the thing with waypoints  ;) they go in sequence, one after another. Just add two waypoints to him right away (using addWaypoint). So the code would look like:

Code: [Select]
_ins14 = ins14
_ins14gp = ins14gp
_wp114 = _ins14gp addWaypoint [getMarkerPos "ins14pos1", 0]
_wp115 = _ins14gp addWaypoint [getMarerPos "ins14pos2", 0]
[ins14gp, 1] setWPPos getMarkerPos "ins14pos1"
_ins14gp setCurrentWaypoint _wp114
_wp114 setWaypointType "SAD"

Note however you have a lot of unnecessary code up there. To make it cleaner, all you need is:

Code: [Select]
_ins14 = ins14
_ins14gp = ins14gp
_wp114 = _ins14gp addWaypoint [getMarkerPos "ins14pos1", 0]
_wp115 = _ins14gp addWaypoint [getMarkerPos "ins14pos2", 0]
_wp114 setWaypointType "SAD"
_wp115 setWaypointType "MOVE"

Since the WP will already BE at the marker's position, and the first waypoint is already the naturally selected one :) Unless you have a lot of other WPs, of course, that go ahead.

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Meatball0311

  • Members
  • *
Re: Creating Waypoints by script
« Reply #10 on: 19 Nov 2007, 21:28:00 »
 :good: Thanks for all of the advice.  It works great!!

Offline Trexian

  • Members
  • *
Re: Creating Waypoints by script
« Reply #11 on: 27 Nov 2007, 15:18:55 »
On offshoot of this issue. :)

I'd like to have the AI set up some waypoints between himself and marker 1, then between himself and marker 2.  (Eventually, this will cycle among 4 markers, 1-2-3-4-1-2-3-4....)

I've worked through how to set a waypoint at a marker, and even within a radius of a marker.  I can also get the direction from the AI to the marker.  I'd like to set a waypoint about 20m in front of the AI toward the marker, then as he reaches that one, set another one about 20m beyond that.  Alternatively, set a fixed number (let's say 6) waypoints between the AI and the marker.  Then, when he reaches the marker delete those waypoints and set another set of waypoints to the next marker.

Any help would be greatly appreciated! :D

Edit:  Oof.

Going back about 20 years to trig.

Plotted out what I think will be the way to go.

Pseudo-codishly:

getPos AI
getPos Marker
subtract marker position select 0 from AI position select 0 yields the difference in X (xdiff)
subtract marker position select 1 from AI position select 1 yields the difference in y (ydiff)
(that gives me the two sides of the right triangle that describes the relative location)
xdiff + ydiff = total diff (absolute value?)
xdiff / total diff = percentage of change component in x (percX)
ydiff / total diff = percentage of change component in y (percY)
(let's say I want to put a waypoint about 20m away)
new x difference = 20 * percX (newXdiff)
new y difference = 20 * percy (newYdiff)
(voila)
new marker/waypoint location = [AI position + newXdiff, AI position + newYdiff, (same z or 0, depending)]

Hey - look!  No hypotenuses or old Greek guys named Pythagorus! :)

Does that at all resemble something that might actually work?

Edit2:

Only thing I'm worried about, but now that I think about it I'm not worried about it, is if there's a negative someplace in the equation.  I think the "position" type variable is purely grid - x,y,z will always be positive in that formulation.  It is when you get into relative distances/positions, it thinks in terms of +/-x/y/z.

Edit3:

Shit.  (Oops - not sure if I can cuss here.) :)

I just realized that if my AI is at a coordinate position GREATER than the marker - in either plane - I will have to allow for negative values/subtraction.  I saw some scripts to help with angles (by Mandoble maybe?) - so I guess I need those?

Or something like figure out which x/y is greater, set a add/subtract variable, then have it trigger the appropriate operations?

NextEdit:

FUUUUCk.  (Ooops - sorry again if I can't cuss.)

Resorted to pen and paper. :)

The subtracting the x/y positions will take care of the pos/neg value, in that THAT difference will have the proper modifier.

So, I think I just need a couple conditionals.

if xdiff < 0
newX = AI position - newXdiff
  else
newX = AI position + newXdiff

if ydiff < 0
newY = AI position - newYdiff
  else
newY = AI position + newYdiff

new marker/waypoint location = [newX, newY, z]

Ok, now to test.  Once I get rid of the headache. :D

NextEdit:
Yeah, headaches still here.

But, thought of another headache.  How can I tell if the marker/waypoint is inside a building such that it will interfere with the AI pathfinding.  I'm thinking some variation of nearestobject within a small radius - like 5m - will be able to tell me.  Plus, to allow for seamless transitions (or close) I was hoping to have a check and set a new waypoint once the guy is within 5m or so, and if he is, then set delete that waypoint/marker and set a new one.  So maybe the pathfinding will take care of itself?

Yeah yeah yeah.  Won't know until I try, eh? :D
« Last Edit: 27 Nov 2007, 19:46:11 by Trexian »
Sic semper tyrannosauro.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Creating Waypoints by script
« Reply #12 on: 27 Nov 2007, 19:51:05 »
Would it not be more efficient to just work all this out on paper or on your machine till you solve it, rather than have a long rambling conversation with yourself?


 ::)


Planck
I know a little about a lot, and a lot about a little.

Offline Trexian

  • Members
  • *
Re: Creating Waypoints by script
« Reply #13 on: 27 Nov 2007, 19:59:33 »
:D

I was kinda hoping that this would NOT be a conversation with myself.  (BTW, thanks for posting!)

I'm really not good at this stuff, so any ideas/suggestions/observations/help would be much appreciated.

Plus, I hate it when I search for something and the last post of a thread is:
Quote
Got it working, thanks.

With no explanation as to what the person changed to get it working. ;)  This way, anyone searching for help on a similar problem will likely find either the answer or at least the thread.   :cool2:

(Oh, and other dude got dinked a bit for responding to himself, so I thought editing was likely a better approach.) :)
(And thanks for not getting mad at the cussing.)  :thumbs: :)
« Last Edit: 27 Nov 2007, 20:03:30 by Trexian »
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Creating Waypoints by script
« Reply #14 on: 30 Nov 2007, 06:00:11 »
Soz for self-replying. :)

Got it figured out, mostly.

Just need to loop it with however many destination markers you want.

Code: [Select]

hint "trig script";
sleep 1;

// get starting positions
markPos = getMarkerPos "dest1";
aiPos = getPos this;

// get plane differences
xCoordMark = markPos select 0;
xCoordAI = aiPos select 0;
xDiff = xCoordMark - xCoordAI;

yCoordMark = markPos select 1;
yCoordAI = aiPos select 1;
yDiff = yCoordMark - yCoordAI;

// get total diff and perc
totDiff = abs xDiff + abs yDiff;
xPerc = abs XDiff / totDiff;
yPerc = abs yDiff / totDiff;

// make coords for waypoint
xNewDiff = 20 * xPerc;
yNewDiff = 20 * yPerc;

// conditions for negative values

if (xDiff < 0) then
{
  xNew = xCoordAI - xNewDiff;
};

if (yDiff < 0) then
{
  yNew = yCoordAI - yNewDiff;
};

if (xDiff > 0) then
{
  xNew = xCoordAI + xNewDiff;
};

if (yDiff > 0) then
{
  yNew = yCoordAI + yNewDiff;
};

//newMarkPos = [xNew, yNew, 0];
//curMarker = createMarker [NewMarker, newMarkPos];

// mark new waypoint
cone1 = "RoadCone" createVehicle [xNew, yNew, 0];

//this Move newMarkPos;
this Move [xNew, yNew, 0];

waitUntil {unitready this};

//done
sleep 1;

hint "trig script done";

Input/suggestions/critiques/complaints welcome.  Oh yeah - I know I didn't use underscores in the variables.  Was lazy.  For real work, someone would have to use, for instance, _xDiff and _yDiff.

Along those same lines, the next area I need to learn is local variables so I can have multiple instances of the script running. :)  But, I'll hijack a thread where something like that is the topic. ;)

 :good:
Sic semper tyrannosauro.