Stapo 1 Posted March 9, 2013 (edited) Hello everyone, so ive wrote a anti-base rape and anti-tk script for an upcoming misison im making and i cant for the life of me get it to work... i execute it on player death: init.sqf player setVariable ["player_side",playerside]; _punishment = player addMPEventHandler ["MPKilled", {null = _this execVM "punish.sqf";}]; punish.sqf: victim = _this select 0; killer = _this select 1; victim_side = player getVariable "player_side"; killer_side = side killer; SKmessage = {titleText ["SPAWN KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; TKmessage = {titleText ["TEAM KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; if (killer == victim) exitWith {}; if (killer_side == victim_side) then { [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; }; if (victim_side == WEST) then { if ((victim distance getMarkerPos "Respawn_west" < 100) || (victim distance getMarkerPos "Respawn_west_1" < 50) || (victim distance getMarkerPos "Respawn_west_2" < 75)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; } else { if ((victim distance getMarkerPos "Respawn_east" < 100) || (victim distance getMarkerPos "Respawn_east_1" < 75) || (victim distance getMarkerPos "Respawn_east_2" < 50)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; }; ive got this script to work sort of a few hours ago, but it was showing the wrong messages, so i decided to rewrite and yeah, not working :( Thanks, Stapo Edited March 9, 2013 by Stapo Share this post Link to post Share on other sites
Stapo 1 Posted March 9, 2013 (edited) Updated Post, Edit now it seems to be working sort of, as in the messages are opposite??? if i team kill i get the SKmessage BUT if i kill someone at thier spawn, i get a quick flash of the SKmessage then it turns into the TKmessage... something very strange is happening here... Anyone wamt to take a stab at it? Edited March 9, 2013 by Stapo Share this post Link to post Share on other sites
Stapo 1 Posted March 9, 2013 Please, anyone? this has been driving me insane for the last 2 days Share this post Link to post Share on other sites
eggbeast 3673 Posted March 9, 2013 try this? if (killer == victim) exitWith {}; if (killer_side == victim_side) then { [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; }; if (victim_side == "WEST" and killer_side =="EAST") then { if ((victim distance getMarkerPos "Respawn_west" < 100) || (victim distance getMarkerPos "Respawn_west_1" < 50) || (victim distance getMarkerPos "Respawn_west_2" < 75)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; }; if (victim_side == "EAST" and killer_side =="WEST") then { if ((victim distance getMarkerPos "Respawn_east" < 100) || (victim distance getMarkerPos "Respawn_east_1" < 75) || (victim distance getMarkerPos "Respawn_east_2" < 50)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; }; Share this post Link to post Share on other sites
Stapo 1 Posted March 9, 2013 @eggbeast, thanks i tried it but and it got me alittle closer :) as in if you TK you get the CORRECT message now, BUT now if you SK you get the TK message... this is driving me nuts lol :) Share this post Link to post Share on other sites
squeeze 22 Posted March 10, 2013 (edited) I did something along these lines back 4 years ago.... I think you scored points for a good kill and either died or lost points for a bad kill, takes into account spawn markers....i remembered it worked well. hope it can help. int.sqf funcInfantryKilled = compile preprocessFile "InfantryKilled.sqf"; funcGetMSG = compile preprocessFile "GetMSG.sqf"; SQU_MSG = []; "SQU_MSG" addPublicVariableEventHandler {_this select 1 call funcGetMSG}; //added to ever unit so not in main init.sqf _event = format["[_this, %1,%2]spawn funcInfantryKilled",_side,_leader]; _unit addEventHandler ["killed",_event]; InfantryKilled.sqf // args: [[dead, killer]] _dead = (_this select 0) select 0; _killer = (_this select 0) select 1; _sidedead = _this select 1; _leaderdead = _this select 2; _score = 0; _temp = 0; _sidekiller = -1; SQU_ScoreKill = []; _dist = 0; _spawnPosDead = []; _spawnPosKiller = []; if(_sidedead == SQU_West)then{_spawnPosDead = getmarkerpos "respawn_west"; _spawnPosKiller = getmarkerpos "respawn_east"}else{_spawnPosDead = [0,0,0]; _spawnPosKiller = [0,0,0]}; if(_sidedead == SQU_East)then{_spawnPosDead = getmarkerpos "respawn_east"; _spawnPosKiller = getmarkerpos "respawn_west"}; if(side _killer == west)then{_sidekiller = SQU_west}else{_sidekiller = SQU_Res}; if(side _killer == east)then{_sidekiller = SQU_East}; _leaderKiller = vehicleVarName leader _killer; _nameleaderdead = vehicleVarName leader _dead; if((_sidedead == SQU_West) && (_dead != (call compile format["SQU_W%1",_leaderdead])))then{SQU_WestUnitsAlive = SQU_WestUnitsAlive - 1;publicvariable "SQU_WestUnitsAlive"}; if((_sidedead == SQU_East) && (_dead != (call compile format["SQU_E%1",_leaderdead])))then{SQU_EastUnitsAlive = SQU_EastUnitsAlive - 1;publicvariable "SQU_EastUnitsAlive"}; //Check distance dead was killed from there own spawn point _dist = (_dead distance _spawnPosDead); if(_dist < 200)exitwith { _score = 99; SQU_ScoreKill = [_score,_dead,_sidedead,_leaderdead,_sidekiller,_leaderKiller,false]; publicvariable "SQU_ScoreKill"; if(isServer)then{[_score,_dead,_sidedead,_leaderdead,_sidekiller,_leaderKiller,false]call funcScoreKill}; if((_sidekiller != _sidedead)&&(_sidekiller != SQU_Res))then { _score = 1; SQU_ScoreKill = [_score,_killer,_sidekiller,_leaderKiller,_sidedead,_nameleaderdead,false]; publicvariable "SQU_ScoreKill"; if(isServer)then{[_score,_killer,_sidekiller,_leaderKiller,_sidedead,_nameleaderdead,false]call funcScoreKill}; SQU_MSG = [ "SQU_allplayers", format["%1 or a unit in his Group just spawn killed",(name(leader _killer))]]; publicvariable "SQU_MSG"; if(isServer)then{SQU_MSG call funcGetMSG}; _killer setdamage 1; }; }; //A West unit was killed if(_sidedead == SQU_West)then { if((_sidekiller == SQU_West)||(_sidekiller == SQU_Res)||(_dead == _killer))exitwith{_score = 99;}; _score = 1; }; //A East unit was killed if(_sidedead == SQU_East)then { if((_sidekiller == SQU_East)||(_sidekiller == SQU_Res)||(_dead == _killer))exitwith{_score = 99;}; _score = 1; }; //A Resistance unit was killed if(_sidedead == SQU_Res)then { if((_dead == _killer)||(_sidekiller == SQU_Res))exitwith{}; _score = 1; }; //A Civilian unit was killed if(_sidedead == SQU_Civ)then { if((_dead == _killer)||(_sidekiller == SQU_Civ))exitwith{}; SQU_MSG = [ "SQU_allplayers", format["%1 or a unit in his Group just killed a Civilian",(name(leader _killer))]]; publicvariable "SQU_MSG"; if(isServer)then{SQU_MSG call funcGetMSG}; _score = 1; }; if(_score == 0)exitwith{/*no score*/}; SQU_ScoreKill = [_score,_dead,_sidedead,_leaderdead,_sidekiller,_leaderKiller,false]; publicvariable "SQU_ScoreKill"; if(isServer)then{[_score,_dead,_sidedead,_leaderdead,_sidekiller,_leaderKiller,false]call funcScoreKill}; //player globalchat format ["SQU_ScoreKill=%1",SQU_ScoreKill]; getMSG.sqf ......I'd use publicVariableClient these days //arg:[msg to...null = all recieve, msg] //player globalchat format ["THis=%1",_this]; _MSGto = _this select 0; _MSG = _this select 1; SQU_MSG = []; if((_MSGto == "SQU_allplayers") || (_MSGto == vehicleVarName player))then { titleText [_MSG, "PLAIN DOWN", 2]; }; Edited March 11, 2013 by Squ33z3 Share this post Link to post Share on other sites
Stapo 1 Posted March 11, 2013 hmm thanks, but still a no go... this is what i have now: victim = _this select 0; killer = _this select 1; victim_side = player getVariable "player_side"; killer_side = side killer; SKmessage = {titleText ["SPAWN KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; TKmessage = {titleText ["TEAM KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; if (victim == killer) exitWith {}; if (victim_side == WEST) then { if (killer_side == victim_side) then { [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; } else { if ((victim distance getMarkerPos "Respawn_west" < 100) || (victim distance getMarkerPos "Respawn_west_1" < 50) || (victim distance getMarkerPos "Respawn_west_2" < 75)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; }; }; if (victim_side == EAST) then { if (killer_side == victim_side) then { [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; } else { if ((victim distance getMarkerPos "Respawn_east" < 100) || (victim distance getMarkerPos "Respawn_east_1" < 75) || (victim distance getMarkerPos "Respawn_east_2" < 50)) then { [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; }; }; }; and its giving out the wrong messages... and its just broken. i really starting to think that the side command is broken... Share this post Link to post Share on other sites
squeeze 22 Posted March 11, 2013 victim_side = player getVariable "player_side"; so this line will give the side of the player, different on every computer null on dedicated server.....so make sure this script only runs on the victims computer for it to work, if it runs on the killers computer you'll get the killers side. Share this post Link to post Share on other sites
Stapo 1 Posted March 11, 2013 (edited) victim_side = player getVariable "player_side"; so this line will give the side of the player, different on every computer null on dedicated server.....so make sure this script only runs on the victims computer for it to work, if it runs on the killers computer you'll get the killers side. as you can see here, this is in my init.sqf of the mission: player setVariable ["player_side",playerside]; _punishment = player addMPEventHandler ["MPKilled", {null = _this execVM "punish.sqf";}]; only the player thats killed executes the scripts.... i even diag_log'd the side and they were correct. this script is just driving me nuts... Edited March 11, 2013 by Stapo Share this post Link to post Share on other sites
squeeze 22 Posted March 11, 2013 change the way you use "player" also in your init.sqf put this "waitUntil{!isNull player}" before you use the player command......good luck or have fun going nuts:bounce3: only the player thats killed executes the scripts......look againMP notes: "Killed" and "Hit" eventhandlers are executed where given unit is local. All other eventhandlers are executed on all computers. Coding advice: Call a function from the MPKilled EH code space, rather to define the full code in there directly. The reason is the code space will be transferred over network on each event activation - so keep the data as small as possible! Share this post Link to post Share on other sites
Stapo 1 Posted March 12, 2013 ok so im trying something a tad different... as in moving from MPkilled to just Killed. here is what i have atm: INIT.SQF: player setVariable ["player_side",playerside]; _punishment = player addEventHandler ["Killed", {_this execVM "punish.sqf"}]; PUNISH.SQF: victim = _this select 0; killer = _this select 1; victim_side = player getVariable "player_side"; killer_side = side killer; TKmessage = {titleText ["TEAM KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; SKmessage = {titleText ["SPAWN KILLING IS NOT ALLOWED!", "BLACK IN",8];killer setDamage 1;}; if (victim == killer) exitWith {}; if (victim_side == WEST) then { if (killer_side == WEST) then { //diag_log format ["TEAM-KILL (BLUFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; }; if (killer_side == EAST) then { if ((victim distance getMarkerPos "Respawn_west" < 100) || (victim distance getMarkerPos "Respawn_west_1" < 50) || (victim distance getMarkerPos "Respawn_west_2" < 75)) then { //diag_log format ["SPAWN-KILL (BLUFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; } else { //diag_log format ["KILL (BLUFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; }; }; }; if (victim_side == EAST) then { if (killer_side == EAST) then { //diag_log format ["TEAM-KILL (OPFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; [[],"TKmessage",killer,true,true] spawn BIS_fnc_MP; killer setDamage 1; }; if (killer_side == WEST) then { if ((victim distance getMarkerPos "Respawn_east" < 100) || (victim distance getMarkerPos "Respawn_east_1" < 75) || (victim distance getMarkerPos "Respawn_east_2" < 50)) then { //diag_log format ["SPAWN-KILL (OPFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; [[],"SKmessage",killer,true,true] spawn BIS_fnc_MP; } else { //diag_log format ["KILL (OPFOR) == VICTIM SIDE: %1 - KILLER SIDE: %2", victim_side, killer_side]; }; }; }; and i tested all the outcomes with diag_logs and everything come up clean... only problem im having now is that now the victim also gets the messages on his screen... maybe because its not using MPkilled... but im still a learner :) im getting there Share this post Link to post Share on other sites
Tajin 348 Posted March 12, 2013 (edited) Cleaned it up a bit and made some logical changes. Didn't test any of it yet, hope it helps. ;) Init.sqf TKmessage = {titleText ["TEAM KILLING IS NOT ALLOWED!", "BLACK IN",8]; player setDamage 1;}; SKmessage = {titleText ["SPAWN KILLING IS NOT ALLOWED!", "BLACK IN",8]; player setDamage 1;}; punishment = player addEventHandler ["Killed", {_this execVM "punish.sqf"}]; punish.sqf victim = _this select 0; killer = _this select 1; victim_side = side (group victim); killer_side = side (group killer); if (victim == killer) exitWith {}; if (victim_side == killer_side) then { [[],"TKmessage",killer,true,false] spawn BIS_fnc_MP; } else { if ( killer_side == EAST && ((victim distance getMarkerPos "Respawn_west" < 100) || (victim distance getMarkerPos "Respawn_west_1" < 50) || (victim distance getMarkerPos "Respawn_west_2" < 75)) ) then { [[],"SKmessage",killer,true,false] spawn BIS_fnc_MP; }; if ( killer_side == WEST && ((victim distance getMarkerPos "Respawn_east" < 100) || (victim distance getMarkerPos "Respawn_east_1" < 75) || (victim distance getMarkerPos "Respawn_east_2" < 50)) ) then { [[],"SKmessage",killer,true,false] spawn BIS_fnc_MP; }; }; // Edited March 12, 2013 by Tajin Share this post Link to post Share on other sites
Stapo 1 Posted March 13, 2013 @Tajin, thanks a bunch man... worked great :D i will credit you when i release my mission later on today. ---------- Post added at 16:15 ---------- Previous post was at 15:40 ---------- http://forums.bistudio.com/showthread.php?149745-Ultimate-Team-Deathmatch Share this post Link to post Share on other sites