Jump to content
Sign in to follow this  
alleycat

"this execvm... problem"

Recommended Posts

I am trying to run a script on a soldier (like giving weapons via calling a script. However when I put

this execvm "script.sqf"

in the init line, I get errors. I guess this is some syntax issue?

Share this post


Link to post
Share on other sites

You need to have a script "handle" when doing that, so that you can reach the script while it is running if needed.

The general convention for that, for scripts you don't care if you can reach when they are running or not, is to use "nul" as handle to make it:

nul = this execVM "script.sqf"

Share this post


Link to post
Share on other sites

Why won't it then apply the script to the unit? I wrote in the script:

removeallweapons this;

Share this post


Link to post
Share on other sites

In the init line of the unit put this

null = [this] execVm "script.sqf";

Note the square brackets around "this"

Then at the start of script.sqf put:

_unit = _this select 0;
removeallweapons _unit;

If you have any other lines of code in script.sqf that use 'this' you'll need to replace them with _unit.

If you want this to work in MP you'll need to also add something like

_unit = _this select 0;
if (!local _unit) exitWith {};
removeallweapons _unit;

Share this post


Link to post
Share on other sites

More informations on various "this" versions, where they can be used, and what they mean in various places can be found here.

Share this post


Link to post
Share on other sites

How to call a script that does things which are not connected to anything? Like I want to spawn some bombshells for ambient explosions, which are called in a script from a trigger.

If I do this it won't work:

_nul = this execVM "bomb.sqf"

bomb.sqf:

bomb = "ARTY_Sh_122_HE" createVehicle (getmarkerpos "bombmarker1");

sleep 5;

bomb = "ARTY_Sh_122_HE" createVehicle (getmarkerpos "bombmarker2");

Share this post


Link to post
Share on other sites
How to call a script that does things which are not connected to anything? Like I want to spawn some bombshells for ambient explosions, which are called in a script from a trigger.

If I do this it won't work:

_nul = this execVM "bomb.sqf"

bomb.sqf:

bomb = "ARTY_Sh_122_HE" createVehicle (getmarkerpos "bombmarker1");

sleep 5;

bomb = "ARTY_Sh_122_HE" createVehicle (getmarkerpos "bombmarker2");

Depending on where you are calling this, _nul is a local variable and is alright in a script. If you were calling it from a trigger it has to be a global variable, so cannot start with _

If you don't need to pass anything then exclude the this component which would need square brackets if it was needed anyway.

So from a trigger

nul = execVM "bomb.sqf"

From a script you could use

_nul = execVM "bomb.sqf"

Share this post


Link to post
Share on other sites
I am trying to run a script on a soldier (like giving weapons via calling a script. However when I put

this execvm "script.sqf"

in the init line, I get errors. I guess this is some syntax issue?

Just use:

[this] call compile preprocessfile "script.sqf"

In .sqf file you need to use "private" command to pass the "this" to your script.

private ["_variable"];
_variable = _this select 0;
{rest of the code}

Remember not to use "this" in your script, it is replaced by "_variable". Everything should be ok by now

Share this post


Link to post
Share on other sites

This is confusing. I ran into a similar problem again. Basically I want any player in MP to be able to perform an action on another unit. And that action should call a script that should work absolutely waterproof in mp.

Like, having the unit the script it was attached to say soemthing and then move somewhere:

hostage globalchat "say something.";

hostage move getpos hostagemarker;

I have tried this within scripts but it always causes problems in MP.

Share this post


Link to post
Share on other sites

About globalChat, notice the AG and EL icons at the top, and learn what it means. And here is another source to learn from - important stuff for anyone diving into mission making and scripting for multiplayer - which is not trivial business.

Share this post


Link to post
Share on other sites

Why do simple things have to be so confusing in MP? Also going back on the artillery shell spawning, is there a way to have the shell spawn at a certain elevation without using scripts? I would rather have a simple trigger method instead of having to learn advanced scripting just to have a shell spawn in mid air.

Share this post


Link to post
Share on other sites
This is confusing. I ran into a similar problem again. Basically I want any player in MP to be able to perform an action on another unit. And that action should call a script that should work absolutely waterproof in mp.

Like, having the unit the script it was attached to say soemthing and then move somewhere:

hostage globalchat "say something.";

hostage move getpos hostagemarker;

I have tried this within scripts but it always causes problems in MP.

Hi there,

Remember, actions are local to the player's/unit's machine that clicks it.

Lets say the hostage as an action and I click it in a multiplayer game,. The script will only run on my machine, you just need to make it run on all machines.

This can be easily done using a publicVariable and addPublicVariableEventHandler. Or even more easier with Multiplayer Framework - RE.

_neo_

Share this post


Link to post
Share on other sites

thx for the info.

Also why is this game so painful to work with when it comes to multiplayer? I just had a mission break in coop because apparently the MP code cant take all players starting in a civi truck (moved in in the init file). Works flawlessly in SP.

Share this post


Link to post
Share on other sites
thx for the info.

Also why is this game so painful to work with when it comes to multiplayer? I just had a mission break in coop because apparently the MP code cant take all players starting in a civi truck (moved in in the init file). Works flawlessly in SP.

You think its diferent from any other game alike? Only its simpler in Arma 2 I can tell you that.

:)

_neo_

Share this post


Link to post
Share on other sites

There is no game alike.

btw question:

If I call a script from a trigger, can I assume it is going to work as intended in mp? In a coop I made there was a surprise scripted mortar attack that spawned some shells in the air. It was activated by WEST PRESENT in the TRIGGER and set to ONCE. But every WEST player that stepped onto that trigger caused another barrage (or was the script calling it locally for everyone - 20 players?) And if it is executed locally, why did "global" things like all players experience the now multiplied mortar attack?

Actually I got so paranoid after this that I do almost anything directly in the editor without scripts. Because even the most simple things go wrong in MP in ways not predictable to me.

Share this post


Link to post
Share on other sites

Triggers are local and will fire separately on each machine. What caused the multiple attacks is because you used createvehicle, which creates the shells and syncs them to all players. If you wanted to create them locally, you should use createvehiclelocal.

Share this post


Link to post
Share on other sites

So, if one player fires a trigger, why does not it simply do things globally, because in most cases you want anything happening to be global anway? I mean if a player fires a detected trigger by well, being detected, and the Ai becomes aware, that is a global thing.

Also I do not get what createvehiclelocal was supposed to do. What I wanted was when ANY player steps on a trigger, I want that to start a script that does what is inside the script. And isnt it logical that I want the artillery barrage to fire once and not be multiplied by any other player firing it ALTHOUGH it was set to ONCE?

The whole point of me using a script is because it is easier to read than having it written in a tiny box in the trigger.

To me it feels like everything is loaded locally just to confuse people.

Share this post


Link to post
Share on other sites

If I wanted to create a script that uses many lines of globalchat with sleep delays, can I safely use it from a BLUFOR PRESENT without it multiplying itself on over 20+ players?

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
Sign in to follow this  

×