Jump to content
Sign in to follow this  
diraven

Some questions about the Arma 2 scripting engine.

Recommended Posts

At first tnanks a lot for not banning me for questions probably already answered here on this forum. I've used search but unhopefully found nothing, so posting here.

I have got next questions during the make of my first big project:

1) How can I delete vehicle from the gameworld with the driver inside? When I use deleteVehicle on the vehicle with the driver created in the editor vehicle disappears and driver falls down. =) I want him disappear aswell.

Do the driver of the created vehicle have the same group as the entire vehicle? If so - can I delete both vehicle and driver with something like:

// If I want to delete _the_unit_to_be_deleted with the dirver inside:
_units_list = units group _the_unit_to_be_deleted;
"deleteVehicle _x" forEach _units_list;

Ore something like that. For me it did not work. =(

2) How can I create markers only visible to one side and invisible for another (multiplayer).

3) Can I create separate introes, separate briefings and objectives for different sides? (multiplayer)

and one more

4) Can I make squad-specific respawn markers? So only one group will be spawning there. And if so is there any way to grant user an ability to choose his spawn location? For exampla base or this squad-specific marker.

Edited by DiRaven

Share this post


Link to post
Share on other sites

The first one is easy, so I'll answer that.

Use the 'crew' command to get an array of whoever is in the vehicle.

_crew=crew myvehicle;

{deletevehicle _x} foreach _crew;

The rest gets more complex, and as I don't usually do MP stuff I'll let someone else help with that.

By the way this is the ArmA section, not ArmA 2. Maybe a mod can move this thread for you.

Edit: Looks like it was moved.

Edited by Maddmatt

Share this post


Link to post
Share on other sites

Check out the Arma1 scripting topics, especially the sticky ones on the top:

Arma1 Scripting Topics

You'll quickly learn that scripting for multiplayer can be tricky, especially of you're new to the language and locality issues of the commands.

2) I've never done it, as I'm into coops only. But I'll suggest downloading some Arma1 multiplayer missions and see how its done.

3) See #2.

4) As for respawn, I'd go with base respawn for each side. After respawn you can teleport the player to the position of the current leader of the squad or a location of your choosing if the position is to be dynamic.

Welcome and good luck. Jumping straight into multiplayer editing is bold :)

Share this post


Link to post
Share on other sites

You also can take a look into Mr-Murray Editing Guide. There´s a bunch of information in it. A book for A2 will follow later but you can use it as well.

You find the book in my signature...

Share this post


Link to post
Share on other sites
2) How can I create markers only visible to one side and invisible for another (multiplayer).

Create the markers via script. Create them local and check the side of the player.

if (side player==west) then {
_marker = createmarkerlocal getpos westbase;
} else {
_marker = createmarkerlocal getpos eastbase;
};

3) Can I create separate introes, separate briefings and objectives for different sides? (multiplayer)

Yes , Dont Know, Yes.

For seperate intro and objective for each side just place a "sidecheck" like the markerthing in the introcamscript or the init/script that activates the objectives.

I think there was a way to make briefings for each side since OFP, but i cant remember it anymore.

4) Can I make squad-specific respawn markers? So only one group will be spawning there. And if so is there any way to grant user an ability to choose his spawn location? For exampla base or this squad-specific marker.

Place a script called onplayerkilled.sqs in your mission directory. It will execute if the player dies.

Write

waituntil {alive player};

in the script. If the player dies, the script will wait until he respawn. After that you can simply make a setpos to another location or do anything else with the repawned player.

Share this post


Link to post
Share on other sites

Ou dear... Thanks for answers... Big sorry for the delay, had problems with the internet almost a week. I will check all the tips asap. Thanks again. =)

---------- Post added at 01:14 PM ---------- Previous post was at 12:25 PM ----------

Check out the Arma1 scripting topics, especially the sticky ones on the top:

Arma1 Scripting Topics

ou'll quickly learn that scripting for multiplayer can be tricky, especially of you're new to the language and locality issues of the commands.

Will do. Thanks. =)

2) I've never done it, as I'm into coops only. But I'll suggest downloading some Arma1 multiplayer missions and see how its done.

Already done. Coding styles are very different. And my goal is to find good solution which will be reworked and reused, not that "copy-paste" programming.

3) See #2.

4) As for respawn, I'd go with base respawn for each side. After respawn you can teleport the player to the position of the current leader of the squad or a location of your choosing if the position is to be dynamic.

Welcome and good luck. Jumping straight into multiplayer editing is bold :)

Thanks again. =) I'm working on a huge project that looks like Domination but is more complex.

You also can take a look into Mr-Murray Editing Guide. There´s a bunch of information in it. A book for A2 will follow later but you can use it as well.

You find the book in my signature...

Downloading. Thanks.

Create the markers via script. Create them local and check the side of the player.

if (side player==west) then {
_marker = createmarkerlocal getpos westbase;
} else {
_marker = createmarkerlocal getpos eastbase;
};

Will check it out. It is the way I thought it to be done. Just expected there are already ready functions like "Add marker for OPFOR" =)

Place a script called onplayerkilled.sqs in your mission directory. It will execute if the player dies.

Write

waituntil {alive player};

in the script. If the player dies, the script will wait until he respawn. After that you can simply make a setpos to another location or do anything else with the repawned player.

Perfect tip. Thanks a lot.

---------- Post added at 01:19 PM ---------- Previous post was at 01:14 PM ----------

The first one is easy, so I'll answer that.

Use the 'crew' command to get an array of whoever is in the vehicle.

_crew=crew myvehicle;

{deletevehicle _x} foreach _crew;

Exactly what I asked. Big thanks. =)

Share this post


Link to post
Share on other sites
Originally Posted by NeoArmageddon

Place a script called onplayerkilled.sqs in your mission directory. It will execute if the player dies.

Write

Code:

waituntil {alive player};

in the script. If the player dies, the script will wait until he respawn. After that you can simply make a setpos to another location or do anything else with the repawned player.

Thats wrong! I forgot, that onplayerkilled.sqs just works if the player dies permanently. I just ave the problem on an own map. But there is another solution.

Write in you init.sqf:

_handlerid = player addEventHandler ["killed", {_this execVM "playerkilled.sqf"}];

This will work, like my mentioned above. Here is my "playerkilled"-script for comparision/copying:

waituntil {(alive player)};

if (side player==East) then {

player setpos getpos Jail;

} else {

_spawns=MBG_locsReal-[Logic_6];
_sp = _spawns select floor(random(count(_spawns)));
player setpos getpos _sp;

};

Share this post


Link to post
Share on other sites
You also can take a look into Mr-Murray Editing Guide. There´s a bunch of information in it. A book for A2 will follow later but you can use it as well.

You find the book in my signature...

Have read this stuff hardly. Really awesome work... Covers a lot of my questions. Thanks once more.

Share this post


Link to post
Share on other sites

Got next question.

While trying to execute:

for "_i" from 0 to 9 do
{
   player globalChat format["%1",_i];
};

I'm always getting result as "Any"... One chat message with the ANY word. Any suggestions?

Share this post


Link to post
Share on other sites

I would use .sqf with

for [{_i=0},{_i<=9},{_i=_i+1}] do {

player globalChat format["%1",_i];

};

With this method _i mussnt be initialized with private.

Share this post


Link to post
Share on other sites

u mean I should write something like

private "_i";
for "_i" from 0 to 9 do
{
   player globalChat format["%1",_i];
};

?

That does not work aswell.

With the following:

for [{_i=0},{_i<=9},{_i=_i+1}] do {

player globalChat format["%1",_i];

};

Getting the same:

BLUFOR Player: "ANY"

---------- Post added at 11:53 AM ---------- Previous post was at 11:05 AM ----------

Looks like foreach loop can have multiline code block only in "spawn"ed functions.

For example:

{player globalChat format["%1", _x];player globalChat format["%1", _x];} forEach _arr;

Works perfectily in init.sqf and gives perfect result.

And

{
player globalChat format["%1", _x];
player globalChat format["%1", _x];
} forEach _arr;

Does not, causing player to say just "ANY", but still works OK in the spawned function.

Is it bug or feature?

Edited by DiRaven

Share this post


Link to post
Share on other sites

Could it be that you're no longer supposed to do loops like this from within a timing 'critical' script like init.sqf? I don't know really, it just sounds like some new limitation. Did you try starting such as script from a trigger or something?

Share this post


Link to post
Share on other sites
Could it be that you're no longer supposed to do loops like this from within a timing 'critical' script like init.sqf? I don't know really, it just sounds like some new limitation. Did you try starting such as script from a trigger or something?

Will try, but later. Now want to give people to test my pra-alpha version. =)

In the meantime I have another question:

How to set unit desctiption (see Editor, unit mode, unit creating/editing dialog) via script?

Share this post


Link to post
Share on other sites

I have no idea. In Arma1 there was no point in doing it, as you couldn't script new or changed slots (afaik). All slots had to be preplaced in the editor, where you also set your descriptions.

Can you now make dynamic slots?

You could try the 3D Editor approach, as it generates a mission.sqf. Check what commands it uses to create playable characters, and if description can be set.

Share this post


Link to post
Share on other sites

As I have tried - absolutely clearly it is possible to _remove_ playable slots without players. Later will try to add some.

Still think it is now possible to add new game slots while game is already running.

Nice tip about the editor. It's still buggy and useless but there is a chance to get an answer to my question.

---------- Post added at 09:49 PM ---------- Previous post was at 09:44 PM ----------

Could it be that you're no longer supposed to do loops like this from within a timing 'critical' script like init.sqf? I don't know really, it just sounds like some new limitation. Did you try starting such as script from a trigger or something?

One more thing... I have noticed that many loop-like commands (if, forEach and so on) works only in one-row-variant in the init.sqf script.

Like:

WRONG

{
 player globalChat format["%1", _x];
 hint format["%1", _x];
} forEach _markers;

RIGHT

{player globalChat format["%1", _x]; hint format["%1", _x];} forEach _markers;

May be this will help me when I will get back to thet piece of code... Still not sure if it is bug or feature?

---------- Post added at 10:09 PM ---------- Previous post was at 09:49 PM ----------

And once more - quick tip. How to execute script on every machine during the MP play? Not at the start via the init.sqf but in progress.

Should it be 0:0 trigger, working for everyone? Or there is another way to do it?

Share this post


Link to post
Share on other sites
One more thing... I have noticed that many loop-like commands (if, forEach and so on) works only in one-row-variant in the init.sqf script.

May be this will help me when I will get back to thet piece of code... Still not sure if it is bug or feature?

This is definately not a feature and I doubt it's broken, because that would mean pretty much none of the scripts in the game would work. The old SQS was line-based, but SQF is not. If you have a case where this is not true, please present it to us :)

Share this post


Link to post
Share on other sites

I'm using SQF ewerywhere now.

Right now have checked next code:

Works fine:

for [{_x=0},{_x<=49},{_x=_x+1}] do {arr_mkr_OPFOR_possibleDeploymentLocations = arr_mkr_OPFOR_possibleDeploymentLocations + ['mkr_OPFOR_possibledeployment_' + format ["%1", _x]];}

Gives "any" value instead of _x:

for [{_x=0},{_x<=49},{_x=_x+1}] do {
 arr_mkr_OPFOR_possibleDeploymentLocations = arr_mkr_OPFOR_possibleDeploymentLocations + ['mkr_OPFOR_possibledeployment_' + format ["%1", _x]];
}

File format - UTF8

Editor - NotePad++ with the ArmaEdit addon

---------- Post added at 01:34 PM ---------- Previous post was at 01:06 PM ----------

BTW multiline (/* comment */) comments do not work aswell.

Share this post


Link to post
Share on other sites

Due to locality I've got another question:

1. How to execute script on the server. So I must be sure that:

- It is executed.

- It is executed by server.

2. How to do the same for the certain group of players. For example for one side, for one group, for all players. And again I must be sure that:

- Script is executed.

- Script is executed by the certain group of players.

The second to my mind can be done using repeating triggers with 0:0 area. But I have no idea how to do first one.

Share this post


Link to post
Share on other sites

Your examples won't work since both are missing a semicolon after the code block.

You might want to take a look at your RPT file. I guess you'll find a lot of answers in there... ;)

Edit: Are you sure you use execVM and not exec to run your scripts?

Edited by Worldeater

Share this post


Link to post
Share on other sites
Your examples won't work since both are missing a semicolon after the code block.

But examples work exactly the way I explained.

You might want to take a look at your RPT file. I guess you'll find a lot of answers in there... ;)

Nothing for now. Just some missing objects.

Edit: Are you sure you use execVM and not exec to run your scripts?

Why do I need to use ExecVM? I don't want this scripts run asynchroniusly and I need their result returnvalue.

And still:

Due to locality I've got another question:

1. How to execute script on the server. So I must be sure that:

- It is executed.

- It is executed by server.

2. How to do the same for the certain group of players. For example for one side, for one group, for all players. And again I must be sure that:

- Script is executed.

- Script is executed by the certain group of players.

The second to my mind can be done using repeating triggers with 0:0 area. But I have no idea how to do first one.

Edited by DiRaven

Share this post


Link to post
Share on other sites
Due to locality I've got another question:

1. How to execute script on the server. So I must be sure that:

- It is executed.

- It is executed by server.

2. How to do the same for the certain group of players. For example for one side, for one group, for all players. And again I must be sure that:

- Script is executed.

- Script is executed by the certain group of players.

The second to my mind can be done using repeating triggers with 0:0 area. But I have no idea how to do first one.

Read this. Use the code provided there.

http://community.bistudio.com/wiki/6thSense.eu:EG#Determining_if_machine_is_Ingame_Server.2C_Ded_Server.2C_Player_or_JIP_Player

Why do I need to use ExecVM? I don't want this scripts run asynchroniusly and I need their result returnvalue.

This is why

exec

exec starts a thread for a script in SQS syntax.

and

The old SQS was line-based, but SQF is not.

So, you are running SQF with an SQS command. So, your multi-line code is not being parsed properly and is giving you problems.

Share this post


Link to post
Share on other sites

Done, thanks. This worth trying.

So, you are running SQF with an SQS command. So, your multi-line code is not being parsed properly and is giving you problems.

And what about init.sqf then?

Share this post


Link to post
Share on other sites

Hard to say without seeing what you are trying to do.

How and where was _arr declared? Is it populated with values before you try and access it? What kind of values? Where are they taken from? etc etc

Share this post


Link to post
Share on other sites
And what about init.sqf then?

init.sqf is executed as sqf but every .sqf script that is executed via exec wont run correctly... Thats the reason why you foreach dont run in more than one line.

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  

×