OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: dalton on 11 Feb 2004, 14:17:07

Title: distance?
Post by: dalton on 11 Feb 2004, 14:17:07
i want the player to add an action when he is a certain distance away

what i did was this:

? (_player1 distance vehicle)<3:[] exec "script.sqs"

then in my otha script i did:

_player1 addaction ["actionname", "script.sqs"

so which 1 is wrong with it and how can i fix it?
Title: Re:distance?
Post by: Marvin on 11 Feb 2004, 14:20:35
You have to put

? (_player1 distance vehicle <3):[] exec "script.sqs"

I hope that there are defined unit _player1
and there are vehicle named vehicle


and the other myst have after addaction ] - mayby they disapiere when you copy!
Title: Re:distance?
Post by: PsyWarrior on 11 Feb 2004, 15:01:23
Greetings,

What is _player1 supposed to be, exactly?

the "_" is only really used in .sqs scripts to define local variables as Marvin says, if you call your player "player1" and the vehicle "vehicle", then all you need is this:

In a script:

Code: [Select]
#loop
? player1 distance vehicle <3: player addAction ["Action", "script.sqs"]
~0.1
goto "loop"

In a trigger:

Condition: player1 distance vehicle <3
On Activation: player1 addAction ["Action", "script.sqs"]

That should solve your problems.

Regards,

-Supreme Commander PsyWarrior
-Psychic Productions
Title: Re:distance?
Post by: gundernak on 11 Feb 2004, 15:12:52
I would suggest you to not use these names as 'vehicle','ammo'...these are syntaxes in the scripting language of OFP, and you can have difficulties because of it.

Always add a number or something to these names....for example: 'vehicle01'
Title: Re:distance?
Post by: Marvin on 11 Feb 2004, 15:17:28
then i suggest you to not use _player1, byt use player1 without _
of course if you named your player - player1

This is jyst a way to do this in scripting!
Title: Re:distance?
Post by: dalton on 12 Feb 2004, 00:39:43
thnx guys

but the only problem is that when i use the loop, the action keeps coming up and coming up and it neva stops

o yea btw my vehicle is not named vehicle but if i give out the name then it will ruin the surprise for what the mission is about
Title: Re:distance?
Post by: Marvin on 12 Feb 2004, 09:56:09
Then Use like PsyWarrior sad! Use the trigers to activate script, and you can crate onother striger, when the player is 3 meters from car then on activation you can add removeaction!
Title: Re:distance?
Post by: Chris Death on 12 Feb 2004, 10:14:32
errm - why don't you simply add the action to the vehicle?

That way you wouldn't need your scripts, and it would still
be the very same effect as what you want to do by these
scripts.

Once the player gets close (let's say 3 - 5 meters) to the
vehicle, the action of the vehicle will appear.

~S~ CD
Title: Re:distance?
Post by: PsyWarrior on 12 Feb 2004, 14:04:06
Greetings,

If you are scripting an action, you have to make sure that you remove the action when the condition is no longer true. So a solution would be:

#loop
? player1 distance vehicle1 <3: goto "engage"
~0.1
goto "loop"

#engage
action = player1 addAction ["Action", "script.sqs"]

#disLoop
? player1 distance vehicle1 > 3: player1 removeAction action; goto "loop"
~0.1
goto "loop"

gundernak, note addition of '1' to vehicle...point taken, my mistake...  ::)

Or you could do as Chris says - I temporarily forgot that you can see the actions of other units when you get close to them.  :-[

-Supr. Cmdr. PsyWarrior
-Psychic Productions