Results 1 to 8 of 8

  Click here to go to the first Developer post in this thread.  

Thread: How to make this code run once only?

  1. #1
    Staff Sergeant Acelondoner's Avatar
    Join Date
    Apr 8 2010
    Location
    The clue is in my username ;)
    Posts
    296

    How to make this code run once only?

    I have this bit of code which will load objects into vehicles using r3f logistics.

    I'm having trouble as it runs once for every player so instead of placing 24 fuel cans, it places 48 when two players, 72 when three players etc. Anyone know how to make it run only once on the server and not for each player?

    startpreload.sqf
    Code:
    [fuelcontainer1, [fuel1,fuel2,fuel3,fuel4,fuel5,fuel6,fuel7,fuel8,fuel9,fuel10,fuel11,fuel12,fuel13,fuel14,fuel15,fuel16,fuel17,fuel18,fuel19,fuel20,fuel21,fuel22,fuel23,fuel24]] execVM "preload.sqf";
    preload.sqf
    Code:
    // LOG module needs to be running for this to work
    waitUntil {!isNil "R3F_LOG_PUBVAR_point_attache"};
    
    private ["_objectArray", "_vehicle", "_currentItems"];
    
    // Parameters
    _vehicle = _this select 0;
    _objectArray = _this select 1;
    
    // Add items to the vehicle
    _currentItems = [];
    _currentItems = _vehicle getVariable "R3F_LOG_objets_charges";
    if (isNil "_currentItems") then {_currentItems = []};
    _currentItems = _currentItems + _objectArray;
    
    _vehicle setVariable ["R3F_LOG_objets_charges", _currentItems, true];
    
    // This block of code comes from R3F_ARTY_AND_LOG\R3F_LOG\transporteur\charger_deplace.sqf
    // Absolutely all credit goes to R3F and madbull
    {
        private ["_position_attache", "_nb_tirage_pos"];
        _position_attache = [random 3000, random 3000, (10000 + (random 3000))];
        _nb_tirage_pos = 1;
        while {(!isNull (nearestObject _position_attache)) && (_nb_tirage_pos < 25)} do
        {
            _position_attache = [random 3000, random 3000, (10000 + (random 3000))];
            _nb_tirage_pos = _nb_tirage_pos + 1;
        };
        
        _x attachTo [R3F_LOG_PUBVAR_point_attache, _position_attache];
    } forEach _objectArray;
    MISSIONS
    [co4] Delta Rescue Released | [co8] Infestation Released | [co12] Battle of Mogadishu (Black Hawk Down) Coming Soon
    Like Dubstep?

  2.   This is the last Developer post in this thread.   #2
    Code:
    if (isServer) then
    {
    	hint "yay!";
    };
    Or:

    Code:
    if (local _this) then
    {
    	hint "yay!";
    };
    Last edited by Mondkalb; Jan 17 2012 at 12:12.

  3. #3
    Staff Sergeant Acelondoner's Avatar
    Join Date
    Apr 8 2010
    Location
    The clue is in my username ;)
    Posts
    296
    Author of the Thread
    The above doesn't work. It still runs once for each player.
    Last edited by Acelondoner; Jan 17 2012 at 12:54.

  4. #4
    In your activation surround your "on act" code with: if (isServer) then {ORIGINAL CODE HERE};

  5. #5
    Staff Sergeant Acelondoner's Avatar
    Join Date
    Apr 8 2010
    Location
    The clue is in my username ;)
    Posts
    296
    Author of the Thread
    I did this
    Code:
    if (isServer) then {null = execVM "startpreload.sqf"};
    and the trigger is not set to repeated but it still runs once for each player.

  6. #6
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    one way to make sure something is only run once on server even when players JIP is to assign a variable and check if its there, then dont do anything:

    for example you run a script from init.sqf:
    Code:
    [] execVM "someScript.sqf";
    now in someScript.sqf you start withg this:
    Code:
    if (!isNil "myCustomGlobalVariable" OR !isServer) exitWith {};  // meaning if the variable myCustomGlobalVariable is already created or if its not server, exit without doing nothing.
    myCustomGlobalVariable = true;  // we are now on server, and the variable have been created first time, every other attempt to run it will exit without nothing happening.
    
    // Your code here.
    My scripts:
    Spoiler:

    what to do when posting any kind of code dammit!!

    Any new mission editor or scripter in Arma2 should have read Mr Murrays Editing Guide Deluxe at least once, it still applies for A2 even though it was made for Armed Assault.

  7. #7
    Staff Sergeant Acelondoner's Avatar
    Join Date
    Apr 8 2010
    Location
    The clue is in my username ;)
    Posts
    296
    Author of the Thread
    Thanks Demonized, that sorted it

  8. #8
    So that someone doesn't get wrong impression from this thread, isServer check in a trigger will work as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •