Jump to content
Sign in to follow this  
snkman

Create a condition with "nearObjects" ?

Recommended Posts

Hi all,

well i just tryed to exec a script after a tank is nearer then 100 meters to the player

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_list = position player nearObjects ["Tank",100]

i tryed to create a condition with it like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (position player nearObjects ["Tank",100]) then {exec "myScript.sqs"}

But so far i was not able to create any condition with nearObjects... So how do i have to use it?

Share this post


Link to post
Share on other sites

I assuming this is in a trigger, if so there's at least a couple of ways you can do this (I think):

If the distance is less than 50 meters you can put something in the expCond line like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">heli_pad distance (nearestObject [heli_pad, "Helicopter"]) < 7;(I use this as a condition in a chopper rearm/refuel script I have)

or if using the nearest objects command try <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">count nearestObjects [player, ["Tank"], 100] >= 1

then in the expActiv line place something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "myScript.sqs"

If there is only one side you want to trigger the script you can also place 'this &&' as well as the above code - where the 'this' is BLUFOR present etc.

Share this post


Link to post
Share on other sites
Hi all,

well i just tryed to exec a script after a tank is nearer then 100 meters to the player

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_list = position player nearObjects ["Tank",100]

i tryed to create a condition with it like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (position player nearObjects ["Tank",100]) then {exec "myScript.sqs"}

But so far i was not able to create any condition with nearObjects... So how do i have to use it?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">position player nearObjects ["Tank",100]

Doesnt return true or false so you cant ask just "if".

I belive this is what you are looking for:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (count (position player nearObjects ["Tank",100])>0) then {exec "myScript.sqs"}

Since it returns an array you want to ask if the amount of objects in the array are greater than 0.

Very nice command btw, didnt know about it before you posted it. Alot better than nearestObject in many situations  smile_o.gif

Share this post


Link to post
Share on other sites

Thanks for the replay Guy's,

InqWiper way is what i was looking for.

IT WORKS! yay.gif

Share this post


Link to post
Share on other sites

Just another question plz.

I have 6 tanks on a map and if a tank is nearer then 100 meters the script will run but it's still running after the tank was destroyed... crazy_o.gif

How can i do this to stop the script after a tank was destroyed and start it again after the next tank is nearer then 100 meters?

If i just put some more in the condition like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((damage "Tank") < 0.8 && (position player nearObjects ["Tank",100])) then {exec "myScript.sqs"}

but i don't know how to tell this to the class.

Share this post


Link to post
Share on other sites
Just another question plz.

I have 6 tanks on a map and if a tank is nearer then 100 meters the script will run but it's still running after the tank was destroyed... crazy_o.gif

How can i do this to stop the script after a tank was destroyed and start it again after the next tank is nearer then 100 meters?

If i just put some more in the condition like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((damage "Tank") < 0.8 && (position player nearObjects ["Tank",100])) then {exec "myScript.sqs"}

but i don't know how to tell this to the class.

To be overinformative

name your tank(s) e.g.

myTank1

myTank2

etc etc

And You need to think of the tank as a object not a class in the "check damage"-case.

like

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(((damage myTank1) < 0.8) && (position player nearObjects ["Tank",100]))then{

exec "myScript.sqs";

};

Share this post


Link to post
Share on other sites

There is no way to create a trigger condition the way you want using nearObjects and checking for object damage.

I would suggest a trigger of 100m radius that is scripted to follow the player. Set trigger to enemy side present repeatedly with condition:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x isKindOf "Tank" && damage _x < 1} forEach thisList

Suppose you have named the trigger myTrigger

Then either in your init.sqs or player init put the following:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">nul = [player,myTrigger] execVM "triggerfollow.sqf"

triggerfollow.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0;

_trigger = _this select 1;

while {TRUE} do

{

_trigger setPos (getPos _unit);

sleep 2;

};

Share this post


Link to post
Share on other sites

Well pretty good idea Mr.Peanut wink_o.gif

I will try it.

Share this post


Link to post
Share on other sites

Hmmm... Have to recant somewhat on my previous post. If trigger is to be stationary then:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">({damage _x < 1} count (position player nearObjects ["Tank",100])) > 0

should work.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_t = (position player nearObjects ["Tank",100]);

IF (EAST countSide _t > 0) THEN {hint "Help!"} ELSE {hint "No threat."};

You can replace EAST with WEST or GUER if needed.

Dead units don't have a side anymore, that should do the trick.

Cheers,

Victor

Share this post


Link to post
Share on other sites
Dead units don't have a side anymore, that should do the trick.

Actually, for some obscure reason they become civilian when dead confused_o.gif

Until the game removes them and they are members of null

Share this post


Link to post
Share on other sites

Hey Victor smile_o.gif

You da man thumbs-up.gif

It works pretty well!

@The_Taurus

Well that's not a problem becouse the script i like to use it in didn't check for civilians. wink_o.gif

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  

×