Jump to content
Z1DDE

Write Script for unit but not in the units Init

Recommended Posts

Well, generally speaking when you use remoteExec you pass all the necessary arguments to the function (or command) you want to be executed (on the clients you choose) as arguments to the command. After the remoteExec you "declare" which command you want to be executed. To clarify it a bit see the following code snippet (with a lot of comments)

// The arguments you want to pass to the titleText command must be placed before the remoteExec command. These are:
// ["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]. Pass them as an array.
// Then you call remoteExec with "argument" the name of the command you want to be executed in a string. This is:
// remoteExec["titleText"]
// So the full invokation would look like
["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true] remoteExec ["titleText"];

// Then you have to do the same for the "titleFadeOut" command.
[10] remoteExec["titleFadeOut];

So this should work...

 

Now, regarding your error, you should pay attention to the order of the "objects". You have to subtract the "_Terrorist" from the rest of the players. This means that your code should look like

// Correct
["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false];

// What you seem to have typed
["Innocent!"] remoteExec["hint", _Terrorist - allPlayers, false]; // The _Terrorist and allPlayers is flipped.

Finally I believe it would be better to use playableUnits as sarogahtyp suggested above. In the end the code should look like

["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true] remoteExec ["titleText", _Terrorist, false]; // Send to traitor
[10] remoteExec["titleFadeOut, _Terrorist, false]; // Set fade out for traitor

["<t color='#ff0000' size='5'>Innocent!</t><br/>***********", "PLAIN", -1, true, true] remoteExec ["titleText", playableUnits - _Terrorist, false]; // Send to everyone else
[10] remoteExec["titleFadeOut, playableUnits - _Terrorist, false]; // Set fade out for everyone else

Once more........ Keep in mind this is NOT tested and some minor (or major) errors may exist.

 

Please inform of any issues you cannot fix to help you find solutions. 🙂.

  • Like 2

Share this post


Link to post
Share on other sites
49 minutes ago, ZaellixA said:

["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true] remoteExec ["titleText"];

I have a bit of a weird error?

No titleText is displaying but there isnt any errors showing ?

Share this post


Link to post
Share on other sites
53 minutes ago, ZaellixA said:

// Correct ["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false]; // What you seem to have typed ["Innocent!"] remoteExec["hint", _Terrorist - allPlayers, false]; // The _Terrorist and allPlayers is flipped.

Also i flipped _Terrorist and allPlayers becuase allPlayers - _Terroris wasnt working.

 

Example

unknown.png

Share this post


Link to post
Share on other sites
2 minutes ago, Z1DDE said:

Also i flipped _Terrorist and allPlayers becuase allPlayers - _Terroris wasnt working.

 

Example

unknown.png

Well, then this must be my fault. Apologies for that. You can use:

_allButTerrorist = playableUnits; // Get all playable units
_Terrorist = selectRandom _allButTerrorist; // Pick a random terrorist
_allButTerrorist = deleteAt (findIf{_x isEqualTo _Terrorist}); // Remove the terrorist from the array

This should work.

 

Now for the titleText command. Can you please try the following and let us know of the results

["Traitor!", "PLAIN"] remoteExec["titleText"];

 

Share this post


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

@ZaellixA

 

I also get this error

unknown.png

with this code running:


["Traitor!"] remoteExec["hint", _Terrorist, false];
["Innocent!"] remoteExec["hint", allPlayers - _Terrorist, false];

 

["Innocent!"] remoteExec ["hint", allPlayers - [_Terrorist]];

 

  • Like 1

Share this post


Link to post
Share on other sites
24 minutes ago, ZaellixA said:

Now for the titleText command. Can you please try the following and let us know of the results


["Traitor!", "PLAIN"] remoteExec["titleText"];

Nothing happens, i tried just a normal titleText and that worked. somethings not working with the remoteExec i guess ?

Share this post


Link to post
Share on other sites
29 minutes ago, ZaellixA said:

 

Now for the titleText command. Can you please try the following and let us know of the results


["Traitor!", "PLAIN"] remoteExec["titleText"];

I've got it working now, you just needed a extra pare of bracket on the text

[["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]] remoteExec ["titleText", _Terrorist, false];

 

  • Like 1

Share this post


Link to post
Share on other sites

Hey @Z1DDE, would you care to share a working piece of code if you eventually manage to make it work? I am asking so that people could potentially benefit from your solution in the future. That is, if you don't mind sharing of course.

  • Like 1

Share this post


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

Hey @Z1DDE, would you care to share a working piece of code if you eventually manage to make it work? I am asking so that people could potentially benefit from your solution in the future. That is, if you don't mind sharing of course.

waituntil{time>2};
	systemchat "Start"; // Writes out that the script has started

if (count allPlayers isEqualTo 1) then { // counts players, if there is only one player then it ends the mission
	systemchat "not enough players";
	endMission "END1";
};

//Creates Variables
_allButTerrorist = playableUnits; // Gets all the units and creates a variable
_Terrorist = selectRandom _allButTerrorist; // Randomizes one terrorist out of all players
_allButTerrorist = playableUnits - [_Terrorist]; // Creates a variables for all the playes without the terrorist

//Public Variables
PublicVariable "_Terrorist"; // makes the _Terrorist variable public
PublicVariable "_allButTerrorist"; // makes the _allButTerrorist variable public

//Title Texts
[["<t color='#ff0000' size='5'>Traitor!</t><br/>***********", "PLAIN", -1, true, true]] remoteExec ["titleText", _Terrorist, false]; // Displays a titletext to show you're the traitor
[10] remoteExec["titleFadeOut", _Terrorist, false]; // Fades out titleText

[["<t color='#00FF00' size='5'>Innocent!</t><br/>***********", "PLAIN", -1, true, true]] remoteExec ["titleText", _allButTerrorist, false]; // Displays a titletext to show you're innocent
[10] remoteExec["titleFadeOut", _allButTerrorist, false]; // Fades out titleText for innocent

//Ending
waitUntil {uisleep 1;!alive _Terrorist}; // If the terrorist Dies Then innocent win
endMission "END1";  

Here is all the code, I don't know if _Terrorist and _allButTerrorist needs to be public variable but i just did incase. With this there are no errors and everything works while hosted on my server. I also added comments just to make it easier for the future.

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, Z1DDE said:

everything works while hosted on my server. I also added comments just to make it easier for the future.

 

That can work only if you are waiting for all players before starting the mission. allPlayers (and playableUnits in case of disabled AIs in lobby) are never updated.

  • Like 2

Share this post


Link to post
Share on other sites

@Z1DDE, this won't work:

//Public Variables
PublicVariable "_Terrorist"; // makes the _Terrorist variable public
PublicVariable "_allButTerrorist"; // makes the _allButTerrorist variable public

Read that.

  • Like 1

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

×