Home   Help Search Login Register  

Author Topic: Unit name to script  (Read 2165 times)

0 Members and 3 Guests are viewing this topic.

BUNNY

  • Guest
Unit name to script
« on: 24 Nov 2004, 07:06:45 »
I'm making a MP mission and I need to relocate soldier when it respawns to west_respawn marker. I made a trigger covering the marker (west, present, repeatedly) , but what do I put in the on Activation field? What I'm asking is, how can i get the unit name that's in the trigger transferred to the relocating script? It is something [xxx] exec "relocate.sqs"... And does this work if more than one soldier respawn at the same time? Or is there any better way to deal with this?

Offline CrashDome

  • Members
  • *
Re:Unit name to script
« Reply #1 on: 24 Nov 2004, 08:35:31 »
[thislist] exec "relocate.sqs"

It will send an array of all units currently in the trigger area.
so in your script you must do something like this:
Code: [Select]
Private ["_units"]

_units = _this select 0

;not sure what your script does but this moves all units to their leader's current position
{_x setpos (getpos leader _x)} foreach _units

EXIT

BUNNY

  • Guest
Re:Unit name to script
« Reply #2 on: 24 Nov 2004, 14:33:37 »
Thx. I try to use this.

 I get the " _units = _this select 0 " but what does that >"  Private ["_units"] " do?
And i assume that i have to copy this >"  {_x setpos (getpos leader _x)} foreach _units " and alter it for y cordinates...? Right.

noobydoobydoobdoob

Uldics

  • Guest
Re:Unit name to script
« Reply #3 on: 24 Nov 2004, 16:14:04 »
As I understand from http://www.ofpec.com/editors/comref.php?letter=P#private it means if the same name is used some other place outside the place in the script, then it will not make name collision and just use the private one and not see another one.

Offline CrashDome

  • Members
  • *
Re:Unit name to script
« Reply #4 on: 24 Nov 2004, 19:20:30 »
Yes, the 'Private' function is to prevent conflicts with other scripts that might also use the same name '_units'. It is optional, but good coding practice.

As far as using the "{_x setpos (getpos leader...." command. I only put that there as an example. It can be any code you wish. If you do use that example, you do not need to alter the Y coordinate if you don't want to... it's a matter of personal taste. There may be a problem if the leader dies though. Especially if player is leader. It might keep setpos'ing the player into the same spot if he is the leader and respawns. Again... it was only a quick example. ;)

BUNNY

  • Guest
Re:Unit name to script
« Reply #5 on: 25 Nov 2004, 07:14:21 »
Thank you! I modded that and i got it to work.

 The main idea was to have 2 locations to spawn into (original respawn marker not included).

I could make script that determines rhe spawnpoint by analysing the status of the mission, but what I would like to do is get player to choose his spawnpoint.

I tried to look and make this with dialogboxes, but thats SO messy...just cannot compute. And the dialogmaker software isn't very good either. So is there any other way to do this...to choose your spawnpoint after death?

Offline CrashDome

  • Members
  • *
Re:Unit name to script
« Reply #6 on: 25 Nov 2004, 19:10:32 »
You can, but will be just as messy as a dialog.

If you do not want to make your own dialog, might I suggest using my Dynamic Dialog?

you can find it here: http://www.sinewsofwar.com/forum/dloads.php

Unzip the file

Copy the folder "SOW_DynamicDlg" to your mission folder

Copy the contents of the Description.ext file paste it all into your description.ext file (anywhere)

Put in your init.sqs file this line:
Code: [Select]
SOW_FillListBox = preprocessfile "SOW_DynamicDlg\FillListBox.sqf";
RespawnSpeech = call loadfile "RespawnSpeech.sqf";

create a function file "RespawnSpeech.sqf" in your mission folder
and paste this into it:
Code: [Select]
private ["_structure"];

_structure = [];

comment "Array consists of [ AI unit text response, [Array of user responses] ] for each dialog 'page' or 'set' ";
comment "Array for user responses consists of [text, which page to go to next (or -1 to end), {scripted action} ]";
comment "Speech Set 0";
_structure = _structure +
[[
   "You have died. Please choose your respawn area:","",
   [
      ["Respawn Area 1",-1,{_listener setpos (getmarkerpos "respawn1")}],
      ["Respawn Area 2",-1,{_listener setpos (getmarkerpos "respawn2")}]
   ]
]];

_structure


NOW, you will have to change some stuff because I don't know what you use for respawn areas? Are they markers? If so change the marker names "Respawn1" and "Respawn2" in the above code to match yours.
You can also change the text to whatever you want.

Lastly, you will need to change the
Code: [Select]
{_x setpos (getpos leader _x)} foreach _units in your relocate.sqs file to:
Code: [Select]
{if (_x == player) then {[player, RespawnSpeech, player] exec "SOW_DynamicDlg\talk.sqs"} else {_x setpos (getpos leader _x)};} foreach _units

There is one problem with this. If the player chooses the cancel button or hits the ESC key during this dialog, they will stay at the original respawn marker.

Let me know of any problems.
« Last Edit: 25 Nov 2004, 19:13:01 by CrashDome »

BUNNY

  • Guest
Re:Unit name to script
« Reply #7 on: 26 Nov 2004, 07:11:21 »
Wow! Thanks!! Just what I need.

I'm quite busy for a while but I let ya know how it turned out.
So I can use this freely and publish my upcoming MP-mode? You can be sure that you'll get all the credits from this.

Thanks anyway :)

Offline CrashDome

  • Members
  • *
Re:Unit name to script
« Reply #8 on: 26 Nov 2004, 16:12:08 »
So I can use this freely and publish my upcoming MP-mode? You can be sure that you'll get all the credits from this.

Absolutely!  ;)

Once you get it working, I can help you tweak it to suit your needs better. It was originally intended to make AI speak and allow players to respond, but can be adjusted so that A) the cancel button is not there and B) if players hit ESC (close the dialog) before choosing a respawn area it redisplays the dialog again, forcing them to choose.