Home   Help Search Login Register  

Author Topic: Run addAction on clients through AddOn?  (Read 2548 times)

0 Members and 1 Guest are viewing this topic.

Offline Inkompetent

  • Members
  • *
Run addAction on clients through AddOn?
« on: 05 Feb 2008, 14:19:07 »
Hellosie!

Bumped into quite a problem here, where I suspect I will have to split my mod into one AddOn and one script part.

First of all I'm adding and modifying weapons, ammunition and characters. This needs an addon as far as I know (correct me if I'm wrong).

Secondly I want to run addAction on all clients (to use the above objects) that I understood have to be executed locally.

So now to the real question: Is there any workaround that can be put in an addon so that I can run the addAction command on a client (since the Init event handler doesn't do the job) without adding any scripts or command lines to a mission, or will I have to run part of my addon through the init.sqs and alike to get it all to work?

/ Inkompetent

Offline Loyalguard

  • Former Staff
  • ****
Re: Run addAction on clients through AddOn?
« Reply #1 on: 05 Feb 2008, 15:25:33 »
I am curious about the addAction not working with an init EH.  I am not automatically doubting you, but, I was unaware of any problems like this.  What do you mean by "Init event handler doesn't do the job"?  Do you get an error, does it not work at all, does it partially not work?

Before moving on to other solutions I want to make sure we exhaust all possible init EH solutions first.


Offline Inkompetent

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #2 on: 05 Feb 2008, 15:57:25 »
It seems to me like the init event handler only runs on the server.

When playing single player all works as it should. When hosting multiplayer all works as it should. But when I host a dedicated server and join it, or when a friend joins my non-dedicated server it doesn't work as it should.

The addon never runs the script I call with the init event handler for clients.

Offline Loyalguard

  • Former Staff
  • ****
Re: Run addAction on clients through AddOn?
« Reply #3 on: 05 Feb 2008, 16:44:16 »
Ok, I assume that this is only a problem for addAction because it requires local arguments and has local effects AND most likely your object is only local on the server...so...here are a couple quick ideas while I look into the local/global issue some more to see if that is correct:

1) Use the init EH in class EventHandlers to to create a trigger at the location of the object (and maybe that adds the addAction to the object.  A trigger created with createTrigger should be local on the server and all clients.

2) This one is more of a question really... Does anyone know if you can use class UserActions in a config for an action.  I have seen it used for animation related actions but I am not sure if other things can be done with it.

Another question for you, Inkompetent, if you don't want to share what exactly you are working on I understand, but can you describe what kind of "uses" you are trying for when you say "to use the above objects".  That may help us determine if there are other methods available to us.
« Last Edit: 05 Feb 2008, 16:45:54 by Loyalguard »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Run addAction on clients through AddOn?
« Reply #4 on: 05 Feb 2008, 16:44:58 »
AFAIK init event handler is global, excuted in all connected machines for a particular vehicle as soon as it is created. For soliders the behaviour is a bit different, if a soldier starts inside a vehicle, the init EH is executed as soon as the unit gets out it.

Offline Inkompetent

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #5 on: 05 Feb 2008, 17:38:26 »
Thanks for the suggestion about the trigger. I could try to create a map-covering trigger which executes the base script on all units.


And what I'm trying to do. It is for the Real M136 addon. I wanted to take it a step further by letting you carry multiple M136 launchers, as well as carrying launchers together with machineguns.

For maximum compatibility I simply altered the basic M136. That way people won't have to change their missions to use my one shot launchers.

What I do is that I've made the M136 use ammo slots (this way you can pick up an M136 if you already carry another launcher classed weapon).
Upon unit initialization replace any carried M136 with my Inko_M136 (which is identical to the original M136, configwise) and I remove all excess rockets.

This script calls the main script that I run looping on all units. The loop checks if you hold an M136 (if you do it replaces it with a placeholder), the Inko_M136_Placeholder (the dummy object for the extra M136 you can carry) and adds/removes the appropriate actions (equip extra launcher, and dump empty tube).


I thought it was as you say, Mandoble, but I can't get it to function that way. Maybe I've just done something wrong though, but since it do run properly on the server and at least the "fired" EH works on the clients I dunno what it would be that's at fault.


The only other thing that doesn't work properly at the moment is that the M136 when picked up doesn't use the four slots of inventory space I've defined it to use and also is invisible, which I assume is because it is a weapon assigned to a magazine slot.
Since I can't redefine the weapon to a magazine, and I don't know how to prevent someone from picking up an object (since there is no event handler for it) I'm quite clueless how to solve this one.

Offline Loyalguard

  • Former Staff
  • ****
Re: Run addAction on clients through AddOn?
« Reply #6 on: 05 Feb 2008, 17:52:05 »
Have you checked out CSL Weapon Switching by ColonelSandersLite?  There are several aspects to his excellent script which may apply to what you are trying to do (multiple weapons, AT and MG, etc.).  Even if it is not what you need it may give you some ideas on implementing some of the features you are looking for.
« Last Edit: 05 Feb 2008, 17:53:40 by Loyalguard »

Offline Inkompetent

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #7 on: 05 Feb 2008, 18:14:45 »
I'll do one simple thing to change the MGs.

The class MGunCore has its type defined as type = 1 + 4, i.e. primary weapon and and launcher weapon. I'll simply redefine that to type = 1 and you can carry launchers together with them.

I did look at that weapon switching quite early in the process, and even though I didn't pick anything from it the code was a nice lesson in programming. Smartly done and a good way to learn how to memorize, transform and transfer data between scripts.


Edit:
And now I'm of course running into more problems. I can't figure out how to call my script with the trigger I create. I get an error about missing a "]" in my setTriggerStatements line, but I sure can't figure where.

Neither
Code: [Select]
_trg setTriggerStatements["this","_this execVM "inko_real_m136x\scripts\init_m136.sqf";"]; or
Code: [Select]
_trg setTriggerStatements["this","_this execVM "inko_real_m136x\scripts\init_m136.sqf";",""]; works, and neither does it if I strip out the ";" from after the execVM.

Hilfe!
« Last Edit: 06 Feb 2008, 09:17:18 by Inkompetent »

Offline Tajin

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #8 on: 06 Feb 2008, 13:54:47 »
The nested quotes are the Problem.

try one of these:
Code: [Select]
_trg setTriggerStatements["this","_this execVM ""inko_real_m136x\scripts\init_m136.sqf"" "];
Code: [Select]
_trg setTriggerStatements["this","_this execVM 'inko_real_m136x\scripts\init_m136.sqf' "];

Offline Inkompetent

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #9 on: 08 Feb 2008, 16:45:06 »
Thanks, and that problem was solved.

After lots of trying and searching I can't get any return data from the created trigger other than a boolean return though, looking like this:
Code: [Select]
Error in expression <.sqf"
private ["_unit"];

_unit = _this select 0;

if (_unit hasWeapon "M136") t>
  Error position: <select 0;

if (_unit hasWeapon "M136") t>
  Error select: Type Bool, expected Array,Config entry

The code it refers to is the following:
Code: [Select]
private ["_unit"];

_unit = _this select 0;

if (_unit hasWeapon "M136") then {
_unit removeWeapon "M136";
if (_unit hasWeapon "Inko_M136") then {
_unit addMagazine "Inko_M136_Placeholder";
}
else {
_unit addWeapon "Inko_M136";
};
};
_this execVM "inko_real_m136x\scripts\action_m136.sqf";

The script creating the trigger calling the "init_m136.sqf" looks like this:
Code: [Select]
if (isServer) then {
_trg = createTrigger["EmptyDetector",[0,0,0]];
_trg setTriggerArea[20000,20000,0,true]; // Width, Height, Angle, Rectangle?
_trg setTriggerActivation["ANY","PRESENT",true]; // Activated by, activated how, repeating?
_trg setTriggerStatements["this","this execVM ""inko_real_m136x\scripts\init_m136.sqf"" ",""];
};

Now, what the heck is wrong with this, causing me to only get a boolean return from the trigger rather than an array for the unit triggering it?

Oh, and another thing? Would I need to increase the trigger size to 40000x40000 since I create the trigger in the upper left corner (?) of the map? I'm not quite sure how the trigger is created, but I guess it might expand in both directions for the X and Y axis and not only in one direction?
« Last Edit: 08 Feb 2008, 16:49:38 by Inkompetent »

Offline Sick

  • Members
  • *
    • Dev-Heaven.net
Re: Run addAction on clients through AddOn?
« Reply #10 on: 12 Feb 2008, 12:00:44 »
The trigger stuff doesn't work because THIS contains the trigger afaik, and not the unit who triggers it.
In case you want to do something with the units inside the trigger (grab array of units):
  • within the onactivation/deactivation/condition fields you must use ThisList variable
  • inside scripts or other fields, you can use: list TRIGGERNAME
You can create the trigger in the middle of the isle by using: getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition")
In any case, I would stop bothering with triggers etc :)

The init EventHandler fires on every computer; Server, Ded Server, Client, JIP Client.
The only difference is the time it fires, afaik:
  • Server/Ded Server fire it before the clients/jip clients do
  • Clients fire it before jip clients do (logically because jip clients connect later :p)

I'll look into the scripts and figure out why it doesn't work as it should in MP.


Changeset with fixes/optimizations, however importance was on fixing, there might still be stuff left to optimize :D
http://trac.6thsense.eu/arma/changeset/53
« Last Edit: 12 Feb 2008, 13:12:04 by Sick »

Offline Inkompetent

  • Members
  • *
Re: Run addAction on clients through AddOn?
« Reply #11 on: 12 Feb 2008, 12:17:16 »
Thank you very much! The sooner I get this sorted the better since I think that it is what I try to achieve with v2 is what people actually would like to see in the addon.

Next step will be properly working attack helicopters methinks. Hmm... :scratch:


Edit:
Great thanks to Sickboy for helping, schooling me in how ArmA executes stuff and general pondering! Got it to work as it should in the end. Just one little thing to add (I think  ???) and this little baby will be put up for release!
« Last Edit: 12 Feb 2008, 19:39:44 by Inkompetent »