Jump to content
Sign in to follow this  
Muadjin

Make unit stop immediatly and delete all waypoints!

Recommended Posts

Hi,

On a trigger activation I pass in an npc into the below function : [pvt_patrol] execVM "Deletewaypoints.sqf";

I want the npc to stop immediatly without finishing his current waypoint(first while lloop) and delete every waypoint (second while loop)

What is wrong with my first do/while loop ? Is there any other way to make him stop immediatly and delete his waypoints ?

I 'm totaly new to scripting, so this prolly is a silly question, any help is appreciated tho.

// bot is the npc object I pass in the function
_bot = _this select 0;
_i = 0;

// Iterate over all the waypoints and set the position of each to the current pos of _bot
// so the npc stops moving immediatly -> NOT WORKING
while {_i<(count(waypoints _bot))} do 
{		
_wp = ((waypoints _bot) select _i);
_wp setWPPos [(getPos _bot),0];
_i=_i+1;
//sleep 0.125;			
}
// Delete all the waypoints
while {(count(waypoints _bot))>0} do 
{
deletewaypoint ((waypoints _bot) select 0);			
}

Share this post


Link to post
Share on other sites

Not tested but should work.... maybe instead of the setWaypointPosition you might need to use addWaypoint and add a waypoint here....since they've all been deleted. I'm not sure.

while {(count (waypoints _bot)) > 0} do {
deleteWaypoint ((waypoints _bot) select 1);
sleep 0.01;
};

[group _bot, 0] setWaypointPosition [position _bot, 0];

Share this post


Link to post
Share on other sites

Just tested and it doesn't work.

Why would you setWaypointPosition after you deleted all the waypoints ?

And deleting is not really the problem, and I don't want to add a waypoint(yet), I just want the npc to stop immediatly on his route to the current waypoint.

In this case the npc runs all the way to the current waypoint THEN stops and deletes all his waypoints instead of doing it exactly when the trigger activates and the script has run.

Share this post


Link to post
Share on other sites

Well the setWaypointPosition or addWaypoint was to give him a waypoint at his current position....which should stop him.

You can always use doStop.

Share this post


Link to post
Share on other sites

Thanks, DoStop does make him stop... tho now I can't seem to move him anymore, weird..

perhaps its a little to drastic, cuz it does seem to say in the comments that the unit doesn't move untill the group is engaging an enemy or he gets a command from group leader or something.. all very confusing :)

_bot = _this select 0;
_play =_this select 1;
_i = 0;

doStop _bot;

while {(count(waypoints _bot))>0} do 
{
deletewaypoint ((waypoints _bot) select 0);	

}
_bot doMove (postion _play);
//[group _bot, 0] addWaypoint [position _play, 0];

Edited by Muadjin

Share this post


Link to post
Share on other sites
Look up doMove see if that helps.

Thats what I just did in the previous code example mate :)

Tho it doesn't seem to work either.

The unit just stops and turns around now and then

Share this post


Link to post
Share on other sites
Thats what I just did in the previous code example mate :)

Ahhh... Sorry for missing that in your post. I'll see what I can knock up in the editor for you and post a demo mission.

EDIT:-

OK...this stops him when he enters the trigger. Waypoints are deleted... he is given a waypoint at his current location and he stops dead in his tracks. Demo here.

_bot = _this select 0;

_group  = group _bot;

while {(count (waypoints _group)) > 1} do {
deleteWaypoint ((waypoints _group) select 1);
sleep 0.01;
};

_wp = _group addWaypoint [position _bot, 0];

What do you want him to do after he stops?

Edited by twirly
Added stuff

Share this post


Link to post
Share on other sites

Yay, I just found another good tip on the wiki of deletewaypoint wich seems to work fine. http://community.bistudio.com/wiki/deleteWaypoint :

The path of the unit is calculated by the waypoints present at start, and the unit will continue according to the original waypoints even if you delete them by using this command.
to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group. A new group will start without any preset waypoints so you can start setting new WPs all over again.

Solution :

// bot is the npc object I pass in the function
_bot = _this select 0;
// player object
_play =_this select 1;
_i = 0;

_botGrp = createGroup WEST;
{[_x] joinSilent _bot2Grp} forEach (units _bot);
_botGrp addWaypoint [getPos _play, 1];

Share this post


Link to post
Share on other sites

**I posted a reply twice already as I had found another solution, but they don't seem to reach the thread :s

Thank you for taking the time tho, I 'll look into your solution**

Just got the script working.

http://community.bistudio.com/wiki/deleteWaypoint :

The path of the unit is calculated by the waypoints present at start, and the unit will continue according to the original waypoints even if you delete them by using this command.

to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group.

Solution :

// bot is the npc object I pass in the function
_bot = _this select 0;
// player object
_play =_this select 1;
_i = 0;

_bot2Grp = createGroup WEST;
{[_x] joinSilent _bot2Grp} forEach (units _bot);
_bot2Grp addWaypoint [getPos _play, 1];

Share this post


Link to post
Share on other sites

testqsdqsd

---------- Post added at 12:01 AM ---------- Previous post was Yesterday at 11:54 PM ----------

Thanks this works, but I 've told you that already in pm :) since I wasn't allowed to post on the forums anymore.

Since I 've noticed I can post again, I 'll post here what I 've found as well :

http://community.bistudio.com/wiki/deleteWaypoint :

The path of the unit is calculated by the waypoints present at start, and the unit will continue according to the original waypoints even if you delete them by using this command.

to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group.

Solution :

// bot is the npc object I pass in the function
_bot = _this select 0;
// player object
_play =_this select 1;
_i = 0;


_bot2Grp = createGroup WEST;
{[_x] joinSilent _bot2Grp} forEach (units _bot);
_bot2Grp addWaypoint [getPos _play, 1];

Share this post


Link to post
Share on other sites

Cool thing mate...if that works then go for it. Good to have another method and good of you to post it for all to see.

Share this post


Link to post
Share on other sites

The probable downer with my method is that there is a new group made, wich might affect the rest of the logic ( internal group names differ or something?!) .. but that is out of my reach to even start thinkin about that atm :)

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  

×