Jump to content
Sign in to follow this  
NGagedFX

Credits System - Getting it to work in MP

Recommended Posts

With great help of Neokika I got a credits system working in which your team gains credits for completing objectives and with which you can buy vehicles and other stuff. In SP this works great, but in MP it gets all messy. I got some scripting knowledge but I have no clue and never had any about MP scripting.

I often play with friends where I'm host, but my mission also needs to be compatible with a dedicated server. Here's the setup:

Soldier A, B & C, each with the same init

My_group1 = group this;

init.sqf

if (isServer) then {
  {_x setvariable ["groupCredits", 3, true]} forEach [My_group1];
};

trigger onAct

My_group1 setVariable ["groupCredits", ((My_group1 getVariable "groupCredits") + 1), true];
nil = [My_group1] execVM "supplyDrop\credits.sqf";

*this code is started from either a trigger or script

I also have a billboard with custom textures to reflect the current status. This is updated by running credits.sqf

switch ((_this select 0) getVariable "groupCredits") do
{
case 0 : { hint "Your team has 0 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_0_credits.jpg"] };
case 1 : { hint "Your team has 1 Credit";
	   supplyDropbb setObjectTexture [0,"textures\SD_1_credits.jpg"] };
case 2 : { hint "Your team has 2 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_2_credits.jpg"] };
case 3 : { hint "Your team has 3 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_3_credits.jpg"] };
case 4 : { hint "Your team has 4 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_4_credits.jpg"] };
case 5 : { hint "Your team has 5 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_5_credits.jpg"] };
case 6 : { hint "Your team has 6 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_6_credits.jpg"] };
case 7 : { hint "Your team has 7 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_7_credits.jpg"] };
case 8 : { hint "Your team has 8 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_8_credits.jpg"] };
case 9 : { hint "Your team has 9 Credits";
	   supplyDropbb setObjectTexture [0,"textures\SD_9_credits.jpg"] };
case 10 : { hint "Your team has reached the maximum amount of 10 Credits. Buy something before acquiring even more Credits!";
	   supplyDropbb setObjectTexture [0,"textures\SD_10_credits.jpg"] };
};

We all connect and start the mission: everyone has the same amount of credits and the billboard is up-to-date. When either one us fires the trigger, most of the time everyone will get credits, but this is very inconsistent. Sometimes the player who fires the trigger will get double or triple the credits, while at other times other people don't get anything. There are moment when everything is in sync, but it takes very little effort to mess it all up. :confused: I think the problem is with running the scripts 'serverside/clientside' and I should probably use publicVariables but I have no idea where to start and how all this stuff works. So if anyone could point me in the right direction and help me out it would be greatly appreciated, as this credit system is the core of my sandbox map. :)

Edited by NGagedFX

Share this post


Link to post
Share on other sites

HI NGagedFX,

Your problem seems to be that the trigger is firing on all machines, meaning you either have a editor placed trigger (that places a trigger on every computer within the network) or you're creating the trigger in every machine.

So the solution here, is to create the trigger in one machine only such as the server:

Init.sqf

if (isServer) then 
{
  {_x setvariable ["groupCredits", 3, true]} forEach [My_group1];

  //Create trigger here
};

Using createTrigger command.

Since the trigger only exists on the server now, you will need to broadcast the hint and setObjectTexture to every player, one way is to place the Functions Module on editor and using the following parameters:

[nil, nil, rHINT, "Your team has 0 Credits"] call RE;  //All machines connected
[nil, supplyDropbb, "per", rSETOBJECTTEXTURE, 0,"textures\SD_10_credits.jpg"] call RE;  //All machines connected plus JIP

_neo_

Edited by neokika

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  

×