Z1DDE 5 Posted June 20, 2019 Hey, im new to Arma 3 scripting (so please go easy on me ( : ) I was wondering how I would write a player init in a sqf file instead of in the editor. For more context: I have 4 units and I would like to run individual scripts for each of them ? How would I do this? Thanks Edit: Could I have it so each unit runs "his" script file? Share this post Link to post Share on other sites
Lorenz94 6 Posted June 20, 2019 Hi Z1DDE, what do you need to do exaclty? What's the code you used to paste in the init field of those units? Share this post Link to post Share on other sites
Z1DDE 5 Posted June 20, 2019 4 minutes ago, Lorenz94 said: Hi Z1DDE, what do you need to do exaclty? What's the code you used to paste in the init field of those units? Well im trying to make the gamemode TTT, because I thought that would be simple. The code im trying to put in the units is just the randomizer for who becomes traitor or innocent. But I don't want to do it in the editor string1 = ["traitor", "innocent","innocent","innocent"] call BIS_fnc_selectRandom; 1 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted June 20, 2019 6 hours ago, Z1DDE said: Well im trying to make the gamemode TTT Hello there Z1DDE and welcome also to Bis Forums ! Whould you like to do something like this ? Share this post Link to post Share on other sites
Z1DDE 5 Posted June 20, 2019 1 hour ago, GEORGE FLOROS GR said: Hello there Z1DDE and welcome also to Bis Forums ! Whould you like to do something like this ? Thanks alot! my code now looks like this: waituntil{time>2}; systemchat "Start"; _allPlayers = allUnits select {isPlayer _x && {alive _x} && {!(_x isKindOf "HeadlessClient_F")}}; if (count _allPlayers isEqualTo 1) exitWith { systemchat "not enough players"; }; _Terrorist = selectrandom _allPlayers; if (player isEqualTo _Terrorist) then { titleText ["Now this is epic", "PLAIN"]; waitUntil {uisleep 1;!alive _Terrorist}; systemchat "Good Job"; Uisleep 3; []execvm "script.sqf"; Only thing I don't think works is: if (player isEqualTo _Terrorist) then { titleText ["Now this is epic", "PLAIN"]; I don't think im suppose to use "player" here ? You can also see ive changed _player to _terrorist but eitherway how would I check if it actually makes someone the terrorist? what I would like is for it to display a titletext when you're the traitor. I know how to that, but at the moment it isnt displaying the titletext and that is probably because im using player. So what I was wondering is what would I do ? thanks ! Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 i guess you don't use .rpt file to watch script errors. do you? your if then statement is missing the closing curly bracket... edit: you can just use _allPlayers = allUnits; because allUnits has only alive players and no headless clients in it reading command descriptions in the wiki helps a lot 2 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted June 21, 2019 12 hours ago, Z1DDE said: _allPlayers = allUnits select {isPlayer _x && {alive _x} && {!(_x isKindOf "HeadlessClient_F")}}; 4 hours ago, sarogahtyp said: because allUnits has only alive players and no headless clients in it I was always trying generally , to find what is better in order to work in SP/MP because there are a lot of different codes that you can work with. like : _allPlayers = []; {if(alive _x && isPlayer _x) then{_allPlayers pushBack _x;};}forEach allUnits; any suggestion , to have a better performance and working solution ? by the way with allunits it detects also the 3 sides in the editor , i don't know really how they called. like : _allPlayers = allUnits select {!isPlayer _x && alive _x && _x iskindof "man"}; 12 hours ago, Z1DDE said: Only thing I don't think works is: would you lik to add a little bit more info , about what you want to create ? 1 Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 @GEORGE FLOROS GR I'll try explaining what I want: This selects all units and makes them to _allPlayers, right ? _allPlayers = allUnits; _Terrorist = selectrandom _allPlayers; Then this chooses randomly one of them and makes him _Terrorist Then I would want it to display a titleText that says that you're the traitor if you were to become _Terrorist 1 Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 Quote you can just use _allPlayers = allUnits; huh, I made a mistake. I should have read the wiki myself before posting nonsense... I meant playableUnits: _allPlayers = playableUnits; this contains alive players without HCs + switchable Units which should not exist on MP without AI usage for Player slots... 2 Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 4 minutes ago, sarogahtyp said: huh, I made a mistake. I should have read the wiki myself before posting nonsense... I meant playableUnits: _allPlayers = playableUnits; this contains alive players without HCs + switchable Units which should not exist on MP without AI usage for Player slots... ok thanks Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted June 21, 2019 4 minutes ago, sarogahtyp said: _allPlayers = playableUnits; I think , not that sure , that i read from @pierremgi that playableUnits will not be JIP , if there is not an ai unit selected from the lobby , also i remember that is not working in SP. 1 Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 31 minutes ago, sarogahtyp said: huh, I made a mistake. I should have read the wiki myself before posting nonsense... I meant playableUnits: _allPlayers = playableUnits; this contains alive players without HCs + switchable Units which should not exist on MP without AI usage for Player slots... When I used playableUnits instead of allUnits a error happend so I switched back. But I also realized that the _allPlayers = allUnits; makes it so titletexts doesnt work ? Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 @Z1DDE provide infos! Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 I've got everything working now! waituntil{time>2}; systemchat "Start"; if (count allPlayers isEqualTo 1) then { systemchat "not enough players"; }; _Terrorist = selectRandom allPlayers; _Terrorist setVariable ["terroristVar", player, true]; if (player isEqualTo _Terrorist) exitWith { titleText ["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; } else { titleText ["<t color='#00FF00' size='5'>Innocent!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; }; waitUntil {uisleep 1;!alive _Terrorist}; systemchat "Good Job"; Share this post Link to post Share on other sites
ZaellixA 384 Posted June 21, 2019 Hhhmmm..., correct me if I am wrong, but I am not sure the part of the code after the exitWith will be executed. I haven't tested but to me it seems that the code will exit the current scope (which looks like is the script "itself"). Now, regarding your "issue" I would actually tackle it like this: // COPIED FROM YOUR CODE waituntil{time>2}; systemchat "Start"; if (count allPlayers isEqualTo 1) then { systemchat "not enough players"; }; _Terrorist = selectRandom allPlayers; // CHANGED // _Terrorist setVariable ["terroristVar", player, true]; -> COMMENTED OUT AS IT IS NOT NEEDED IN MY VARIANCE ["Traitor!"] remoteExec["hint", _Terrorist, false]; // Execute hint with "Traitor!" at traitor's locality ["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false]; // Execute hint with "Innocent!" at everyone else's locality // FOLLOWING CODE IS COMMENTED OUT AS IT IS NOT NEEDED /* if (player isEqualTo _Terrorist) exitWith { titleText ["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; } else { titleText ["<t color='#00FF00' size='5'>Innocent!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; }; */ // FOLLOWING CODE IS LEFT AS IS TO WAIT UNTIL THE TRAITOR IS KILLED waitUntil {uisleep 1;!alive _Terrorist}; systemchat "Good Job"; Again, this is not tested and may (most probably) contain errors, but I believe the main idea is communicated. I hope this helps to widen the arsenal of your choices. EDIT: Just for the sake of convenience here is a link to the remoteExec command. Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 7 minutes ago, ZaellixA said: Hhhmmm..., correct me if I am wrong, but I am not sure the part of the code after the exitWith will be executed. I haven't tested but to me it seems that the code will exit the current scope (which looks like is the script "itself"). Now, regarding your "issue" I would actually tackle it like this: // COPIED FROM YOUR CODE waituntil{time>2}; systemchat "Start"; if (count allPlayers isEqualTo 1) then { systemchat "not enough players"; }; _Terrorist = selectRandom allPlayers; // CHANGED // _Terrorist setVariable ["terroristVar", player, true]; -> COMMENTED OUT AS IT IS NOT NEEDED IN MY VARIANCE ["Traitor!"] remoteExec["hint", _Terrorist, false]; // Execute hint with "Traitor!" at traitor's locality ["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false]; // Execute hint with "Innocent!" at everyone else's locality // FOLLOWING CODE IS COMMENTED OUT AS IT IS NOT NEEDED /* if (player isEqualTo _Terrorist) exitWith { titleText ["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; } else { titleText ["<t color='#00FF00' size='5'>Innocent!</t><br/>***********", "PLAIN", -1, true, true]; titleFadeOut 10; }; */ // FOLLOWING CODE IS LEFT AS IS TO WAIT UNTIL THE TRAITOR IS KILLED waitUntil {uisleep 1;!alive _Terrorist}; systemchat "Good Job"; Again, this is not tested and may (most probably) contain errors, but I believe the main idea is communicated. I hope this helps to widen the arsenal of your choices. EDIT: Just for the sake of convenience here is a link to the remoteExec command. Yes i forgot to mention. I realized that and changed it 1 Share this post Link to post Share on other sites
ZaellixA 384 Posted June 21, 2019 One more detail about my code is that it does NOT differentiate between Headless Clients and players. You should use the following code snippet in order to make sure this happens. 16 hours ago, Z1DDE said: _allPlayers = allUnits select {isPlayer _x && {alive _x} && {!(_x isKindOf "HeadlessClient_F")}}; Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 3 minutes ago, ZaellixA said: One more detail about my code is that it does NOT differentiate between Headless Clients and players. You should use the following code snippet in order to make sure this happens. Well the gamemode isnt made for AI use so I don't know if it is needed Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 @ZaellixA one more detail is that u r writing code for use on server and op tries it on client. (using "player"). OPs code will not work if there are some more connected clients because each client will choose a different terrorist. but again, why not using _allPlayers = playableUnits; instead of 4 minutes ago, ZaellixA said: _allPlayers = allUnits select {isPlayer _x && {alive _x} && {!(_x isKindOf "HeadlessClient_F")}}; ??? 1 Share this post Link to post Share on other sites
ZaellixA 384 Posted June 21, 2019 It may be needed if you end up playing with headless client(s). I am not sure about it (if someone could either confirm that) but I believe that ArmA sees headless clients as players., so you may end up having a headless client as traitor. Which from my point of view is not really helpful for a game mode 😛 Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 1 minute ago, ZaellixA said: It may be needed if you end up playing with headless client(s). I am not sure about it (if someone could either confirm that) but I believe that ArmA sees headless clients as players., so you may end up having a headless client as traitor. Which from my point of view is not really helpful for a game mode 😛 okay, i can confirm a hc is not part of playableUnits. 1 Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 21, 2019 it's also in the wiki entry of playableUnits. somewhat hidden but it is: Quote Does not contain units of sideLogic. A HC is part of sideLogic 1 Share this post Link to post Share on other sites
ZaellixA 384 Posted June 21, 2019 Well, I wouldn't say no to the use of playableUnits (seems perfectly valid to me). On the other hand the reason I suggested using the remoteExec is, as you said, that OP's code has some drawbacks (like the one you mention). I am not sure though that remoteExec can be invoked only on servers. Also, there are some workarounds in the comments at the bottom of the page, to make the code runnable in SP and dedicated servers too. Again, if there are (and most probably there exist) better ways to do it, then that's great 🙂 Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 @ZaellixA How would i use this but with titleTexts instead ? I really appreciate the help btw! ["Traitor!"] remoteExec["hint", _Terrorist, false]; ["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false]; Share this post Link to post Share on other sites
Z1DDE 5 Posted June 21, 2019 @ZaellixA I also get this error with this code running: ["Traitor!"] remoteExec["hint", _Terrorist, false]; ["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false]; Share this post Link to post Share on other sites