OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Acecool on 28 Feb 2005, 11:19:01

Title: name _unit .. but the actual Name: from the editor..
Post by: Acecool on 28 Feb 2005, 11:19:01
How do I get the actual name from a player?

not "name _unit" which would return Acecool, but the Name what you give in the editor?

Thanks in advance :-)
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: StonedSoldier on 28 Feb 2005, 11:22:56
ok, not quite sure what your asking but here goes,

either try

hint format ["%1",_unit]

or

hint format ["%1",typeof _unit]
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: THobson on 28 Feb 2005, 12:20:11
If you give the name in description.ext you can then use the name command to extract it.
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 28 Feb 2005, 13:15:57
Hi, thanks for the quick responses :-)

_unit gives a full list then :Acecool..
typeof gives the type, like Solder...  etc..

Say I name a unit p1, etc in the editor, how would I get that to show up?

Thanks
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: THobson on 28 Feb 2005, 13:58:53
If Stonedsoldier's suggestions don't work then I am not sure you can
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 28 Feb 2005, 19:15:08
Hmm, there has got to be a way..

Basically, create a unit with the editor, then in the Name: _____________________ field type in a name..

That name is the one I need to get, heh..
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: StonedSoldier on 28 Feb 2005, 19:41:26
give us some idea why you need this information and what your trying to do and im sure we can find a work around
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: ACF on 28 Feb 2005, 19:47:55
The game engine knows the units as, say, East Alpha Black:1 - that's the sort of thing you get when you do a Format ["%1",mynamedunit].

When you name a unit in the editor you are defining a variable whose value is the unit's 'identifier' i.e.

mynamedunit = East Alpha Black:1

In wanting the editor name of the unit, you are effectively asking the question 'which variable holds this value?'  You can't do that withoout knowing all the variables and checking through them.

The other way I would read your first post is 'how do you set the player's real name against the player unit's identity?'  All I can offer on this one is that in Sui's missions, he has pulled out the player' name as a string because it appears as text; there must be a reserved variable 'playername' or somesuch. /knowledge
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 28 Feb 2005, 20:13:47
Well, I do this:

_Players = ["p1","p2","p3","p4","p5", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"]
{call format [{%1 addAction ["Statistics","Scripts/Stats.sqs"]}, _x]} forEach _Players

for a few others aswell (actions etc)..

When the user dies, it doesnt select the correct user for the messages etc..
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Fragorl on 01 Mar 2005, 01:03:20
Have you tried it without using strings, like ' "p1" ' but instead just objects, ' p1 '?
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: General Barron on 01 Mar 2005, 03:28:54
I think you are making this WAY more complicated than it needs to be. Listen to what ACF is telling you: putting "p1" in a unit's name field is EXACTLY the same as putting this in his init field:
  p1 = this

So basically you are asking a totally illogical question. It is like you are saying:
  a = 5
  what variable is 5?
Obviously "5" could be stored in any number of variables, just like a unit can be stored in any number of variables. But there isn't really any reason why you would HAVE to know the answer to this question, because you can just do it an easier way:

_players = [p1, p2, p3, ... ]
{_x addaction ["blah","blah.sqs"]} foreach _players

edit

Quote
All I can offer on this one is that in Sui's missions, he has pulled out the player' name as a string because it appears as text; there must be a reserved variable 'playername' or somesuch. /knowledge


name unit
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Sui on 01 Mar 2005, 05:41:50
Quote
All I can offer on this one is that in Sui's missions, he has pulled out the player' name as a string because it appears as text; there must be a reserved variable 'playername' or somesuch. /knowledge


name unit

Correctamundo... I simply used:

name player

(or for the intro: name c1 as it didn't like player...)
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: THobson on 01 Mar 2005, 08:15:08
Which takes us back to #2 above.
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 01 Mar 2005, 14:14:22
On the player init, I just put this addaction for now..

Basically, I need this for respawn...

Code: [Select]
_unit = _this select 0

_msg = Format["%1 you died and will respawn in 1 Minute!", name _unit]
_unit groupchat _msg

~61
_unit addAction ["Statistics","Scripts/Stats.sqs"]

~1
deletevehicle _unit

exit

it deletes the dead body, but doesnt add action to the unit.. which is why I want it to add it to the actual player: p1 (instead of Acecool) or would that work?
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: General Barron on 01 Mar 2005, 20:11:31
Why are you deleting _unit right after you add an action to it? Is this script run from a killed eventhandler?

I assume that what is happening is that the action is being added to the player's corpse, which is then deleted. I don't know much about respawning, so I don't know if I can help you on this one. The question I would need to know is:

If you name the player "p1", and the player dies and respawns, does "p1" then point to his corpse, or the new, respawned player?

I would think that how you approach this would have to depend on the answer to this question.
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 01 Mar 2005, 21:37:42
P1 is always p1...

Since when you respawn the "p1" marker jumps to where you respawn :-)
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 02 Mar 2005, 17:09:51
Any ideas? :-)
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: General Barron on 02 Mar 2005, 20:51:21
Okay, so in your killed eventhandler, _unit seems to always point to the players corpse, even after he respawns. But your variable p1 always points to the player, meaning after he respawns it stops pointing to his corpse, and instead points to his "new body". So it seems to me that all you have to do is add the action to p1 (the player's live body), instead of adding it to _unit (the player's corpse).

I assume you are going to then ask "well how do I know which variable to use, because I want to use the same script for all the players" (p1-p8 or whatever), which I take it was basically your original question. Their are two ways you could solve this:

#1: Like ACF suggested, you can simply compare _unit to all the player variables until you come up with a match (and do the comparison when _unit still points to the player; i.e. before respawn). So basically it would look something like:

Quote
_unit = _this select 0
? _unit == p1 : _var = 1
? _unit == p2 : _var = 2
     ........
~61
? _var == 1 : p1 addaction [.......]
? _var == 2 : p2 addaction [.......]

#2: A trickier, but more elegant way to do it, would be to use strings and the call / format commands to essentially pass a variable (as opposed to what is inside of that variable) to the script run by the eventhandler:

in the unit's init field:
Code: [Select]
p1 addeventhandler ["killed", {[_this select 0, "p1"] exec "killed.sqs"}]killed.sqs:
Code: [Select]
_corpse = _this select 0
_var = _this select 1
     ............
~61
call format [{%1 addaction  ["Statistics","Scripts/Stats.sqs"]}, _var]
deletevehicle _corpse
exit
Note that I haven't tested that, and I don't know jack about MP scripting, so no promises. However, if everything else you said was true, then I would think that this should work fine.
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 03 Mar 2005, 06:51:07
Hi, thanks, it works now if I define all.. but..


This works:
? _unit_id == 1 : removeallweapons p1; p1 addaction ["Statistics","Scripts/Stats.sqs"]; p1 addEventHandler ["killed", {_this exec "Global/Player_Killed.sqs"}]; p1 addeventhandler ["fired", {_this exec "Global/Player_Fired.sqs"}]; p1 groupchat _msg;


This doesnt:
? _unit == p1 : _unit_id = "p1"
? _unit == p2 : _unit_id = "p2"
? _unit == p3 : _unit_id = "p3"
? _unit == p4 : _unit_id = "p4"
? _unit == p5 : _unit_id = "p5"
? _unit == c1 : _unit_id = "c1"
? _unit == c2 : _unit_id = "c2"
? _unit == c3 : _unit_id = "c3"
? _unit == c4 : _unit_id = "c4"
? _unit == c5 : _unit_id = "c5"
? _unit == c6 : _unit_id = "c6"
? _unit == c7 : _unit_id = "c7"
? _unit == c8 : _unit_id = "c8"
? _unit == c9 : _unit_id = "c9"
? _unit == c10 : _unit_id = "c10"

{call format [{removeallweapons %1}, _unit_id]}
{call format [{%1 addAction ["Statistics","Scripts/Stats.sqs"]}, _unit_id]}
{call format [{%1 addeventhandler ["Killed", {_this exec "Global/Player_Killed.sqs"}]}, _unit_id]}
{call format [{%1 addeventhandler ["Fired", {_this exec "Global/Player_Fired.sqs"}]}, _unit_id]}
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: General Barron on 03 Mar 2005, 19:26:49
I dont' understand. Post the complete script.
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 03 Mar 2005, 23:12:53
Init.sqs (on the player field...)
_unit = _this select 0

Money = 2500
Ammo_Check = 0

_unit addAction ["Statistics","Scripts/Stats.sqs"]
_unit addeventhandler ["killed", {_this exec "Global/Player_Killed.sqs"}]
_unit addeventhandler ["fired", {_this exec "Global/Player_Fired.sqs"}]

Exit

player_killed.sqs
_unit = _this select 0

? _unit == p1 : _unit_id = "p1"
? _unit == p2 : _unit_id = "p2"
? _unit == p3 : _unit_id = "p3"
? _unit == p4 : _unit_id = "p4"
? _unit == p5 : _unit_id = "p5"
? _unit == c1 : _unit_id = "c1"
? _unit == c2 : _unit_id = "c2"
? _unit == c3 : _unit_id = "c3"
? _unit == c4 : _unit_id = "c4"
? _unit == c5 : _unit_id = "c5"
? _unit == c6 : _unit_id = "c6"
? _unit == c7 : _unit_id = "c7"
? _unit == c8 : _unit_id = "c8"
? _unit == c9 : _unit_id = "c9"
? _unit == c10 : _unit_id = "c10"

_unit removealleventhandlers "Killed"
_unit removealleventhandlers "Fired"

_msg = Format["%1 you died and will respawn in 1 Minute!", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 55 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 50 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 45 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 40 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 35 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 30 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 25 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 20 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 15 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 10 Seconds.", name _unit]
_unit groupchat _msg
~5
_msg = Format["%1 you will respawn in 5 Seconds.", name _unit]
_unit groupchat _msg
~1
_msg = Format["%1 you will respawn in 4 Second.", name _unit]
_unit groupchat _msg
~1
_msg = Format["%1 you will respawn in 3 Second.", name _unit]
_unit groupchat _msg
~1
_msg = Format["%1 you will respawn in 2 Second.", name _unit]
_unit groupchat _msg
~1
_msg = Format["%1 you will respawn in 1 Second.", name _unit]
_unit groupchat _msg
_msg = Format["Welcome back to the land of the living, %1.", name _unit]

~1
;? _unit_id == 1 : removeallweapons p1; p1 addaction ["Statistics","Scripts/Stats.sqs"]; p1 addEventHandler ["killed", {_this exec "Global/Player_Killed.sqs"}]; p1 addeventhandler ["fired", {_this exec "Global/Player_Fired.sqs"}]; p1 groupchat _msg;
{call format [{removeallweapons %1}, _unit_id]}
{call format [{%1 addAction ["Statistics","Scripts/Stats.sqs"]}, _unit_id]}
{call format [{%1 addeventhandler ["Killed", {_this exec "Global/Player_Killed.sqs"}]}, _unit_id]}
{call format [{%1 addeventhandler ["Fired", {_this exec "Global/Player_Fired.sqs"}]}, _unit_id]}
{call format [{%1 groupchat _msg}, _unit_id]}

~1
deletevehicle _unit

exit
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: General Barron on 04 Mar 2005, 03:55:30
Okay, I see the problem. Actually, I should have seen it before, but anyway, the problem is that you have lines like this:

{call format [{%1 groupchat _msg}, _unit_id]}

The entire line is just a string that reads:

"call format [......]"

What you need  to do is have the call command, and have the string you want to execute next to it. So it should look like this:

call format [{%1 groupchat _msg}, _unit_id]

The format command returns a string, so the above gets turned into something like this when the script is run:

call {p1 groupchat _msg}
Title: Re:name _unit .. but the actual Name: from the editor..
Post by: Acecool on 04 Mar 2005, 12:17:50
Wow, thank you very much, works perfectly :-)