Home   Help Search Login Register  

Author Topic: autostart script in addon on mission start ?  (Read 4705 times)

0 Members and 1 Guest are viewing this topic.

Offline nuxil

  • Members
  • *
autostart script in addon on mission start ?
« on: 20 Sep 2010, 11:09:38 »
Hello good people.

i have a question.

lets say i have a serveraddon abc

is it possible to make addon abc to autostart a bunch of scripts each time a mission starts ?
so instead of editing 100 missions + upcomming missions with the execution of my scripts in addon abc.
is it possible to do what i want ?


Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: autostart script in addon on mission start ?
« Reply #1 on: 20 Sep 2010, 13:00:27 »
What kind of autostart? The kind of autostart wherein EVERY mission starts these scripts (e.g. VFAI, DSAI, etc.) or the kind of autostart wherein you put down a module (F7) and that starts the scripts (e.g. all the default BIS modules, Mando Missile etc)? The first one requires you to use CBA whereas the second is as simple as configuring an init eventhandler on a game logic. Here's an example of that (just paste into a config.cpp file and compile the pbo together with your scripts):

Code: [Select]
class CfgPatches
{
class YOURTAG_Addon
{
units[] = {};
weapons[] = {};
requiredVersion = 1.05;
requiredAddons[] = {""};
};
};


class cfgvehicles
{
class Logic;


    class YOURTAG_Name  : Logic
    {
        displayName = "Name of module";
        icon = "\ca\ui\data\icon_functions_ca.paa";
        picture = "\ca\ui\data\icon_functions_ca.paa";
        vehicleClass = "Modules";

        class Eventhandlers  {
            init = "(_this select 0) execvm ""YourScript.sqf"" ";
        };
    };

};

Simply add YourScript.sqf to the addon and it should work out all right. If you have a bunch of scripts, simply have it run an init script which in turn starts all the others :) (or have many logics). You can also have regular folder paths and stuff, just use /scriptfolder/script.sqf.

The CBA method is kind of similar, but slightly more complicated, but check out CBA for documentation on that :)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: autostart script in addon on mission start ?
« Reply #2 on: 20 Sep 2010, 13:09:54 »
PS: Styling wise you may want to use quotes in single quotes or the other way round.

"Text ""Quotes in the Text"" End"
=>
"Text 'Quotes in the Text' End"
or
'Text "Quotes in the Text" End'

Offline nuxil

  • Members
  • *
Re: autostart script in addon on mission start ?
« Reply #3 on: 21 Sep 2010, 18:57:25 »
Hi Wolfrug and thanks for your reply.

i tried to look at the cba doc. but could not really find what i was looking for,
maybe you could point me ;p
also i dont want to rely on a 2nd addon for mine to work. but if no other way then i'll have to.

the 2nd methode you said. about using modules.
im not sure i understood it correct.

if i make a module doesnt both the server & client need the addon?

the thing is i only want the server sided scripts in the addon to autostart.
my addon is just a pack of scripts.

at the moment i am editing every missions init file and adding the path to my server addon init script
i find this methode a really shitty one. i dont want to edit every #!!# mission to run my server scripts :p


i been googeling a bit. but coulnt really find anything related.
i found this post here.
http://dev-heaven.net/boards/23/topics/show/1537

so i tried make/editing my vehicle config file for the server addon
to like
Code: [Select]
class CfgVehicles
{
    class All;
    class AllVehicles;
    class Land;
    class Man : Land
    {
        class Eventhandlers 
        {
            init = '[] execvm "\myaddon\sqf\init.sqf"';
        };
    };
};

but this didnt work. i seams like init.qsf never got executed.
maybe this was because the ai's on the missions i tested it with was greated localy.donno.



Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: autostart script in addon on mission start ?
« Reply #4 on: 21 Sep 2010, 19:45:03 »
Config EH overwrite each other. This is the reason to use CBA/XEH.

Offline nuxil

  • Members
  • *
Re: autostart script in addon on mission start ?
« Reply #5 on: 22 Sep 2010, 01:22:53 »
ok thanks kju.
i didnt know Config EH overwrite each other.

i'll look into the cba docs a bit more.


btw. about your styling you posted earler. i does matter sometimes.
i found out that when i deal with dialogs i somethimes need to use "foo = ""bar"""
example
Code: [Select]
class MY_BUTTON : BUTTON
{
    text = "my button";
    action = "myvar = ""test"";PublicVariable ""myvar""";
}
using
Code: [Select]
action = "myvar = 'test';PublicVariable 'myvar'";
action = 'myvar = "test";PublicVariable "myvar"';

would not work..
« Last Edit: 22 Sep 2010, 02:36:30 by nuxil »

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: autostart script in addon on mission start ?
« Reply #6 on: 22 Sep 2010, 08:53:41 »
Hm weird. These work for me:

Code: [Select]
    onLoad = "[] execVM 'features\bon_artillery\dialog\bon_initartillery.sqf';";
    onUnload = "if (AAS_ArtyDialogOpen) then {player execVM 'features\bon_artillery\bon_arti_cancle.sqf';};";

Code: [Select]
action = "[99,player] execVM 'cClickSpawnButton.sqf';";


XEH is actually pretty easy. The best way to get into it is to look at examples (as always).
Basically for the simple usage you only need to convert your config EH to the XEH format.

A few examples:

Code: [Select]
class Extended_Init_EventHandlers
{
 class Man
 {
  DisableBasicConversationsForAnyUnit_Gameplay_C_PROPER_Man_Init = "{_x setVariable ['BIS_noCoreConversations', true];} foreach allUnits;";
 };
};

Code: [Select]
class Extended_PreInit_EventHandlers
{
 PROPER_EasyFly_Planes_preinit = "PROPER_EasyFly_Planes_by_Celery_Plane_Init_Pre = compile preprocessFileLineNumbers '\EasyFly_Planes_by_Celery_Gameplay_C_PROPER\CLY_EasyFly.sqf'";
};
class Extended_Init_EventHandlers
{
 class Plane
 {
  PROPER_EasyFly_Planes_by_Celery_Init_Plane = "[] spawn PROPER_EasyFly_Planes_by_Celery_Plane_Init_Pre;";
 };
};
class Extended_GetIn_Eventhandlers
{
 class Plane
 {
  PROPER_EasyFly_Planes_by_Celery_GetIn_Plane = "if (player == (_this select 2)) then { [] spawn PROPER_EasyFly_Planes_by_Celery_Plane_Init_Pre };";
 };
};

Code: [Select]
class Extended_PreInit_EventHandlers
{
 PROPER_ToughChopperRotor_preinit = "PROPER_ToughChopperRotor_Init_Pre = compile preprocessFileLineNumbers '\ToughChopperRotor_Gameplay_C_PROPER\PROPER_ToughChopperRotor.sqf'";
};
class Extended_Init_EventHandlers
{
 class Helicopter
 {
  PROPER_ToughChopperRotor_Helicopter_Init = "[] spawn PROPER_ToughChopperRotor_Init_Pre;";
 };
};
class Extended_GetIn_Eventhandlers
{
 class Helicopter
 {
  PROPER_ToughChopperRotor_Helicopter_Init = "if (player == (_this select 2)) then {[] spawn PROPER_ToughChopperRotor_Init_Pre;};";
 };
};

So there is not really much magic involved (unless you use the additional powerful spells available in XEH too).  :)

Offline nuxil

  • Members
  • *
Re: autostart script in addon on mission start ?
« Reply #7 on: 25 Sep 2010, 12:36:22 »
hmm. seams easy enough. but i cant get it to work.

on my server i placed @cba in my arma2 install dir.
using mod parm. mod=@cba;@myserveraddon on the server startup.

i see the rpt log says.

[7877,115.793,0,"XEH: PreInit Started"]
[7877,115.91,0,"MISSINIT","-British_Army_Forces-co30_Domi","Takistan",true,true,true]
[7877,116.435,0,"XEH: PreInit Finished"]

so im assuming the init xeh is started.

config.cpp
Code: [Select]
#include "CfgPatches.hpp"
#include "Extended_Init_EventHandlers.hpp"

CfgPatches.hpp
Code: [Select]
class CfgPatches {
class MyServerAddon
{
units[] = {};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {};
version = 0.1;
fileName = "myserveraddon.pbo";
author = "";
mail = "";
};
};

Extended_Init_EventHandlers.hpp
Code: [Select]
class Extended_Init_EventHandlers {
class Man
{
My_Man = '[] execvm "\myserveraddon\sqf\init.sqf"';
};
};

i cant get this to work.

when i connect to my server it says im missing cba_main..
thats really anoying. since i want it to be server sided only. and clients should not need to get such message, since they dont depend on it.

but anyway. if i put
Code: [Select]
if ((isServer) or (isDedicated)) then
{
    nil = [] execvm "\myserveraddon\sqf\init.sqf";
};
in the init of a mission it works like a charm.
so where am i doing wrong here??

should i use class Extended_PreInit_EventHandlers instead?
with
serverInit = "[] execvm '\myserveraddon\sqf\init.sqf';";


im verry confused here.
« Last Edit: 25 Sep 2010, 13:11:33 by nuxil »


Offline nuxil

  • Members
  • *
Re: autostart script in addon on mission start ?
« Reply #9 on: 25 Sep 2010, 15:52:11 »
ahh nice..
i got it working now.

only problem i now have is the message i get by cba.
YOU ARE MISSING THE FOLLOWING MOD: CBA_MAIN

is there a way to disable this ?

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: autostart script in addon on mission start ?
« Reply #10 on: 25 Sep 2010, 20:23:06 »
Try to remove the CBA_versioning.pbo or cba_diagnostic.pbo on the server.