Home   Help Search Login Register  

Author Topic: help with a script  (Read 1878 times)

0 Members and 1 Guest are viewing this topic.

Offline HGuderian

  • Members
  • *
help with a script
« on: 15 Dec 2008, 18:30:56 »
Hi to all!

I'm trin' to make an EH compatible addon wich reproduce rustling sound when the player bot is into (or very near) bushes.

I'm really noob about scripting but I've played around some scripts makin' more than a collage (all the credits goes to the original authors)...so this is it:

Code: [Select]
_Soldier = _this select 0
? ! (_Soldier == player) : exit

_soundRustle  = "Logic" createVehicle (position player)
_soundRustleradius = 0
_soundRustlelist = ["amb_foliage1","amb_foliage2","amb_foliage3","amb_foliage4","amb_foliage5"]

;nearestObjects ["DD_bush01","DD_bush02","Krovi2","Krovi4","Krovi","Krovi_bigest","Krovi_long"]
_nObject = ["DD_bush01","DD_bush02","Krovi2","Krovi4","Krovi","Krovi_bigest","Krovi_long"]

#loop
~1
~ random 5
? ! (alive player) : goto "loop"
_pos = getpos player
_nObject = nearestObject player

_soundRustleselected = (_soundRustlelist select floor(random(count _soundRustlelist)))

? _soundRustleselected == "amb_foliage1" : goto "amb_foliage1"
? _soundRustleselected == "amb_foliage2" : goto "amb_foliage2"
? _soundRustleselected == "amb_foliage3" : goto "amb_foliage3"
? _soundRustleselected == "amb_foliage4" : goto "amb_foliage4"
? _soundRustleselected == "amb_foliage5" : goto "amb_foliage5"

#amb_foliage1
_nObject = nearestObject player
_soundRustle setpos (getpos _nObject)
_soundRustle say ["amb_foliage1", 0]
goto "loop"
............etc.

The problem is that this script (activated via EHinit) play the rantling sounds everywhere is the player bot independently by the bushes and the distance from them.

Any idea how can I obtain the effect I'm lookin' for?

Thanks in advance and Greetings.
« Last Edit: 15 Dec 2008, 18:50:25 by bedges »

Offline Ext3rmin4tor

  • Members
  • *
Re: help with a script
« Reply #1 on: 15 Dec 2008, 18:52:22 »
First thing: the script has a real high overload since it is a SQS based script, the script never exit when the player dies but for some reason the author decided to force the script to execute a neverending loop instead of exiting the script. If you're going to use such a function in ArmA i recommend you to rewrite the script as SQF script because their overload is smaller.

Second thing: The script has the effect you mentioned because it doesn't perform any check on the nearest object player classname, in simple words the script doesn't check if the object is actually a bush, but it simply chooses a random sound from the provided array and select the corresponding code block to play the sound.

Third thing: When you post code of any kind please use the code tag (the "#" simbol in the text interface)

When I have some time I'll try to rewrite the script for you.

EDIT: You edit the message while I was still writing my reply, you used the code tag  :D
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: help with a script
« Reply #2 on: 15 Dec 2008, 19:08:17 »
nearestobject to a player is always the player itself. Check nearestobject or nearestobject specifying a class, in case the bushes have any class name.

Offline HGuderian

  • Members
  • *
Re: help with a script
« Reply #3 on: 15 Dec 2008, 19:12:35 »
Thanks a lot for your reply.

I know the advantage of .sqf but as I wrote I'm only tried to paste various part of some scripts  :whistle:

I can't understand how to perform the detection of bushes (objects or buildings) cause they seems to be not classified in config.

However thanks...and it would be very kindly if u might rewrite my attempt in sqf form. :good:

Best regards and Merry Christmas to both


Offline Ext3rmin4tor

  • Members
  • *
Re: help with a script
« Reply #4 on: 15 Dec 2008, 19:31:45 »
nearestobject to a player is always the player itself. Check nearestobject or nearestobject specifying a class, in case the bushes have any class name.

Are you sure about the nearestObject command? Because in the Biki there's an example which uses nearestObject player. However I can't find the classnames for the bushes, can anyone post them?
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: help with a script
« Reply #5 on: 15 Dec 2008, 20:08:49 »
I think there are no classes for them.

Offline Ext3rmin4tor

  • Members
  • *
Re: help with a script
« Reply #6 on: 15 Dec 2008, 20:23:27 »
So it's impossible to make such a script since you can't check if an object is a bush or not
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Re: help with a script
« Reply #7 on: 22 Dec 2008, 20:29:20 »
Not exactly impossible.
While objects like bushes and trees don't have classes, you can get the names of the p3d files of those objects.
I remember trying to find a way to remove trees from a section in a forest, but gave up when I couldn't find a way to delete them.

The first important thing is not to limit the object search by classes.
Try something like this:
Code: [Select]
_a = nearestObjects [player, [], 5];
_i = 0; _c = count _a;
while {_i < _c} do
{
   player globalChat format ["%1",_a select _i];
   _i = _i + 1;
};
You should see something like "384734 funkyname.p3d" (might be some # or similar at the head of it, can't remember), with the first part being the editor id and the second the model name.

Then you could use toArray and toString to remove anything before and including that space and you could make your own array of bushes to check for.
So not impossible, just needing some work :)