Jump to content
Sign in to follow this  
McArcher

Player Init. What am I doing wrong?

Recommended Posts

Started a test mission,

in init.sqf wrote:

player setVehicleInit "clearWeaponCargo this; clearMagazineCargo this; this addWeaponCargo [""ItemGPS"", 1]; this sideChat ""Weapons initialized.""; ";

processInitCommands;

I see text, but weapon is still with me after start. Why? What's wrong?

Share this post


Link to post
Share on other sites

ou, thanx

player setVehicleInit "removeAllWeapons this; this sideChat ""Weapons initialized.""; ";

processInitCommands;

this works :)

Share this post


Link to post
Share on other sites

Why are you using setvehicleinit on mission start when you can just use the commands directly for the unit?

Share this post


Link to post
Share on other sites
Error alive: Тип МножеÑтво, ожидаетÑÑ ÐžÐ±ÑŠÐµÐºÑ‚

Type Unity , expected Object..

isn't it an Object already?

Share this post


Link to post
Share on other sites
Error alive: Тип МножеÑтво, ожидаетÑÑ ÐžÐ±ÑŠÐµÐºÑ‚

Type Unity , expected Object..

isn't it an Object already?

Share this post


Link to post
Share on other sites

Cargo-commands are only for weapons and ammo in the cargo space of vehicles. Soldiers have no cargo space.

Your latter command seems right (although why not simply put the init-line stuff in the unit's init field in the editor, rather than in init.sqf?

To add the GPS simply use this addWeapon "ItemGPS";

Share this post


Link to post
Share on other sites

My previous messages were deleted...so... I'm writing again....

I'm trying to remove weapons from playable NPCs after their respawn (they begin game without guns, but have them after respawn). The code is following:

// mca_players_init_s.sqf
// version 1.1s

if (isServer) then
{

{
	_x setVehicleInit "removeAllWeapons this; ";
	if ( isNil{_x getVariable "mk_killedEHadded"} ) then 
	{
		_x addEventHandler ["killed", 
		{ 
			//[] execVM "mca_onNPCKilled.sqf";
			[_this select 0] spawn {
				private ["_unit"];
				_unit = _this select 0;
				diag_log format ["In spawn _unit=%1", _unit];//dbg						
				waitUntil { alive _unit }; 					
				//[_unit] execVM "mca_onNPCRespawn.sqf";
				removeAllWeapons _unit;
			};	
		}];
		_x setVariable ["mk_killedEHadded", true];
	};
} forEach RU_players;

{
	_x setVehicleInit "removeAllWeapons this; ";
	if ( isNil{_x getVariable "mk_killedEHadded"} ) then 
	{
		_x addEventHandler ["killed", 
		{ 
			//[] execVM "mca_onNPCKilled.sqf";
			[_this select 0] spawn {
				private ["_unit"];
				_unit = _this select 0;
				waitUntil { alive _unit }; 
				//[_unit] execVM "mca_onNPCRespawn.sqf";
				removeAllWeapons _unit;
			};	
		}];
		_x setVariable ["mk_killedEHadded", true];
	};
} forEach US_players;

processInitCommands;

};

Well, I think I know why it doesn't work.

For example RU_player_2 after death and RU_player_2 after respawn are different objects (the dead body isn't removed). When I modify script and wait until RU_player_2 respawns remove weapons not from _unit but from RU_player_2, then it works. But... I checked with diag_log, unit is RU_player_2 before respawn and RU_player_2 after respawn! So this pointer just changes its adress I guess but I have old value if I use _unit to adress to it... How can I check new unit to respawn? (player instead of _unit works fine for respawning myself, but how can server know that _unit respawned?) Please help.

---------- Post added at 19:58 ---------- Previous post was at 19:54 ----------

maybe I can count a number _n of my _unit in array of players and check by number? hm... it will adress to old value (dead body) again..... how to address new unit?

---------- Post added at 20:07 ---------- Previous post was at 19:58 ----------

sorry for flooding the thread, but I have found the solution to address to new _unit (using call compile):

// mca_players_init_s.sqf
// version 1.1s

if (isServer) then
{

{
	_x setVehicleInit "removeAllWeapons this; ";
	if ( isNil{_x getVariable "mk_killedEHadded"} ) then 
	{
		_x addEventHandler ["killed", 
		{ 
			//[] execVM "mca_onNPCKilled.sqf";
			[_this select 0] spawn 
			{
				private ["_unit"];
				_unit = _this select 0;
				sleep 0.5;
				_s = format["          waitUntil { alive %1 }; removeAllWeapons %1; 					", _unit];
				diag_log format ["_s=%1", _s];//dbg						
				call compile _s;
				//[_unit] execVM "mca_onNPCRespawn.sqf";
			};	
		}];
		_x setVariable ["mk_killedEHadded", true];
	};
} forEach RU_players;

{
	_x setVehicleInit "removeAllWeapons this; ";
	if ( isNil{_x getVariable "mk_killedEHadded"} ) then 
	{
		_x addEventHandler ["killed", 
		{ 
			//[] execVM "mca_onNPCKilled.sqf";
			[_this select 0] spawn
			 {
				private ["_unit"];
				_unit = _this select 0;
				sleep 0.5;
				_s = format["          waitUntil { alive %1 }; removeAllWeapons %1; 					", _unit];
				diag_log format ["_s=%1", _s];//dbg						
				call compile _s;
				//[_unit] execVM "mca_onNPCRespawn.sqf";
			};	
		}];
		_x setVariable ["mk_killedEHadded", true];
	};
} forEach US_players;

processInitCommands;

};

---------- Post added at 20:11 ---------- Previous post was at 20:07 ----------

it is so boring to write in this super-hi-leveled-code.... I hope someday BIS will allow modders to code in game's code , like in NWN(2) they allow t write scripts... so much time I spend investigating this syntax and addressing problems....so boring....

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  

×