Jump to content
Sign in to follow this  
Tand3rsson

What is wrong with my random movement script?

Recommended Posts

Hi!

For some reason, my script isn't working (due to my limited skill). What I want it to do it: A vehicle moves to one of 7 random markers, when the vehicle is within say 50 m of this marker, it once again gets a random destination from these 7 random markers. And so on. For all eternity.

I have placed a vehicle in ediot, named it patrol1, and then 7 markers (mark1, mark2, mark3 and so on).

In a radio trigger (alpha) i have put: [mark1, mark2, mark3, mark4, mark5, mark6, mark7, patrol] exec "move.sqf" (and move.sqf is in my mission folder)

Move.sqf:

_markOne = _this select 0;
_markTwo = _this select 1;
_markThree = _this select 2;
_markFour = _this select 3;
_markFive = _this select 4;
_markSix = _this select 5;
_markSeven = _this select 6;
_patrol = _this select 8;

goto "Posis"

#Posis

_sel = floor random 7;
_pos = switch (_sel) do

{
case 0: {_markOne};
case 1: {_markTwo};
case 2: {_markThree};
       case 3: {_markFour};
       case 4: {_markFive};
       case 5: {_markSix};
       case 6: {_markSeven};
};

_patrol doMove (getMarkerPos "_pos");


#Update

?(_patrol distance _pos < 50):goto "Posis"

~2
goto "Update"

Anyone able to point out what I have done wrong, and how to correct this?

Thanks in advance!

Share this post


Link to post
Share on other sites

The file should be named move.sqs not move.sqf

exec move.sqs -

sorry not really up on how sqs works.

quick way of doing it using sqf...not tested!

set radio to - execvm "move sqf".

make sure a function module is on map.

move.sqf

_movetomarker = ["mark1", "mark2", "mark3", "mark4", "mark5", "mark6", "mark7"] call BIS_fnc_selectRandom; 
patrol1 domove getmarkerpos _movetomarker; 

Share this post


Link to post
Share on other sites

Tested now, no sucess. And also, if that would work, I would have to have a script for every unit that i want to do the patrol?

Well, ok, it sort of worked. He did select one destination, and moved there. However, after that he isnt chosing a new one :P And I do not wanna have to press radio alfa over and over again to make him move. I was thinking of putting the code in his init. Sorry if i was unclear, but the radio trigger was only for testing purpose

Still, thank you so much for taking time to answer!

Share this post


Link to post
Share on other sites

Place this in the init of any vehicle you want to patrol.

veh = [this] execvm "move.sqf";

move.sqf

_caller = _this select 0;
while (alive _caller) do 
{
_movetomarker = ["mark1", "mark2", "mark3", "mark4", "mark5", "mark6", "mark7"] call BIS_fnc_selectRandom; 
_caller domove getmarkerpos _movetomarker;
waituntil {(_caller distance (getmarkerpos _markertomove) < 10);}; 
};

if domove doesnt work - try move

Share this post


Link to post
Share on other sites

Hi again!

For some reason, now it isn't working at all. Tried changing your

_caller doMove getmarkerpos _movetomarker; to many different variants:

_caller move getmarkerpos _movetomarker;

_caller doMove (getMarkerPos _movetomarker);

But nothing, now he is not moving at all :S

Share this post


Link to post
Share on other sites

my bad - poor scripting on my behalf and rushing through it lol.

so this works - make sure you have a functions module on the map

waituntil {!isnil "bis_fnc_init"};
_caller = _this select 0;
while {alive _caller} do 
{
_movetomarker = ["mark1", "mark2", "mark3", "mark4"] call BIS_fnc_selectRandom; 
(driver _caller) move getmarkerpos _movetomarker;
waituntil {(_caller distance (getmarkerpos _movetomarker) < 10);}; 
};

Share this post


Link to post
Share on other sites

Yepp :) Works lika a charm for me to! Thanks alot for taking time to help me!:) i appreciate it!

Do you have any tips for script learning:P? Obiously I have some knowledge of sqs. but nowadays its sqfs right, and most of it is greek to me :)

Once again, thanks!

Share this post


Link to post
Share on other sites

no prob - unfortunately just need to take your time and have a go at everything. That way you will have a good chance of working it out yourself. If all else fails - Search forums - post if no joy searching, someone will know the answer - wealth of knowledge and there is always someone who can make your script more efficient and shorter.

Feel free to PM me if you have any further questions.

Share this post


Link to post
Share on other sites

Hi.

Here is my "path" from sqs to sqf:

http://forums.bistudio.com/showthread.php?126492-SQS-to-SQF-quot-translation-quot-request-field-of-view-scanner

As you can see it depends mostly on your perseverance and persistence. There is no "quick and easy" substitute for self-learning through practice. Step by step is best way, I think. Differences however aren't so big between sqs and sqf...

Shortly described here: SQS_to_SQF_conversion

But you will probably discover also other diferences.

BTW of course is possible sqf code, that doing same without function module. As for initial sqs: perhaps also _pos shouldn't be in quotes? Not sure at the moment. Never used markers for such purposes, I prefer eg empty triggers instead, as they are objects, so you can do more interesting things with them.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×