Forum Jump :

Author Message

Posts: 2

Level: Member

Country: de
Age: 27
In-game name: [3.JgKp]pestKater

#1 Posted at 2014-01-08 03:04        
For my very first TvT-Mission I'm trying to script a system to conquer spots, so my plan is to add a flag in a base and add an action to this, which execute a script. No problem so far.
First of all, I made a rare test-script and fooled around. Still not a problem. I added some variables to check if the script is executing already, so you can't run the script at the same time. In my local test, the script worked fine. It checks the status of the player and increase the process-variable like I planned.

The next step was the problem with the global (local) variables. I want to sync the status with the other players. So if Player A is running the script, player B can't execute it.
The script will end instant if the player is too far away from the flag. So I also want to sync the progress with the other players. With my global (local) variables these functions worked propper.

Here's the construct so far:

nul = execVM "scripts\vars_init.sqf";

// To Sync only at one time
if(!isServer) exitWith {};

// Each Player runs a script to set the both variables to 0;
{_x execVM "set_vars_default.sqf";} foreach playableUnits;

// For a better readable code I set lokal variables
_flag = _this select 3;
_progress = progress_town1;

player globalChat "Start Script";

// If the script is already running on another client, the script will exit.
if(conquest_town1 == 1) exitWith 
	player globalChat "Conquer already in progress";

// Loop until 100 percent progress
while{_progress < 100} do 
	// Change variable to 1, so other machines will reconize the script is running
	conquest_town1 = 1;
	// Exit the script if player is dead
	if(!(alive player)) exitWith 
		player globalChat "You're dead!";
	// Exit the script if player is to far from flag
	if((player distance _flag) > 15) exitWith
		player globalChat "For gods sake: Stay at the flag!";
	// Needed to create some time to conquer
	sleep 2;
	// Now the progress will be increased by 10 percent
	_progress = _progress + 10;
	// Debugging: Current value
	player globalChat str(_progress);

// Playerfeedback
if(_progress == 100) then
	player globalChat "Town conquered";
} else
	player globalChat "Conquer aborted";

// Write local variable back to global variable
progress_town1 = _progress;
// Change the value, so other machines can use the script again
conquest_town1 = 0;

My problem is now the locallity of the variables. The variables are global but only at each client. A thought is to loop a script on each player (like in vars_init.sqf) if a value changes. But so JIP will be a problem. Each time someone joined the game (with technical reasons) the progress of all players will be lost, because it will reset to 0.
So I googled around and read something about public variables. So I changed vars_init.sqf:

if(!isServer) exitWith {};

publicVariable "conquest_town1";
publicVariable "progress_town1";

conquest_town1 = 0;
progress_town1 = 0;

If I understood everything the variables will broadcasted once they have a value. With my debug-action I saw, the variables was set. I can also start the script. But if I start the script again, it won't abort.
I hope you can help my with this problem. Do I anything wrong? Maybe you have an idea how I can manage JIP with the variable-change-loop.

Greetings from germany,

Added 1 hour 36 minutes later:

I'm so dumb. I can't set variables public without defining them first.

This post was edited by pestKater (2014-01-08 04:42, ago)