Home   Help Search Login Register  

Author Topic: Some script waypoint problems  (Read 3204 times)

0 Members and 2 Guests are viewing this topic.

Offline Anders Greenman

  • Members
  • *
Some script waypoint problems
« on: 11 Feb 2007, 00:04:00 »
I'm making a civil world with several buses driving around picking up people an I want to do it all with scripts.
But, I'm having a problem. I want the bus to go to several locations using road objects ID, but he ignores all the commands except the last one.
I want it to drive to each of them in turn. Here's my script so far (yes, I'm a noob):

busOne doMove getPos (object 1650)

This makes the bus drive to the object named 1650, but when I add another "waypoint" like this, it ignores the first one and drives directly to the other:

busOne doMove getPos (object 1650)
busOne doMove getPos (object 4741)

Any ideas?
And if anybody has any experience with "bus picking up people" I would like to know 8)



Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some script waypoint problems
« Reply #1 on: 11 Feb 2007, 00:23:37 »
busOne doMove getPos (object 1650)
~2
@unitReady driver busOne
busOne doMove getPos (object 4741)
~2
@unitReady driver busOne

EDIT: and another way
busOne doMove getPos (object 1650)
~2
@((object 1650) distance busOne) < 10
busOne doMove getPos (object 4741)
~2
@((object 4741) distance busOne) < 10

Offline Anders Greenman

  • Members
  • *
Re: Some script waypoint problems
« Reply #2 on: 11 Feb 2007, 12:08:36 »
Thanks! It worked great :)

Edit: I'd choose the last one as it made the bus able to stand more obstacles.
But, I have another problem. It wont listen to the behaviour and speed script.
I've tried several methods including unitReady after the command, changed the turn from first to last, with or without unit_ aso.

;WP1 ******************************************
LMOneDriver doMove getPos (object 57852)
~1
@((object 57852) distance LMOneDriver) < 10

unit_LMOneDriver setBehaviour "SAFE"
unit_LMOneDriver setSpeedMode "FULL"

And is there any way to make the bus having the same speed and behaviour through out all the scripts with just one in the top/bottom?
Since the script is so long it would be practical if I didn't need to write the same thing 100 times.

Edit2: Another problem, what's the equivalent script for "Transport Unload"? :dry:





« Last Edit: 11 Feb 2007, 17:08:14 by Anders Greenman »

Offline schuler

  • Contributing Member
  • **
Re: Some script waypoint problems
« Reply #3 on: 12 Feb 2007, 10:36:54 »
Quote
And is there any way to make the bus having the same speed and behaviour through out all the scripts with just one in the top/bottom?
 
Quote
It wont listen to the behaviour and speed script.
i think FULL is a bit much , use NORMAL and put it in the Init.sqs,,,, shouldnt have to go 100 times. ''MIGHT help'' but looks like one of those try over and over things, you probably know this but just trying to help :) cheers or maybe Mandoble might have a loop you can use in it,,,,?

EDIT;;; ive played with this a bit, use a unit_ SetSkill 1 in the Init aswell ,,,  and change the ~2 to ~4 ,,,,i dont know why but its working for me.

Quote
equivalent script for "Transport Unload"?
cmd="EJECT"; "_x action [cmd,busOne]" foreach units dudesnameshere,,, play around with that
« Last Edit: 12 Feb 2007, 11:13:19 by schuler »
Semper Fi

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some script waypoint problems
« Reply #4 on: 12 Feb 2007, 11:28:22 »
setSpeedMode "FULL" does not affect really the speed of the bus, it is intended to make the unit move without waiting for other units to re-join (when there are several units in the same group). I asume you have lots of waypoints, so, better than just having a very long spagetti type script you may try the following:

There is a waypoints array, each member of this array is another small array with [waypoint position, seconds to wait after reaching the waypoint, action to perform after reaching the waypoint]

For this example, action 0 does nothing, then you have action 1 and action 2, you may add more if needed.

To execute it [busname]exec"script.sqs"

Code: [Select]
_bus = _this select 0
_buswps = [[getPos (object 57852), 4, 0],[getPos (object 3852), 10, 0], [getPos (object 7852), 0, 0], [getPos (object 57852), 4, 1]]

_count = count _buswps
_busdriver = driver _bus
_busdriver setBehaviour "CARELESS"

#repeatwps
_i = 0

#wp
_newwp = _buswps select _i
_busdriver doMove (_newwp select 0)
~2
@((unitReady _busdriver) || (!alive _busdriver) || (!canMove _bus))
?!alive _busdriver: hint "Driver dead":exit
?!canMove _bus: hint "Bus ruined":exit

;If there is some acction attached to the current waypoint, execute it
?(_newwp select 2) == 1:goto "action1"
?(_newwp select 2) == 2:goto "action2"
#returnactions

;Now the script waits as many seconds as indicated for the current waypoint
~(_newwp select 1)

_i = _i + 1
?_i < _count :goto "wp"

;All waypoints completed, now the script will repeat all of them again
goto "repeatwps"

#action1
;insert here code for waypoints with action 1
hint "Bus Action 1"
goto "returnactions"

#action2
;insert here code for waypoints with action 2
hint "Bus Action 2"
;Example to unload cargo
_crew = crew _bus
{if (_x != _busdriver) then {unassignVehicle _x, _x action ["getout", _bus]}} forEach _crew
goto "returnactions"

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Some script waypoint problems
« Reply #5 on: 12 Feb 2007, 11:57:48 »
a quick tip for script markers which use sequential numbers:

usually scripts begin with something like

Code: [Select]
?_variable == 1: goto "marker_1"
?_variable == 2: goto "marker_2"
?_variable == 3: goto "marker_3"
etc...

a much quicker way would be to use the format command to create the goto string, like this:

Code: [Select]
_jump = format ["marker_%1", _variable]
goto _jump

Offline schuler

  • Contributing Member
  • **
Re: Some script waypoint problems
« Reply #6 on: 12 Feb 2007, 12:18:19 »
@ Madoble i do see that "CARELESS" makes a difference, sorta gives the unit blinders like a race horse , but it seems to me that FULL  does have a problem with the men boarding , 'as far as', if the men are not placed right, the bus likes to run though yards and hit houses , sum thing is still not right , i'll test this over and over again, im using malden and adding different getpos numbers.

@ Anders Greenman ,, what island or mod are you using?
Semper Fi

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some script waypoint problems
« Reply #7 on: 12 Feb 2007, 13:19:11 »
schuller, if you want anyone to board the bus before it starts moving again, just make sure everyone is onboard before giving a new move command to the driver. The group boarding the bus doesnt need to be the driver's group, just the opposite. You would need a waiting condition like this after ordering the passengers to get in:

(Assuming you have a group of passengers boarding it)
Code: [Select]
@({_x in bus} count units group passenger) == (count units group passenger)
BTW, while they board the bus, if the bus moves, some of them may result killed, so checking the number of passengers in group is equal to number of alive units in passenger group would be even better.

Offline schuler

  • Contributing Member
  • **
Re: Some script waypoint problems
« Reply #8 on: 12 Feb 2007, 13:49:12 »
Mandoble,  ok yes this is one of the probs ''no one likes to get ran over by a bus !!!!!'' i know this is Anders Greenman post, but ive been trying to use these scripts myself. although iam now thinking of making a mission based on '' attack of the killer bus ''.
 The script you made here is working better, but iam wondering should i play with the ~2 and the < 10?,, could it make a difference?
based on the game engine and island!?!?

Quote
busOne doMove getPos (object 1650)
~2
@((object 1650) distance busOne) < 10
busOne doMove getPos (object 4741)
~2
@((object 4741) distance busOne) < 10

@ bedges thanks, thats next   :good:
edit iam now making an assignVehicle script with a guy1,guy2 ~1 guy3,guy4 ~2 and busOne how do i put that into snytax? do you think this might work and solve some probs, i just want it to look good! i dont need isAlive, just something simple and so i understand the script, sorry for the hastles!!!! iam just trying to learn some more scripting,,
 at the end of the intro there will be a badguy fire ["put", "pipebomb"] and a badguy action ["touchoff"] then the gameplay starts.
 iam trying to get an everyday sort of life or people going to work from morning to after noon , ''might use ''skiptime'' so it looks more like a movie,,,, ive got the cam_ stuff down, its just the scripting
« Last Edit: 12 Feb 2007, 14:31:43 by schuler »
Semper Fi

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some script waypoint problems
« Reply #9 on: 12 Feb 2007, 17:59:00 »
Once you give a doMove command OFP engine tries to resolve a valid path between current position and destination. But to calculate a valid path OFP uses a timer, if no path is found in time, the unit will not move. You cannot check for readyness of the unit just after issuing the doMove command, because the unit is still ready, so waiting two seconds is needed here. Then the unit may move or not (path calculation timed out). If the path calculation times out, the unit will be ready again, but certainly the bus will not be closer than 10m to the destination point, so the condition to step to next waypoint will never accomplish. Take that info into consideration for your script, make sure there is not an enourmous distance between a waypoint and the next one, so that OFP can resolve a path without problems.

Offline schuler

  • Contributing Member
  • **
Re: Some script waypoint problems
« Reply #10 on: 13 Feb 2007, 04:11:32 »
Quote
OFP engine tries to resolve a valid path between current position and destination
ok then , its starting to make more sence to me. its not easy but its fun! i'll change the bus route aswell
Semper Fi

Offline Anders Greenman

  • Members
  • *
Re: Some script waypoint problems
« Reply #11 on: 13 Feb 2007, 17:16:12 »
First, thanks to you all!! :D

Mandoble: I'm working with the script now, but as it is a little bit on the edge of my knowledge, it takes some time!
Underlines before local variables has never worked for me. The computer thinks it is a part of the name. Guess it is due to some lack in my knowledge as I have only tried it with my own scripts?

bedges: I'l try that one, but first I need to learn a bit more..

schuler: I'm using Nogova and no mod. My favorite island when it comes to missions including civillians!

Offline schuler

  • Contributing Member
  • **
Re: Some script waypoint problems
« Reply #12 on: 14 Feb 2007, 07:00:16 »
 
Quote
Underlines before local variables has never worked for me
Anders are you using Chris's ofp script editor?  http://www.chenderman.com/CHOFPSE.htm if not, its a big help!!
Semper Fi

Offline Anders Greenman

  • Members
  • *
Re: Some script waypoint problems
« Reply #13 on: 15 Feb 2007, 15:58:11 »
Yes, I'm using it and It's great! Like the colour changings wich makes the whole script easier to read.
And I got the underlines to work now too.

 
Okey, another problem. I am working with the third action , to make the bus load passengers, but the problem is that i can't get several passengers to load into the bus at the same time. It works with one though.

Quote
; Here, I want something like _p = [p1, p2, p3, p4, p5, p6..], but it doesn't work! (think the error was type array, expected group,object). 
_p = p1
_bus = LMOne

hint "LMOne loading"
"_p assignAsCargo _bus" forEach units _p
[_p] ordergetin true
unitReady _p

exit

And this is the main script who execute the thing:

#action3
;picks up people if they are present
if ((_bus distance _p) < 10) then {[_p] exec "LMOneP.sqs"}
goto "returnactions"[/quote]

So, I want the passengers to load the bus if it's present and they do, but it does only work with one.
And they can't be grouped as they're going to be spread all over the map.

Well, any ideas? 8)




Another edit, another happening. This time, it's relatively good :)
I found a solution to my problem, but there is a drawback. The script needed to do this has become very long!
I tried it anyway and it worked for me so I won't trouble looking for anything else in the nearest future.
Despite my temporary solution though, I would like other alternatives. Guess shorting the script prevents lag too?
Here is the whole script so far:



Quote
; *****************************************************
; ** Operation Flashpoint Script File
; *****************************************************


_bus = _this select 0
_buswps = [[getPos (object 57852), 0, 0], [getPos (object 57853), 0, 0], [getPos (object 26140), 0, 0], [getPos (object 6369), 0, 0], [getMarkerPos "Lipany2", 5, 2], [getMarkerPos "Lipany1", 5, 3], [getPos (object 173563), 0, 0], [getPos (object 6366), 0, 0], [getPos (object 5285), 0, 0], [getPos (object 5295), 0, 0], [getPos (object 5424), 0, 0], [getPos (object 5457), 0, 0], [getPos (object 5481), 0, 0], [getMarkerPos "Modrava1", 5, 2], [getMarkerPos "Modrava2", 5, 3], [getPos (object 5300), 0, 0], [getPos (object 2694), 0, 1]]

_count = count _buswps
_busdriver = driver _bus
_busdriver setBehaviour "CARELESS"

#repeatwps
_i = 0

#wp
_newwp = _buswps select _i
_busdriver doMove (_newwp select 0)
~2
@((unitReady _busdriver) || (!alive _busdriver) || (!canMove _bus))
?!alive _busdriver: hint "Driver dead":exit
?!canMove _bus: hint "Bus ruined":exit

;If there is some acction attached to the current waypoint, execute it
?(_newwp select 2) == 1:goto "action1"
?(_newwp select 2) == 2:goto "action2"
?(_newwp select 2) == 3:goto "action3"
#returnactions

;Now the script waits as many seconds as indicated for the current waypoint
~(_newwp select 1)

_i = _i + 1
?_i < _count :goto "wp"

;All waypoints completed, now the script will repeat all of them again
goto "repeatwps"

#action1
;insert here code for waypoints with action 1
hint "LMOne on cycling"
goto "returnactions"

#action2
;insert here code for waypoints with action 2
hint "LMOne unLoading"
;Example to unload cargo
_crew = crew _bus
{if (_x != _busdriver) then {unassignVehicle _x, _x action ["getout", _bus]}} forEach _crew
goto "returnactions"

;***********************************************************************************************
;************************************ Big action ***********************************************
;***********************************************************************************************


#action3
; Passenger loading script
hint "LMOne loading"
; Units
_p1 = p1
_p2 = p2
_p3 = p3
_p4 = p4
_p5 = p5
_p6 = p6
_p7 = p7
_p8 = p8
_p9 = p9
; ****************************'



;Picks up people if they are present. Each have their own part. p1c equals "passenger one check"

; Check if there is anyone at the station

#p1c
; p1
if ((_bus distance _p1) < 30) then {goto "p1"}

#p2c
; p2
if ((_bus distance _p2) < 10) then {goto "p2"}

#p3c
; p3
if ((_bus distance _p3) < 10) then {goto "p3"}

#p4c
; p4
if ((_bus distance _p4) < 10) then {goto "p4"}

#p5c
; p4
if ((_bus distance _p5) < 10) then {goto "p5"}

#p6c
; p6
if ((_bus distance _p6) < 10) then {goto "p6"}

#p7c
; p7
if ((_bus distance _p7) < 10) then {goto "p7"}

#p8c
; p8
if ((_bus distance _p8) < 10) then {goto "p8"}

#p9c
; p9
if ((_bus distance _p9) < 10) then {goto "p9"}
goto "returnactions"

; Commands :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:

#p1
"_p1 assignAsCargo _bus" forEach units _p1
[_p1] ordergetin true
unitReady _p1
goto "p2c"

; **********************************************

#p2
"_p2 assignAsCargo _bus" forEach units _p2
[_p2] ordergetin true
unitReady _p2
goto "p3c"

; ***********************************************

#p3
"_p3 assignAsCargo _bus" forEach units _p3
[_p3] ordergetin true
unitReady _p3
goto "p4c"

; ***********************************************

#p4
"_p4 assignAsCargo _bus" forEach units _p4
[_p4] ordergetin true
unitReady _p4
goto "p5c"

; ***********************************************

#p5
"_p5 assignAsCargo _bus" forEach units _p5
[_p5] ordergetin true
unitReady _p5
goto "p6c"

; ***********************************************

#p6
"_p6 assignAsCargo _bus" forEach units _p6
[_p6] ordergetin true
unitReady _p6
goto "p7c"

; ***********************************************

#p7
"_p7 assignAsCargo _bus" forEach units _p7
[_p7] ordergetin true
unitReady _p7
goto "p8c"

; ***********************************************

#p8
"_p8 assignAsCargo _bus" forEach units _p8
[_p8] ordergetin true
unitReady _p8
goto "p9c"

; ***********************************************

#p9
"_p9 assignAsCargo _bus" forEach units _p9
[_p9] ordergetin true
unitReady _p9
hint "LMOne fully loaded"
goto "returnactions"

; ***********************************************

 


I've now added 16 new waypoints and edited the _p - _bus radius. And a fourth action, script fueling. Didn't bother sending it to a gas station. Buses are always troublesome when it comes to refueling the hard way.

My second question in this post, I'm having so many waypoints that it isn't enough room for them in one line. But I haven't yet figured out any clever way to do this.
Basically, my problem is how to make another line in my wp script without screwing things up.
« Last Edit: 16 Feb 2007, 23:35:08 by Anders Greenman »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some script waypoint problems
« Reply #14 on: 18 Feb 2007, 10:15:15 »
Code: [Select]
#action3
; Passenger loading section
hint "LMOne loading"
_ps = [p1, p2, p3, p4, p5, p6]
_nps = count _ps

;Here we'll store passengers actively mounting each time
_loading = []

_i = 0
#check_p
_p = _ps select _i
;If passenger is in any vehicle, or distance to bus > 10, or not alive, we dont care about him
?(vehicle _p != _p) || ((_p distance _bus) > 30) || (!alive _p): goto "skipmount"
_p assignAsCargo _bus
~1
[_p] ordergetin true
~1
_loading = _loading + [_p]
#skipmount
_i = _i + 1
?_ i < _nps:goto "check_p"

_tomount = count _loading
?_tomount  == 0: goto "returnactions"
~1
@({unitReady _x} count _loading) == _tomount
goto "returnactions"


About your second question:
Code: [Select]
_buswps = [[getPos (object 57852), 0, 0], [getPos (object 57853), 0, 0], [getPos (object 26140), 0, 0], [getPos (object 6369), 0, 0]]
_buswps = _buswps + [[getMarkerPos "Lipany2", 5, 2], [getMarkerPos "Lipany1", 5, 3], [getPos (object 173563), 0, 0]]
_buswps = _buswps + [[getPos (object 6366), 0, 0], [getPos (object 5285), 0, 0], [getPos (object 5295), 0, 0]]
...

is that what you mean with single lines?