Jump to content
Sign in to follow this  
Martinez.E

Script not working on multiplayer dedicated server, works fine on editor

Recommended Posts

Its just a simple rifle range, works fine doing one target at a time like a normal rifle range, once loaded on a dedicated server it forgets that i only need one target popping up..any ideas what im doing wrong? Is there something to the script that needs to be added to make it compatible to be used on a server?

_inc   = 0;
_count   = 0;
_targets = [pt2, pt2_1, pt2_2, pt2_3, pt2_4, pt2_5];
_many    =  count _targets;
{_x  animate["terc",1]} forEach _targets;

hint "Welcome to the 82nd Airborne Division Qualification Range";
sleep 5;
hint "Remember to reload!";
sleep 5;
hint "Setting up the Range";
sleep 3;
hint "The Qualification Course will begin in 10 Seconds";
sleep 2;
hint "The Qualification Course will begin in 8 Seconds";
sleep 2;
hint "The Qualification Course will begin in 6 Seconds";
sleep 2;
hint "The Qualification Course will begin in 4 Seconds";
sleep 2;
hint "The Qualification Course will begin in 2 Seconds";
sleep 2;
hint "Begin!";


while {_inc<40} do 
{
_rnumber = floor random _many;
_rtarget = _targets select _rnumber;
_rtarget animate["terc", 0];
sleep 6;
if (_rtarget animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
  hint format ["Targets :%1 Hit :%2",_inc+1,_count];
_rtarget animate["terc", 1];
_inc = _inc + 1;
};              
sleep 8;
hint "Session Complete,";

sleep5;
if (_count >= 36) then {hint "You Scored EXPERT";};

if (_count <= 32)  then {hint "You Scored SHARPSHOOTER";};

if (_count <= 23)  then {hint "You Scored MARKSMAN";};

if (_count <= 9) then {hint "You Scored Below Minimum Standards, Try Again";};

Share this post


Link to post
Share on other sites

This doesnt help me at all. its explained how clients and servers are relative to a network, but does not explain why the script does what it does and how i can fix or change it.

  • Like 1

Share this post


Link to post
Share on other sites

When you call the script, do you let all players run it or only server?

once loaded on a dedicated server it forgets that i only need one target popping up

After reading this, I'm going to guess it's the former, but I want to know for sure before I continue

Share this post


Link to post
Share on other sites

That should help you exactly. He's explaining to you that if you run your script everywhere, then it duplicates what's in your script by the amount of connected machines.

Is this the same as the other thread you posted on targets in this forum?

http://forums.bistudio.com/showthread.php?186926-trigger-not-working-correctly

Look at the second link posted by DE .and look up the isServer command It should answer your question,.

Share this post


Link to post
Share on other sites

I was thinking the same about the similar thread Das.

But on a more related note you could also use BIS_fnc_MP to execute the script if you wanted to as well, it might be a bit of overkill, but it will give you some flexibility in where the script is executed.

Share this post


Link to post
Share on other sites

so if im understanding correctly, i need to us the isServer in some sort of init? or inside the code? i didnt make this script, it was given to me. So i couldnt tell you how to make it work on a dedi server.

Das - The original problem started differently, F2K Sel gave me a different script to try and it worked great on editor but does not work correctly in the server. decided to make a new thread about this problem to see if anyone could help change it or tell me what needs to be done for it to work.

So would this be correct? Do i need to add something to the target init?

 
if (isServer) then {

_inc   = 0;
_count   = 0;
_targets = [pt2, pt2_1, pt2_2, pt2_3, pt2_4, pt2_5];
_many    =  count _targets;
{_x  animate["terc",1]} forEach _targets;

hint "Welcome to the 82nd Airborne Division Qualification Range";
sleep 5;
hint "Remember to reload!";
sleep 5;
hint "Setting up the Range";
sleep 3;
hint "The Qualification Course will begin in 10 Seconds";
sleep 2;
hint "The Qualification Course will begin in 8 Seconds";
sleep 2;
hint "The Qualification Course will begin in 6 Seconds";
sleep 2;
hint "The Qualification Course will begin in 4 Seconds";
sleep 2;
hint "The Qualification Course will begin in 2 Seconds";
sleep 2;
hint "Begin!";


while {_inc<40} do 
{
_rnumber = floor random _many;
_rtarget = _targets select _rnumber;
_rtarget animate["terc", 0];
sleep 6;
if (_rtarget animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
  hint format ["Targets :%1 Hit :%2",_inc+1,_count];
_rtarget animate["terc", 1];
_inc = _inc + 1;
};              
sleep 8;
hint "Session Complete,";

sleep5;
if (_count >= 36) then {hint "You Scored EXPERT";};

if (_count <= 32)  then {hint "You Scored SHARPSHOOTER";};

if (_count <= 23)  then {hint "You Scored MARKSMAN";};

if (_count <= 9) then {hint "You Scored Below Minimum Standards, Try Again";};

Edited by Emartinez

Share this post


Link to post
Share on other sites

Alright so i tried it the way it is above and it wouldnt run the hints at all but the targets went fine. i then moved it to after the hints but before the while{_inc<40} do and it was able to do the hints but it didnt show the target count or hit counter. so im not really sure what it needs to say or where it needs to go so that everything shows.

bottomline it did do only one target at a time on the plus side.

Share this post


Link to post
Share on other sites

It's because of the locality of the hints is now on the server (which doesn't display for the player).

Share this post


Link to post
Share on other sites

create a function at the end of init.sqf (before you run the script and keep it outside the if is server statement)

AUSMD_showhint = 
{
   _text = _this select 0;
   hint _text;
};

now we can use BIS_fnc_MP to send a packet from the server to broadcast that hint to everybody.

//client will run the function he loaded earlier when he receives the packet, showing a hint with the text that packet contained.
[["my_text_in_here"],"AUSMD_showhint",true,false] spawn BIS_fnc_MP;

Though in your case since theres lots of hints it'll be much more efficient to just tell the client to run his copy of the function, sending a bunch of packets that do the same thing is a waste of bandwith

AUSMD_showhint = 
{
  _timer = 10;
   while{_timer > 1} do
   {
     _timer = _timer - 1;
     hint format ["starting in %1",_timer];
     sleep 1;
   }; 
};

 [[],"AUSMD_showhint",true,false] spawn BIS_fnc_MP; //same thing as above but no need to pass parameters

Edited by austin_medic

Share this post


Link to post
Share on other sites

Only issue I see using BIS_fnc_MP to broadcast to everyone with this particular script you could have multiple fire lanes running at the same time, so the hints would be overlapping.

Share this post


Link to post
Share on other sites
Only issue I see using BIS_fnc_MP to broadcast to everyone with this particular script you could have multiple fire lanes running at the same time, so the hints would be overlapping.

its possible to broadcast to specific units as well if its needed, just change that true variable to a unit name.

Share this post


Link to post
Share on other sites

Good point, just need a good way of getting the executing unit then passing it into BIS_fnc_MP.

Share this post


Link to post
Share on other sites

So using the script i had on the first page, how would that be implemented? or does this need to be run in a seperate file (init.sqf)

inside my depbo'd folder is the VAS which is the virtual ammo box, Description.ext, mission.sqm, and popup, popup2, etc which is for each lane for the rifle range. there is no init.sqf. i assume i need to make an init.sqf?

im not a scripter at all so sorry if my questions seem dumb, its just a basic map for training and the most complex thing (in my mind) is getting the rifle range working, the rest is already done and working the way i need it to work.

Edited by Emartinez

Share this post


Link to post
Share on other sites

i am really needing help to make this script work on our dedicated server. can anyone not help me make edits to it to get it working?

Share this post


Link to post
Share on other sites

This same problem is happening to me, I tried using the if(isServer) but then it wont run the script at all. Any help will be appreciated

Share this post


Link to post
Share on other sites

This same problem is happening to me, I tried using the if(isServer) but then it wont run the script at all. Any help will be appreciated

lol and how do u think we can help u?

edit: give me ur adress i ll book a flight...

Share this post


Link to post
Share on other sites

This same problem is happening to me, I tried using the if(isServer) but then it wont run the script at all. Any help will be appreciated

 

Not necro'ing years old obsolete posts would be a good first step.  Including even a single detail about the issue you've having would be a fine second step.

 

There are a lot of new tools and commands to help with multiplayer scripting.  Start a new thread with your code examples, errors and description of your issue and I'm sure you'll find some information to help.

Share this post


Link to post
Share on other sites

Not necro'ing years old obsolete posts would be a good first step.  Including even a single detail about the issue you've having would be a fine second step.

 

There are a lot of new tools and commands to help with multiplayer scripting.  Start a new thread with your code examples, errors and description of your issue and I'm sure you'll find some information to help.

considering it would not let me make a new thread, I also said that i was having the exact same issue and thus was hoping that new people looking at the thread could help

Share this post


Link to post
Share on other sites

Arguing instead of posting what what was requested is a really poor way of getting help.   :mellow:

 

So are you using the exact same code that emartinez did?  Which doesn't include any usage of BIS_fnc_MP and why it wasn't working.  Or were you using the function from austin_medic which does use BIS_fnc_MP, but wasn't a complete script?  Neither of which really matter since you should now be using remoteExec instead (even though BIS_fnc_MP now uses it internally, but whatever).

 

The point is "I'm having the exact same issue" is not an accurate description of your problem unless you're using the same code, the final version of which we never saw anyway.

 

So, as I already said, post what you actually have so far and what errors you're getting if you expect to get help.  We can't help with something we've never seen.

Share this post


Link to post
Share on other sites

Arguing instead of posting what what was requested is a really poor way of getting help.   :mellow:

 

So are you using the exact same code that emartinez did?  Which doesn't include any usage of BIS_fnc_MP and why it wasn't working.  Or were you using the function from austin_medic which does use BIS_fnc_MP, but wasn't a complete script?  Neither of which really matter since you should now be using remoteExec instead (even though BIS_fnc_MP now uses it internally, but whatever).

 

The point is "I'm having the exact same issue" is not an accurate description of your problem unless you're using the same code, the final version of which we never saw anyway.

 

So, as I already said, post what you actually have so far and what errors you're getting if you expect to get help.  We can't help with something we've never seen.

range2Score = "";
_maxtarg  = 40;
_numtargs = 1;
_skill    = 3;

_targets = [pt2,pt2_1, pt2_2, pt2_3, pt2_4, pt2_5, pt2_6, pt2_7, pt2_8, pt2_9];// target names 
_many    =  count _targets; // count the number of possible targets

_inc     = 0;// keeps track of the number of popup targets triggered 
_score   = 0;// keep count of the targets hit


{_x  animate["terc",1]} forEach _targets;//puts the targets down before the start

_rnumber1=0; 
_rnumber2=0;
_rnumber3=0;

_flag1=0;
_flag2=0;

nopop=true; // sets them to stay down until triggered to popup

hint "Setting up the Range";
sleep 2;
hint "Ready";
sleep 2;


while {_inc<_maxtarg} do 
{
_rnumber1 = random _many;	// a random number of the target


// 1. Set the targets that will popup
_rtarget1 = _targets select _rnumber1;
// 1. END

// 2. Popup target one always active
_rtarget1 animate["terc", 0];
_inc=_inc+1;
// 2. END

// 3. Time allowed for shooting.
sleep _skill; 
// 3. END 

// 4. Check to see if targets have been hit and count the score
 if (_rtarget1 animationPhase "terc" > 0.1) then
{
		_score = _score+1;
		    };

// 4. END		    

// 5. Display Score		    
 range2Score = format ["Range 2 Targets :%1 Hit :%2",_inc,_score];

// 5. END

// 6. Reset targets down and restet flags
_rtarget1 animate["terc", 1];

_flag1=0;
_flag2=0;

// 6. END

sleep 2;
};
rangeMaster2 sideChat range2Score;
sleep 8;
hint "Session Complete";

Having the exact same issue meaning it will popup multiple targets when in MP but it works fine in the editor. I tried using the if(isServer) and I tried BIS_fnc_MP but those would just make it so the script was not running at all

Share this post


Link to post
Share on other sites

Tested as working on hosted and dedicated server:

/* 
Assuming this is run from an addAction on an object or RangeMaster2's init field:

Defaults:

this setVariable["heinz_range2_inUse", false];
this addAction["Start Range", {_this call heinz_fnc_range2}, [], 0, true, false, "", "!(_target getVariable 'heinz_range2_inUse')"];

 or  customized...

this setVariable["heinz_range2_inUse", false];
 this addAction["Start Range Zombies", {_this call heinz_fnc_range2}, [40, 3, rangeMaster1, [ptz, ptz_1, ptz_2, ptz_3, ptz_4], 0, true, false, "", "!(_target getVariable 'heinz_range2_inUse')"];
 
*/

// Function declared in your init.sqf or Functions library
heinz_fnc_range2 = {
	// Grab params from default addAction input and declare _targetsHit to 0
	params["_object",	"_caller", "_id","_args", ["_targetsHit", 0]];

	// Optional arguments for setting # targets, skill level, rangemaster speaker and targets array.
	_args params [
		["_maxtarg", 5],
		["_skill", 2],
		["_rangeMaster", rangeMaster2],
		["_targets", [pt2,pt2_1, pt2_2, pt2_3, pt2_4, pt2_5, pt2_6, pt2_7, pt2_8, pt2_9]]
	];

	// Range in use!
	_rangeMaster setVariable["heinz_range2_inUse", true, true];
	
	//puts the targets down before the start
	{_x  animate["terc",1]} forEach _targets;

	// sets them to stay down until triggered to popup
	nopop=true; 

	// Range setup hints to player who called the action.
	"Setting up the Range" remoteExec ["hint", _caller];
	sleep 2;
	"Get Ready..." remoteExec ["hint", _caller];
	sleep 2;
	"" remoteExec ["hint", _caller];

	// We are live!  Lets line up _maxtarg worth of random targets.
	for [{_i=1},{_i<=_maxtarg},{_i=_i+1}] do {
		
		// Select a random target from the _targets pool.
		_currentTarget = selectRandom _targets;
		// and pop it up
		_currentTarget animate["terc", 0];

		// Sleep based on _skill timer
		sleep _skill; 
	
		// You've had your time, did you hit it?
		if (_currentTarget animationPhase "terc" > 0.1) then
		{
			// Yay you did!
			_targetsHit = _targetsHit+1;
		};

		// Ensure it's set down again.
		_currentTarget animate["terc", 1];
		
		// Sleep for the next target (2 sec seemed a bit long?)
		sleep 1;
	};

	// We're out of targets, so let the shooter know.
	"Session Complete" remoteExec ["hint", _caller];

	// Put all the targets up again.
	{_x  animate["terc",0]} forEach _targets;

	// Rangemaster is tallying your score...
	sleep 2;

	// replace 0 with _caller if only the shooter should see.
	[_rangeMaster, format["Range 2 Targets :%1 Hit :%2",_maxtarg,_targetsHit]] remoteExec ["sideChat", 0];  
	
	// Open for business again!
	_rangeMaster setVariable["heinz_range2_inUse", false, true];
	
	// Clear the "Course Complete" hint.
	"" remoteExec ["hint", _caller];
};

Actually, other than the setVariable to stop others from using the range, I guess it's all local anyway.  Oh well :)

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  

×