Home   Help Search Login Register  

Author Topic: Objects vs Map Objects  (Read 4489 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Objects vs Map Objects
« Reply #15 on: 13 Jun 2007, 20:11:40 »
Lee, if you have preset objects you want to connect sounds to then build an array of objects as follows:
Code: [Select]
_objArray = [tank1,12345,2389,45,car65];You then use the isNumber to control how you get the distance to the player.

pseudocode
0) _close_obj = objNull
1) set _close_dist to max distance to search e.g. 300m
2) loop through _objArray
3) if isnumber(_objArray select _i) then _obj = getPos player nearestObject (_objArray select _i)
    else _obj = (_objArray select _i)
4) _dist = player distance _obj
5) if _dist is smaller than _close_dist then _close_dist = _dist; _close_obj = _obj; _close_sound = _soundArray select _i;
6) end loop through _objArray
7) if (isNull _close_obj) then  none of the objects are in range
    else set sound source trigger and sound it to play
8) sleep 1
9) repeat ad infinitum starting at 0)



However, why do you not simply place an empty(i.e. invisible) marker everywhere you want a sound, and name the markers after the sounds or better yet store the sound name in the marker text? Then all you is find the closest marker, move the trigger to it, and set the sound to play from the marker name or text?
« Last Edit: 14 Jun 2007, 15:43:20 by Mr.Peanut »
urp!

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Objects vs Map Objects
« Reply #16 on: 14 Jun 2007, 05:28:37 »
Thanks Mr. Peanut, i'm gonna give it a go and try and set this up.  I'm just trying to avoid placing 50 markers or game logics on the map.  And its probably taking me longer to figure out how to write a script avoiding that duty than just doing it in the first place!  :dry:  I'll let you know how it turns out and I'll post the completed script...

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Objects vs Map Objects
« Reply #17 on: 14 Jun 2007, 15:46:12 »
But you will learn a lot more doing it this way! :yes: Also, will be a lot more flexible than using markers i.e. can attach sounds even to moving vehicles.

I fixed a bug or two in my pseudocode above. Yes, even p-code has bugs!   :blink:
urp!

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Objects vs Map Objects
« Reply #18 on: 21 Jun 2007, 02:05:50 »
hey Mr. Peanut, finally got it figured out.   :clap:  I used a similar script (one from THobson's Abandoned Armies that gave me the original idea) to your pseudo one and incorporated some of the differences.  Thanks again for the help.  Attached is the demo mission for moving Sound Candy based on object ID's.
« Last Edit: 22 Jun 2007, 04:44:17 by Lee »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Objects vs Map Objects
« Reply #19 on: 21 Jun 2007, 03:00:28 »
Great! Now how about writing a small readme/documentation and submitting it to the Beta thread?  :whistle:
« Last Edit: 21 Jun 2007, 03:03:08 by Mr.Peanut »
urp!

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Objects vs Map Objects
« Reply #20 on: 21 Jun 2007, 03:06:22 »
Right, will do!