Results 1 to 8 of 8

Thread: Addaction and [] call

  1. #1

    Addaction and [] call

    Sorry Another MP issue, not sure ill ever get my head around MP!

    This all works great when testing, but as soon as i put it on my hosted server i get no mission.


    Civi unit
    Code:
    this addAction ["Random Mission!", "getamission.sqf"]
    getamission.sqf
    Code:
    [] call SHK_addmission;
    in my INI

    Code:
    if isserver then {
    SHK_addmission = {
      if isserver then {
        if (count SHK_missions == 0) then {
    	player sideChat "Opps Sorry But I have no Intel for you come back next week";
        } else {
          _this spawn {
            private "_t1";
            if (count _this > 0) then {
              _t1 = _this select 0;
            } else {
              _t1 = SHK_missions select (floor random count SHK_missions);
            };
            SHK_missions = SHK_missions - [_t1];
            switch _t1 do {
    	case 0: {
        		nul = [] execVM "missions\1.sqf";
        		};
        	case 1: {
         		nul = [] execVM "missions\2.sqf";
       		};
        	case 2: { 
      		 nul = [] execVM "missions\3.sqf";
       		 };
        	case 3: {
        		 nul = [] execVM "missions\4sqf";
       		 };
            };
          };
        };
      };
    };
    private "_selectedmission";
     missionCount= 4 ;//paramsarray select 4;
    _selectedmission = paramsarray select 5;
    if isserver then {
      private ["_temp1","_t1"];
      _temp1 = [0,1,2,3];
      SHK_missions = [];
      for "_i" from 0 to (missionCount - 1) do {
        _t1 = _temp1 select (floor random count _temp1);
        SHK_missions set [_i,_t1];
        _temp1 = _temp1 - [_t1];
      };
      // first task
      if (_selectedmission < 99) then {
        [_selectedmission] call SHK_addmission;
      } else {
        [] call SHK_addmission;
      };
    };
    };

    If i place
    Code:
    [] call SHK_addmission;
    in a radio trigger and test on MP it all works great !

    So I presume it is something to do with the addaction ?

    Why o Why can things not be easy

  2. #2
    How about,

    getamission.sqf

    Code:
    bob =[]call SHK_addmission;
    I believe you need a handle. "bob" is the handle.

  3. #3
    Actions only run for the player who activated them. See all those isServer checks? That means that it will not work on a dedicated and only for the host on a hosted server - since isServer return false for all other 'actioneers'. That means the non-server players never know what SHK_addmission is.

    You have a typo in the .sqf extension in mission 4. Also you can get rid of the switch so you don't have to add every mission manually:
    PHP Code:
    _missionName format ["mission%1.sqf"_t1 1]; 
    Then your addmission becomes:
    PHP Code:
    SHK_addmission = {
        if (
    isServerthen {
            if (
    count SHK_missions == 0then {
                
    player sideChat "Opps Sorry But I have no Intel for you come back next week";
            } else {
                
    _this spawn {
                    private 
    "_t1";
                    if (
    count _this 0then {
                      
    _t1 _this select 0;
                    } else {
                      
    _t1 SHK_missions select (floor random count SHK_missions);
                    };
                    
    SHK_missions SHK_missions - [_t1];
                    
    _missionName format ["missions\%1.sqf"_t1+1];
                    [] 
    execVM _missionName;
                };
            };
        };
    }; 
    Then your init.sqf becomes:
    PHP Code:

    SHK_addmission 
    = {
        if (
    isServerthen {
            if (
    count SHK_missions == 0then {
                
    player sideChat "Opps Sorry But I have no Intel for you come back next week";
            } else {
                
    _this spawn {
                    private 
    "_t1";
                    if (
    count _this 0then {
                      
    _t1 _this select 0;
                    } else {
                      
    _t1 SHK_missions select (floor random count SHK_missions);
                    };
                    
    SHK_missions SHK_missions - [_t1];
                    
    _missionName format ["missions\%1.sqf"_t1+1];
                    [] 
    execVM _missionName;
                };
            };
        };
    };

    private 
    "_selectedmission";
    missionCount;//paramsarray select 4;
    _selectedmission paramsarray select 5;
    if 
    isserver then {
        private [
    "_temp1","_t1"];
        
    _temp1 = [0,1,2,3];
        
    SHK_missions = [];
        for 
    "_i" from 0 to (missionCount 1) do {
        
    _t1 _temp1 select (floor random count _temp1);
        
    SHK_missions set [_i,_t1];
        
    _temp1 _temp1 - [_t1];
        };
        
    // first task
        
    if (_selectedmission 99then {
            [
    _selectedmissioncall SHK_addmission;
        } else {
            [] 
    call SHK_addmission;
        };
    }; 
    The SHK_addmission have been moved out of an isServer so all the players can use it. There is still a problem though. Only the server knows SHK_missions and SHK_addmission relies on that, which means that non-server players will still not be able to start a mission.

    You have two solutions I can think of
    Everytime missions changes - publicVariable SHK_missions so the players can start a mission.
    Keep the mission starting and stuff on the server only - and simply tell the server to start a new mission when a player uses the action.

    I'll recommend the second approach. If you use CBA I can come up with a solution that works that way if you'd like?

  4. #4
    Master Gunnery Sergeant 1PARA{God-Father}'s Avatar
    Join Date
    Jul 30 2010
    Posts
    1,191
    Author of the Thread
    Ahhh that would be why, as it is on a deli hosted server so no one is getting anything!

    Yes we all use CBA - so if you could that would be really really great!

    Basically what I am trying to do is go up to a civi get the action and he give us a new mission, but I do not want him to repeat the same mission again. And take the addaction off for a while to stop generating all the mission at the same time

    mant thanks !

  5. #5
    We'll use the CBA event system: http://dev-heaven.net/docs/cba/files...Event-sqf.html . This provides a nice way to solve these MP message sending.

    On the server we register an event for a new mission. Whenever any player uses the action we trigger the event. Your init.sqf is almost unchanged, with only a small addition at the top. I also added a few comments:
    PHP Code:
    //Keep all the mission handling serverside
    if (isServerthen {

        
    //Add the new mission request handling
        
    ["new_mission", {
            
    //Just pick a random mission
            
    [] call SHK_addmission;
        }] 
    call CBA_fnc_addEventHandler;

        
    //The new mission script (function)
        
    SHK_addmission = {
            if (
    isServerthen {
                if (
    count SHK_missions == 0then {
                    
    player sideChat "Opps Sorry But I have no Intel for you come back next week";
                } else {
                    
    _this spawn {
                        private [
    "_t1","_missionName"];
                        if (
    count _this 0then {
                          
    _t1 _this select 0;
                        } else {
                          
    _t1 SHK_missions select (floor random count SHK_missions);
                        };
                        
    SHK_missions SHK_missions - [_t1];
                        
    _missionName format ["missions\%1.sqf"_t1+1];
                        [] 
    execVM _missionName;
                    };
                };
            };
        };

        
    //Generate the mission list and select a first mission
        
    private ["_selectedmission"];
        
    //Do you use this elsewhere ? Else you can '_' before it!
        
    missionCount //paramsarray select 4;
        
    _selectedmission paramsarray select 5;
        if (
    isServerthen {
            private [
    "_temp1","_t1"];
            
    _temp1 = [0,1,2,3];
            
    SHK_missions = [];
            for 
    "_i" from 0 to (missionCount 1) do {
            
    _t1 _temp1 select (floor random count _temp1);
            
    SHK_missions set [_i,_t1];
            
    _temp1 _temp1 - [_t1];
            };
            
    // first task
            
    if (_selectedmission 99then {
                [
    _selectedmissioncall SHK_addmission;
            } else {
                [] 
    call SHK_addmission;
            };
        };
    }; 
    We register the 'newmission' event, and when that is triggered we call the SHK_addmission to select a new mission. When you want this event to trigger you call it like this:
    PHP Code:
    //Why not *_remoteEvent ? - Well the player might also be a server, a hosted server
    ["new_mission", []] call CBA_fnc_globalEvent
    And that's it.

    You can also use event like this to remove the action instead of the trigger solution in the other thread. In your init (not in a isServer check !!!) do this, (assumed your CIV is named MyCiv and you saved the action in MyCivAction):
    PHP Code:
    ["remove_action", {
        if (!
    isNil "MyCivAction"then {
            
    MyCiv removeAction MyCivAction;
            
    MyCivAction nil
        };
    }] 
    call CBA_fnc_addEventHandler
    Then your action sqf might look like this in total:
    PHP Code:
    //Remove the action
    ["remove_action", []] call CBA_fnc_globalEvent;
    //Why not *_removeEvent ? - Well the player might also be a server, a hosted server
    ["new_mission", []] call CBA_fnc_globalEvent
    And you can add another event to tell players to put the action back on, and activate that from the server:
    PHP Code:
    ["add_action", {
        if (
    isNil "MyCivAction"then {
           
    MyCivAction MyCiv addAction ["MyActionName""MyScript.sqf"];
        };
    }] 
    call CBA_fnc_addEventHandler
    I only tested the first part - the new mission part, and not the remove/add-Action parts. However, unless there is a typo, it should work.
    Last edited by Muzzleflash; Aug 8 2011 at 14:30.

  6. #6
    Master Gunnery Sergeant 1PARA{God-Father}'s Avatar
    Join Date
    Jul 30 2010
    Posts
    1,191
    Author of the Thread
    WOW many many thanks

    Just so I completely understand:-

    once i change my INI - then

    CIVI
    Code:
    this addAction ["Random Mission!", "getamission.sqf"]
    getamission.sqf
    Code:
    ["new_mission", []] call CBA_fnc_globalEvent;
    Ill give it a test as soon as i get home then work on the remove bit !

  7. #7
    Yup that should do it. Let me know if you run into problems.

    For other future MP issues remember you can pass parameters to the event too:
    PHP Code:
    ["myHint", {_msg _this select 0hint _msg;}] call CBA_fnc_addEventHandler
    And
    PHP Code:
    ["myHint", ["Everybody will see this hint, not just the local player"]] call CBA_fnc_globalEvent
    Although you should use rHint in the MP framework if all you want to do is hint.

    Happy scripting

  8. #8
    Master Gunnery Sergeant 1PARA{God-Father}'s Avatar
    Join Date
    Jul 30 2010
    Posts
    1,191
    Author of the Thread
    You sir are GREAT !!!!!

    Works like a dream even the remove action , tested on server and perfect !


Posting Permissions

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