Jump to content
dashiellcote

Cool feature in Western Sahara

Recommended Posts

I noticed an interesting feature in WS where when you switch units that unit becomes team leader (works perfectly 100% of the time). I have been trying for at least a week to figure this out myself but no luck. I thought I had it working with some scripting in a trigger but often it will stop working during a longer game session. My first approach was as follows:

 

Activation: Anybody

Activation Type: Present

Condition: round (time %1) ==1

Interval: 0

On Activation: onTeamSwitch{group player selectLeader player};

On Deactivation: onTeamSwitch{group player selectLeader player};

 

After some more searching I've discovered that "onTeamSwitch" has some issues. I was pointed in the direction of maybe using addEventHandler "teamswitch" instead. This is what I found:

 

addMissionEventHandler ["TeamSwitch", { params ["_previousUnit", "_newUnit"]; }];

 

Is there any way to add "selectLeader" to this at all? Again I'm just trying to make it that when I switch units I become team leader. Im kinda at a loss with what to try next and any help would be awesome! 

Share this post


Link to post
Share on other sites

Well, I haven't really used this specific event handler but from my (maybe limited) understanding it shouldn't be that different from what you already have. This could possibly look like

/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  private _newUnit = _this select 1;
  
  (group _newUnit) selectLeader _newUnit;
}];

Effectively, what I have done here is replace the player with the passed argument of _newUnit which is the unit you are "transferring" to. Since the new unit and the unit of the player is effectively the same unit (supposedly this event handler is triggered after the transfer to the new unit) you could possibly just use the same line of code you have used in your code and make it look like

/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  (group player) selectLeader player;
}];

I believe the first one is safer because I am not sure whether the event handler is triggered after the change has happened or before. Thus, if  you use the passed argument of the new unit to appoint the new team leader you will "always" be safe and sure that this unit, which you will be taking control of, will become the leader. And, since the overhead of getting the passed argument (_this select 1) into a variable is minimal, I strongly suggest the first snippet.

 

Please do keep in mind though that the presented code is not tested and should be treated with caution.

 

Don't hesitate to send back if you need more help, further refinement or anything else. And please, for the sake of future reference, let us know if this worked for you or not.

Edited by ZaellixA
Corrected some typos
  • Like 1

Share this post


Link to post
Share on other sites
16 hours ago, ZaellixA said:

Well, I haven't really used this specific event handler but from my (maybe limited) understanding it shouldn't be that different from what you already have. This could possibly look like


/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  private _newUnit = _this select 1;
  
  (group _newUnit) selectLeader _newUnit;
}];

Effectively, what I have done here is replace the player with the passed argument of _newUnit which is the unit you are "transferring" to. Since the new unit and the unit of the player is effectively the same unit (supposedly this event handler is triggered after the transfer to the new unit) you could possibly just use the same line of code you have used in your code and make it look like


/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  (group player) selectLeader player;
}];

I believe the first one is safer because I am not sure whether the event handler is triggered after the change has happened or before. Thus, if  you use the passed argument of the new unit to appoint the new team leader you will "always" be safe and sure that this unit, which you will be taking control of, will become the leader. And, since the overhead of getting the passed argument (_this select 1) into a variable is minimal, I strongly suggest the first snippet.

 

Please do keep in mind though that the presented code is not tested and should be treated with caution.

 

Don't hesitate to send back if you need more help, further refinement or anything else. And please, for the sake of future reference, let us know if this worked for you or not.

 

Sorry for the late response (long day).

 

Want to say first that I haven't ever made an init.sqf file before so took a second to figure that out and might not have done it 100% correct. 

 

So after trying both scripts (in an .sqf as well as in a trigger) and I always get an error message.

 

'...rma 3\missions\TEST.VR\init.sqf"

player |#|addMissionEventHandler ["TeamSwitch", {

...'

Error Missing ;

File C:\Users\User\Documents|Arma 3\missions\TEST.VR\init.sqf..., line 1

 

not sure how to access the entire error message but thats what pops up on screen.

 

 

btw thanks again for your first reply!

Share this post


Link to post
Share on other sites

addMissionEventhandler takes no preceding argument. Correct syntax would be:

 

addMissionEventHandler ["TeamSwitch", ...

 

  • Like 4

Share this post


Link to post
Share on other sites
1 hour ago, mrcurry said:

addMissionEventhandler takes no preceding argument. Correct syntax would be:

 

addMissionEventHandler ["TeamSwitch", ...

 

IT WORKED! THANKS!

Share this post


Link to post
Share on other sites
20 hours ago, ZaellixA said:

Well, I haven't really used this specific event handler but from my (maybe limited) understanding it shouldn't be that different from what you already have. This could possibly look like


/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  private _newUnit = _this select 1;
  
  (group _newUnit) selectLeader _newUnit;
}];

Effectively, what I have done here is replace the player with the passed argument of _newUnit which is the unit you are "transferring" to. Since the new unit and the unit of the player is effectively the same unit (supposedly this event handler is triggered after the transfer to the new unit) you could possibly just use the same line of code you have used in your code and make it look like


/*
 * Most probably this is best added in init.sqf in Singleplayer.
 */

player addMissionEventHandler ["TeamSwitch", {
  (group player) selectLeader player;
}];

I believe the first one is safer because I am not sure whether the event handler is triggered after the change has happened or before. Thus, if  you use the passed argument of the new unit to appoint the new team leader you will "always" be safe and sure that this unit, which you will be taking control of, will become the leader. And, since the overhead of getting the passed argument (_this select 1) into a variable is minimal, I strongly suggest the first snippet.

 

Please do keep in mind though that the presented code is not tested and should be treated with caution.

 

Don't hesitate to send back if you need more help, further refinement or anything else. And please, for the sake of future reference, let us know if this worked for you or not.

With the removal of "player" in the beginning the first script in an init.sqf works like a charm! Thank you so much for your help!!!

 

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, mrcurry said:

addMissionEventhandler takes no preceding argument. Correct syntax would be:

 

addMissionEventHandler ["TeamSwitch", ...

 

ABSOLUTELY CORRECT...

 

Thanks a bunch @mrcurry. I haven't scripted for quite some time and don't have a PC to test all the scripts I provide here. This has made me too rusty lately as it seems. On top of that I didn't pay too much attention to the BIKI, which I should start doing more systematically if I would like to provide some feasible solutions to people seeking help around here. Thanks a lot for the correction and @dashiellcote I am sorry for the extra effort (and possibly frustration) I put you in 😞...

 

Glad it is sorted now and it wasn't something very complicated to work around. 🙂

  • Like 2

Share this post


Link to post
Share on other sites

This thread is a great example of the community at work!  A question well asked, and well answered.  🙂

 

@dashiellcote, how about posting the exact syntax of the final working solution?  That way other interested parties don't have to follow the back-and-forth of the entire thread to know the answer. 

  • Like 1

Share this post


Link to post
Share on other sites

@ZaellixA Arma IS frustration lol! No man I can't thank you enough and it added no frustration. 

 

@johnnyboy I think I made an account here awhile ago (dont remember doing this) but this was my first time using the forum. I'm super impressed by how helpful everyone is!

Should I post the exact syntax here or is there another section I should put it? not sure on the etiquette here....

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, dashiellcote said:

Should I post the exact syntax here or is there another section I should put it? not sure on the etiquette here....

Just post it here and prefix it with "Solution:" or something.   Welcome to the forums!

  • Like 1

Share this post


Link to post
Share on other sites

Click the "code" tool, paste your code inside the new field, then "insert into post."

 

dkEKkAc.png

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×