Home   Help Search Login Register  

Author Topic: name _unit .. but the actual Name: from the editor..  (Read 1965 times)

0 Members and 1 Guest are viewing this topic.

Acecool

  • Guest
Re:name _unit .. but the actual Name: from the editor..
« Reply #15 on: 01 Mar 2005, 21:37:42 »
P1 is always p1...

Since when you respawn the "p1" marker jumps to where you respawn :-)

Acecool

  • Guest
Re:name _unit .. but the actual Name: from the editor..
« Reply #16 on: 02 Mar 2005, 17:09:51 »
Any ideas? :-)

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:name _unit .. but the actual Name: from the editor..
« Reply #17 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.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Acecool

  • Guest
Re:name _unit .. but the actual Name: from the editor..
« Reply #18 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]}

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:name _unit .. but the actual Name: from the editor..
« Reply #19 on: 03 Mar 2005, 19:26:49 »
I dont' understand. Post the complete script.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Acecool

  • Guest
Re:name _unit .. but the actual Name: from the editor..
« Reply #20 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

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:name _unit .. but the actual Name: from the editor..
« Reply #21 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}
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Acecool

  • Guest
Re:name _unit .. but the actual Name: from the editor..
« Reply #22 on: 04 Mar 2005, 12:17:50 »
Wow, thank you very much, works perfectly :-)