Jump to content
Sign in to follow this  
Fuzzy Bandit

Help with Variables and 'Adding Points'

Recommended Posts

Hello!

I'm currently working on a small points system for a PvP gametype based on flags. Each team starts with 0 tickets, and the score limit (let's say) is 50. There are 3 flags on the map and each team is rewarded one point per flag they own on the map every minute.

Now the problem at the moment is that upon capturing just one flag, that team's points seems to increase every minute by 2 OR 3, as opposed to 1 as it should.

In all honesty I've been debugging this damned thing for hours and can't find out how to make it work! The points variables are placed in a Game Logic inside the mission, and they're updated using publicVariable. If I remove the publicVariable lines from the script, it works and only adds the correct amount of points, but JIP players will not see the updated version of the scores.

Here's the relevant script parts posted below. Why on earth would it be adding more than 1 point per flag?

Game Logic

uspoints = 0; plapoints = 0; usflags = 0; plaflags = 0; tflag1 = "Neutral"; tflag2 = "Neutral"; tflag3 = "Neutral"; addit = "waiting";

init.sqf

//Creating loop that adds 1 point per flag each time tickettime goes past
While{(uspoints < scorelimit) OR (plapoints < scorelimit)} do {
sleep tickettime;
if (tflag1 == "US") then {
	uspoints = uspoints + 1;
	publicVariable "uspoints";
};
if (tflag2 == "US") then {
	uspoints = uspoints + 1;
	publicVariable "uspoints";
};
if (tflag3 == "US") then {
	uspoints = uspoints + 1;
	publicVariable "uspoints";
};
if (tflag1 == "PLA") then {
	plapoints = plapoints + 1;
	publicVariable "plapoints";
};
if (tflag2 == "PLA") then {
	plapoints = plapoints + 1;
	publicVariable "plapoints";
};
if (tflag3 == "PLA") then {
	plapoints = plapoints + 1;
	publicVariable "plapoints";
};
};

us.sqf

(Player-Activated Script which goes about the actions to Capture Flag 2 for US Forces)

_flagpro = 0;
hintSilent format ["Capturing Flag!\n%1 seconds remaining...", (flagdone - _flagpro)];
While {(_flagpro < flagdone) AND (player distance flag2 < 5)} do {
sleep 1;
_flagpro = _flagpro + 1;
hintSilent format ["Capturing Flag!\n%1 seconds remaining...", (flagdone - _flagpro)];
};
if (_flagpro == flagdone) then {
publicVariable "flag2west";
tflag2 = "US";
publicVariable "tflag2";
addit = player;
publicVariable "addit";
[west,"HQ"] sideChat format ["We've captured CP2! Good job %1!", name player];
[nil,nil,rHINT,format ["%1 captured CP2 for US Forces!", name player]] call RE;
"marker2" setMarkerType "Faction_US";
"marker2" setMarkerSize [1,0.6];
"marker2" setMarkerText "CP2 (US)";
} else {
hint "";
};

For all that is holy, please somebody point out a mistake! I have no idea why it would be adding more points apart from the issue of the publicVariables. But if I don't use publicVariable, how will JIP players see updated information?!

Cheers!

Share this post


Link to post
Share on other sites

Your score-adder is running on all connected machines, that's why it adds 2 points when you have a server + one client and 3 points when you have a server + two clients, and so on.

1) You want it to run on the server only

2) It has to be a AND / && in the while condition. An OR means that the loop keeps adding until both sides have >= scorelimit points

3) I've shortend the six 'if's to two 'count's. It does the same, just less code

[noparse]
if(isServer) then {
while{(uspoints < scorelimit) && (plapoints < scorelimit)} do {
	sleep tickettime;
	uspoints =  uspoints + ({_x == "US" } count [tflag1, tflag2, tflag3]);
	plapoints = plapoints + ({_x == "PLA"} count [tflag1, tflag2, tflag3]);
	publicVariable "uspoints";
	publicVariable "plapoints";
};
};


[/noparse]

Share this post


Link to post
Share on other sites

Disregard. Already answered.

Edited by Loyalguard
Paste error.

Share this post


Link to post
Share on other sites

You're a star you are! :D

Cleaned up the code nicely for me as well! Thank you huge amounts! Would've been a bit of an embarrassment with 40 people on the server, adding 40 points per flag! :P

I keep forgetting about the 'isServer' condition. It really is unbelievably helpful when dealing with locality issues!

Cheers!

P.S. Thanks to you too Loyalguard! :)

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  

×