Jump to content
Sign in to follow this  
1para{god-father}

Addaction and [] call

Recommended Posts

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

this addAction ["Random Mission!", "getamission.sqf"]

getamission.sqf

[] call SHK_addmission;

in my INI

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

[] 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 :confused:

Share this post


Link to post
Share on other sites

How about,

getamission.sqf

bob =[]call SHK_addmission;

I believe you need a handle. "bob" is the handle.

Share this post


Link to post
Share on other sites

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:

_missionName = format ["mission%1.sqf", _t1 + 1];

Then your addmission becomes:

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];
               _missionName = format ["missions\%1.sqf", _t1+1];
               [] execVM _missionName;
           };
       };
   };
};

Then your init.sqf becomes:


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];
               _missionName = format ["missions\%1.sqf", _t1+1];
               [] execVM _missionName;
           };
       };
   };
};

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;
   };
};

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?

Share this post


Link to post
Share on other sites

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 !

Share this post


Link to post
Share on other sites

We'll use the CBA event system: http://dev-heaven.net/docs/cba/files/events/fnc_globalEvent-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:

//Keep all the mission handling serverside
if (isServer) then {

   //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 (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","_missionName"];
                   if (count _this > 0) then {
                     _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 = 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;
       };
   };
};

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:

//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):

["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:

//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:

["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.

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

WOW many many thanks

Just so I completely understand:-

once i change my INI - then

CIVI

this addAction ["Random Mission!", "getamission.sqf"]

getamission.sqf

["new_mission", []] call CBA_fnc_globalEvent;  

Ill give it a test as soon as i get home :) then work on the remove bit !

Share this post


Link to post
Share on other sites

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:

["myHint", {_msg = _this select 0; hint _msg;}] call CBA_fnc_addEventHandler;

And

["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 :)

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  

×