Jump to content
Sign in to follow this  
Guest

deleting ammo from crates

Recommended Posts

Guest

Hi all.

My script is creating crates on server only, also the script removes the ammo from the crates. That works...........

However, it doesnt work in MP. Clients of the dedi can see the crates and the crates are still filled with ammo.

It seems the script only deletes the ammo locally on the server and not on the clients.

In the prievew mode of the editor the ammo gets deleted just as it should so it works.

As a possible solution I add all created crates to an array.

All clients exit the main script  and go to a side script which is checking the said array for ammorcates. As soon as the main script has completely finished the cliens will remove the ammo from the crates by checking that array.

This works in the editor as well, but still not in MP (dedicated server).

In MP it doesnt recognize the created array although it does when tested in the preview in editor.

Anyone has an idea how I can delete ammo from crates on clients computers while the crates are created on the server only?

[addon]

Just to clearify.

The created array is created (GRF_total_ied_array = []) before the clients exit, so they recognize the array.

However they can not see any additions the script added to that array at a later point), logical yes indeed. But how can I make the clients be able to read the array?

Share this post


Link to post
Share on other sites

If the crates are named like ammo1, ammo2, ammo3 etc. You can then use the last number (or count) to delete ammo locally on clients. Pass the number to everyone by publicvariable.

ammoCount = count GRF_total_ied_array;

publicvariable "ammoCount";

Catch it with a trigger

cond: ammoCount > 0

onact: run script that loops through numbers up to the count, while emptying crates

Share this post


Link to post
Share on other sites
Guest
If the crates are named like ammo1, ammo2, ammo3 etc. You can then use the last number (or count) to delete ammo locally on clients. Pass the number to everyone by publicvariable.

ammoCount = count GRF_total_ied_array;

publicvariable "ammoCount";

Catch it with a trigger

cond: ammoCount > 0

onact: run script that loops through numbers up to the count, while emptying crates

You got me  huh.gif

The script creates ammocrates, they dont have a name.

I can assign them a variable name with the new "setvehiclevarname" but I dont understand how I could make the script loop all counted numbers and know those numbers represent a crate.

Maybe:

I give them a name like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_i=0

GRF_name = "GRF"

GRF_name = GRF_name+format ["%1",_i]

_i = _i + 1

goto "loop"

The above is missing some offcourse but I think you know what I mean wink_o.gif

But........how do I now check their names in the other script?

Share this post


Link to post
Share on other sites

I tried creating boxes and then naming them with setvehiclevarname, but was unable to get it to work. At least, so that it would accept clearweaponcargo etc. So, unless someone can shows a working example, we gotta think of another work around.

Share this post


Link to post
Share on other sites
Guest
I tried creating boxes and then naming them with setvehiclevarname, but was unable to get it to work. At least, so that it would accept clearweaponcargo etc. So, unless someone can shows a working example, we gotta think of another work around.

Yeah, thats exacty what I couldnt do neither, you can assign a name to a created object but still not refer to it.

If you read the command "vehiclename" you will see that setvehiclevarname is meant to change the name set in the editor. So I think its not meant to actually assign names to script created objects/units.........sadly enough.

You can make an array of those name, but checking anything other than the names wont work.

Or at least, all of the above is my experience after trying to get this ammo deleting thing to work for many days now.

Share this post


Link to post
Share on other sites

Do they have to be created on server? Since theres createVehicleLocal

Share this post


Link to post
Share on other sites
Guest

Yes its mandatory the main script (and so the "createvehicle") are done/executed on the server only.

Share this post


Link to post
Share on other sites

Sending arrays can be done with clever scripting:

init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">var_forever = true;

channel execVM "receiveArray.sqf";

sendArray.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_array","_channel","_count","_i"];

_array = _this select 0;

_channel = _this select 1;

_count = count _array;

call compile format ["var_sendArray%1Count = _count; publicVariable ""var_sendArray%1Count""",_channel];

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

{

call compile format ["var_sendArray%1Value%2 = _array select _i; publicVariable ""var_sendArray%1Value%2""",_channel,_i];

};

call compile format ["var_sendArray%1 = true; publicVariable ""var_sendArray%1""",_channel];

receiveArray.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_channel","_array","_i","_count"];

_channel = _this;

while {var_forever} do

{

call compile format ["waitUntil{var_sendArray%1}",_channel];

call compile format ["var_sendArray%1 = false",_channel];

_array = [];

call compile format ["_count = var_sendArray%1Count",_channel];

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

{

call compile format ["_array = _array + [var_sendArray%1Value%2]",_channel,_i];

};

call compile format ["var_receivedArray%1 = _array",_channel];

};

If you want to send an array, you use

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[your_array,channel] call compile loadFile "sendArray.sqf"

your_array - Simply array you want to send smile_o.gif

channel - Channel you want to use. This appears also in init.sqf script - I`ll explain it on example:

You want to send an array - you must as first run receiveArray.sqf with wanted channel on each client (let`s say it will be 1), so you type

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">1 execVM "receiveArray.sqf"

And when you will want to send that array, you locally (on server for example) use

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[myArray,1] call compile loadFile "sendArray.sqf"

And the array will become available on all clients under variable "var_receivedArray1". If you will set channel to 2, you`ll get it on "var_receivedArray2".

The reason why I made these channels is to make possible to send more arrays in same time and also it becomes important in presence of lag. So for channel 1 use for example only ammoboxes array, channel 2 something else and so.

I hope you understand what I mean and I hope it will work. wink_o.gif

Share this post


Link to post
Share on other sites
Guest

Now thats something smile_o.gif

I understand it (even though this kind of clever scripting is out of my league to make) and will try it here, thank you very much for this. thumbs-up.gif

Will get back here with the results smile_o.gif

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  

×