Home   Help Search Login Register  

Author Topic: Names in Multiplayer  (Read 1895 times)

0 Members and 1 Guest are viewing this topic.

XPS

  • Guest
Names in Multiplayer
« on: 11 Jul 2006, 17:10:13 »
Hi,

I have given a unit the name Player1.

When I use this code:
Code: [Select]
Hint Format["Hi %1", Name Player]
The result is "Hi XPS"

The result I want is "Hi Player1"

How can I do this?

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Names in Multiplayer
« Reply #1 on: 11 Jul 2006, 18:20:28 »
player is a command in the command reference and refers in MP to the player on that client.

It has nothing to do with the name given in the name field of the unit dialog.


Planck
I know a little about a lot, and a lot about a little.

XPS

  • Guest
Re: Names in Multiplayer
« Reply #2 on: 11 Jul 2006, 18:26:15 »
I have 3 units, named Player1, Player2 and Player3

When one of those units enters my trigger, I want his name (Player1, Player2 or Player3) as a result.

With my solution (Hint Format["Hi %1", Name Player])
The result is: Hi XPS.

So that is not working for me. What can I do to get Player1, Player2 or Player3 as a result?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Names in Multiplayer
« Reply #3 on: 11 Jul 2006, 18:31:24 »
Code: [Select]
name player
will, as you have probably guessed, return the name of the player, i.e. whoever is playing the mission.

if you wish to the return the name of the unit called player1, use

Code: [Select]
name player1
units which enter a trigger are held in the trigger's activating array. if the trigger has a name (in the 'name' box), the array can be accessed by using

Code: [Select]
_unitarray = list trigger_name
if you wish to assign the array to a global variable from the trigger's init line, use

Code: [Select]
unitarray = thislist
the global variable unitarray is now a real-time array of the units which activate the trigger.

like any array, those units can be accessed using the select command. so for example

Code: [Select]
unitarray select 0
points to the first unit that walked into the trigger. to find out its name, use

Code: [Select]
hint format ["Hi %1", name (unitarray select 0)]
« Last Edit: 11 Jul 2006, 18:37:02 by bedges »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Names in Multiplayer
« Reply #4 on: 11 Jul 2006, 18:37:17 »
I am not sure that this can be done simply. If you were to try this:
Code: [Select]
Hint Format["Hi %1", Player]you would just get "Hi East:Bravo Black 1", or something like that.  There may be a slick way to do this, but I do not know it. Here is a clumsy way:

You will have to create an array of names and a matching array of units.
In your init.sqs
Code: [Select]
nameArray = ["Player1","Player2","Player3",....]
unitArray = [Player1,Player2,Player3,....]

Now when your trigger is activated you will have to search the unitArray to see what element of nameArray to use.
In your trigger On Activation:

Code: [Select]
{if ((thisList select 0) == (unitArray select _i)) then {playerName = nameArray select _i} ; _i = _i + 1} forEach nameArray; hint format ["%1 activated the trigger",playerName]
Note that if the trigger is activated by more than one player, this only gives the name of one of the players.
« Last Edit: 11 Jul 2006, 18:49:58 by Mr.Peanut »
urp!

XPS

  • Guest
Re: Names in Multiplayer
« Reply #5 on: 11 Jul 2006, 19:03:36 »
I get this error:
scalar bool array string 0xfxffffef activated the trigger.

So it still won't get the name I gave the unit.
« Last Edit: 11 Jul 2006, 23:42:57 by XPS »