Home   Help Search Login Register  

Author Topic: One in a billion  (Read 740 times)

0 Members and 1 Guest are viewing this topic.

HuNtA

  • Guest
One in a billion
« on: 02 Sep 2004, 10:05:33 »
....how do I pick out 1 entry from a varible. I know that i can use

_blah = _this select 0, ect.

but I need to have it so a script checks wether an object == the varible

Im making a CoC mines script, and Ive made a varible using a west trigger with activation:

menw = thislist

so all westerners = menw

but then, when Im in a script , I dont know how to check wether the nearestObject is in the varible menw

script:
Code: [Select]
_mine = _this select 0
_menw = menw
_x = getPos _mine select 0
_y = getPos _mine select 1
_z = getPos _mine select 2
#loop
~0.5
_target = nearestObject [(_x),(_y),(_z)]
?(_mine distance _target <1.1):goto "bang"
goto "loop"
#bang
?(_target == _menw):goto "explosion"
goto "loop"
#explosion
_mine setdammage 4
exit
« Last Edit: 02 Sep 2004, 10:06:21 by HuNtA »

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:One in a billion
« Reply #1 on: 02 Sep 2004, 11:16:04 »
first of all, menw isn't a variable, it's an array. So ?(_target == _menw):goto "explosion" won't work, it should give you an error message AFAIK. Tell me if it does.

:beat: *Gets Shot* :beat:

HuNtA

  • Guest
Re:One in a billion
« Reply #2 on: 02 Sep 2004, 12:02:14 »
I know, I sometimes get my words mixed up  ::)

how do I check wether the nearestObject (_target in the script) is in the array

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:One in a billion
« Reply #3 on: 02 Sep 2004, 12:05:20 »
Wait, I have a piece of code somewhere in my archives.

*Go downs to the cellar archives*

A MOUSE!!! AAAAAAAAAAAAAAI!!!!

This is gonna take a little longer. ;)

:beat: *Gets Shot* :beat:

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:One in a billion
« Reply #4 on: 02 Sep 2004, 12:11:24 »
I used this in an abandond project, which I took from another abandonded project. ;D

_dis = 1
{_d=_mine distance _x;if (_d<_dis) then {_dis=_d;_target=_x}} foreach _menw

as you can see by the nice looking code, this line was not made by me. ;D (asked on forum, think it's kuros)

:beat: *Gets Shot* :beat:

« Last Edit: 02 Sep 2004, 12:11:44 by The Real Armstrong »

HuNtA

  • Guest
Re:One in a billion
« Reply #5 on: 02 Sep 2004, 12:11:57 »
ummm, can U kinda explain it to me ???

Offline Zayfod

  • ECP Team
  • *
  • Llama, softest natural fibre in the world.
Re:One in a billion
« Reply #6 on: 02 Sep 2004, 12:21:33 »
To quickly answer your question I believe the "in" command is what you are looking for.

so it would be something like

Code: [Select]
? _target in menw: goto "explosion"
but I wouldnt go about it that way.

Atm you are running a seperate script for each mine and using nearestobject in an imprecise way.

I would do this,

init.sqs
Code: [Select]
mine_boom = PreProcessFile "mine_boom.sqf"
mine_array = []
~2
{_x addeventhandler ["fired", {menw = menw - _this}]} foreach menw
[] exec "mine_scan.sqs"
exit

**********************************************
Add single trigger covering all map

Activation:WEST/EAST/RESISTANCE/ANYBODY (up to you)

***present***

Condition:this

On Activation: menw = thislist
**********************************************

next

**********************************************
In the initialization field of each mine

[this] exec "add_mine_to_array.sqs"; this addeventhandler  ["killed",{mine_array = mine_array - [this]}]

do this to your first mine then simply copy and past that same mine all over your map.
**********************************************

next

mine_boom.sqf

Code: [Select]
private ["_men_array","_mine_array","_check","_i"];
_men_array = _this select 0;
_mine_array = _this select 1;
_check = (count _mine_array)-1;
_i = 0;
while {_i<=_check} do
{
   _mine = _mine_array select _i;
   _i = _i+1;
   if ("_x distance _mine < 1.1" count _men_array > 0) then
   {
      _mine setdammage 4
   }
}

next

mine_scan.sqs
Code: [Select]
~1
#1
if (count mine_array > 0) then  {[menw,mine_array] call mine_boom} else {exit}
~0.5
goto "1"

next

add_mine_to_array.sqs
Code: [Select]
_mine = _this select 0
~random 1
mine_array = mine_array + [_mine]
exit


In this way you will have only one single script that will monitor all your men units and your mines. I made some of the code into SQF function as this will help if you have many units in the map
"I have come here to kick ass and chew bubble gum......an I'm all outta bubble gum!"

HuNtA

  • Guest
Re:One in a billion
« Reply #7 on: 02 Sep 2004, 12:22:33 »
woah. THANKS  ;D