Jump to content
Sign in to follow this  
HulkingUnicorn

Arresting teamkillers - problem with script

Recommended Posts

After being annoyed by teamkillers in multiplayer, I decided to come up with some sort of punishment for tk'ers or "scare factor" for potential ones.

I want to put a teamkilling player into the tower NE of Mercaillo for a certain amount of time - 1 to 5 minutes or depending on if it was a first offense or not.

I put three guys into the editor for this test mission (all playable) - mana, manb, and manc. I also put a wall in front of the door and an object inside the tower for getting position.

However, there seems to be something wrong with my script - could anyone help me? When previewing in the editor I'm placed in the tower and my weapons are removed (I also see the hint stating HulkingUnicorn as a teamkiller), but the while imprisoned block doesn't seem to be working.

Init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addeventhandler ["killed", {[_this select 0, _this select 1] execVM "prison.sqf"}]} foreach [mana, manb, manc]

From the prison.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_victim = _this select 0;

_killer = _this select 1;

if (name _victim == name _killer) exitWith {echo "Suicide!";};

if !(isplayer _killer) exitWith {echo "Teamkiller is an ai!";};

_killername = name _killer;

hint format ["%1 has been arrested for teamkilling!", _killername];

if !(local _killer) exitWith {echo "";};

removeallweapons _killer;

_origpos = getpos _killer;

_nolongerimprisoned = false;

_imprisoned = true;

_killer setpos [(getpos prison select 0), (getpos prison select 1), 18];

_timer = 0;

while {_imprisoned} do

{

_killer setdammage 0;

if (_killer distance prison > 50) then _killer setpos [(getpos prison select 0), (getpos prison select 1), 18];

_timer = (_timer + 1);

text format ["Timer: %1", _timer];

sleep 1;

if (_timer >= 30) {_nolongerimprisoned = true; _imprisoned = false;};

};

if (_nolongerimprisoned) {_killer setpos _origpos; _killer addmagazine "M9"; _killer addweapon "M9";};

Share this post


Link to post
Share on other sites

Heya, First fix:

if (_killer distance prison > 50) then {_killer setpos [(getpos prison select 0), (getpos prison select 1), 18];};

2nd fix:

if (_timer >= 30) then {_nolongerimprisoned = true; _imprisoned = false;};

3rd fix:

if (_nolongerimprisoned) then {_killer setpos _origpos; _killer addmagazine "M9"; _killer addweapon "M9";};

(btw you can use init.sqf. Aswell as preload the script:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">scr_prison=compile preprocessfile "prison.sqf";

{_x addeventhandler ["killed", {d=[_this select 0, _this select 1] spawn scr_prison;}];} foreach [mana, manb, manc];

btw, for the script you showed it doesnt seem you need the _nolongerimprisoned variable as the loop breaks only if he _imprisoned becomes false (after 30 secs).

and I dont think that "text format ["Timer: %1", _timer];" will output anything as text only structures the text? No idea what the structuring means but I would say it should be sth like:

hint text format ["Timer: %1", _timer];

or

hint format ["Timer: %1", _timer];

Share this post


Link to post
Share on other sites

Thanks mate, no error message now! Atleast not until it tries to add ammo for the m9 - guess I have to change the ammoname... It's my first sqf script, so I'm not exactly steady on what's required and where it's required - even after careful use of the biki.

I was kind of insecure about that last var too - figured maybe the last part of the script could be executed during/before the loop or something. I'm kind of reluctant to execute with init.sqf, as I designed it with another mission in mind (which uses init.sqs) and don't feel like rewriting it in sqf format.

But the preprocessing sounds interesting, but puzzling. What exactly is the point/advantage of using it? The biki didn't tell me too much.

Share this post


Link to post
Share on other sites

Rgr that and no biggy smile_o.gif

But the preprocessing sounds interesting, but puzzling. What exactly is the point/advantage of using it? The biki didn't tell me too much.
The point of the preloading is that the script now is compiled & read into memory at the start.. Later when the script is needed, it will be read from memory and executed... If the script repeats multiple times, you would save the need to read, and compile the script everytime over and over from disk if you use this method.

(btw the init.sqf example I gave should work just as well in an sqs, so np)

Share this post


Link to post
Share on other sites

You're right, of course - text format didn't even output anything! Hint format works as always, but I wanted to have plain text instead. Maybe using str to convert it first or something, I guess.

Tested your way of executing it, and it works - I suppose preprocessing an anti-tk scripts is a good idea sad_o.gif

Also put "15Rnd_9x19_M9" as mag for M9 - worked as well.

Removed the _nolongerimprisoned and put:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if !(_imprisoned) then {blah blah}; and now I'm one var slimmer.

Now to test it in MP and find a way to make if work if player respawns/changes role/disconnects, then reconnects.

Share this post


Link to post
Share on other sites

So far the test results online are negative...

When testing alone in MP, it works, but with several people only the hint is displayed.

I'll try to remove the local check - maybe that will help.

Edit:

Today (15.02.06) I did a successful test! A test with several people and several arrests. Offenders got arrested, but weapons were not removed (as they did with only 1 person and an identical version) - also the wall I used to close the tower was placed lower than usual (for some obscure reason). People also get put back in the tower if they run away.

I'm planning to create some sort of system that will put you back in jail if you respawn or disconnect - any input on how to do this would be nice.

Working code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_victim = _this select 0;

_killer = _this select 1;

_punishment = 180;

if (name _victim == name _killer) exitWith {echo "Suicide!";};

if !(isplayer _killer) exitWith {echo "Teamkiller is an ai!";};

_killername = name _killer;

hint format ["%1 has been arrested for teamkilling!\n%1 will be confined for %2 seconds.", _killername, _punishment];

comment "if !(local _killer) exitWith {echo "";}";

removeallweapons _killer;

_origpos = getpos _killer;

_nolongerimprisoned = false;

_killer setpos [(getpos prison select 0), (getpos prison select 1), 18];

_timer = 0;

_imprisoned = true;

while {_imprisoned} do

{

_killer setdammage 0;

removeallweapons _killer;

if (_killer distance prison > 50) then {_killer setpos [(getpos prison select 0), (getpos prison select 1), 18];};

_timer = (_timer + 1);

sleep 1;

if (_timer >= _punishment) then {_imprisoned = false;};

};

if !(_imprisoned) then {_killer setpos _origpos; _killer addmagazine "15Rnd_9x19_M9"; _killer addweapon "M9";};

Share this post


Link to post
Share on other sites

Thanks for the pm.

I tink someting is posible with the onplayerdisconnected and connect commands.

If for example you could some how save a name for the lenght of the mission the guy could be put back when he reconnects.

Share this post


Link to post
Share on other sites

After looking into the onPlayerDisconnected/Connected commands, I don't think they fit well - thank you for the suggestion though.

I'm right in the middle of a major rewriting of the system right now - and my head is in danger of exploding, lol banghead.gif

prison.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//Script run by init.sqs

//Gamelogic called prison should be placed at the prisons location

if (!local prison) exitWith {};

_units = _this select 0;

_punishment = _this select 1;

_cycle = 1;

//List over offending PLAYERS:

Offenders = 0;

//List over UNITS controlled by offending players

_unitsOffenders = 0;

publicVariable "Offenders";

//This part will loop for the length of the mission:

for {_forever = 1} {_forever > 0} {_forever = _forever} do

{

//Run a test for each unit to see if they belong to a teamkilling player:

_count = count _units;

_i = 0;

while {_i < _count} do

{

_z = (_units select _i);

//Is the unit under a TKing players control?

if (name _z in Offenders) then

{

if (_z in _unitsOffenders) then

{

//Do nothing as the offending players unit has already been identified and added to the list

} else

{

//Unit under TKing player found - add him to the big bad list

_unitsOffenders = _unitsOffenders + _z;

};

} else

{

//If the unit is not under a TKing players control, but on the list, remove him from the list

if (_z in _unitsOffenders) then

{

_unitsOffenders = _unitsOffenders - _z;

};

};

_i = _i + 1;

};

//Current units of TKing players should now have been identified - now the player(s) will be punished

_count = count _unitsOffenders;

_i = 0;

while {_i < _count} do

{

_z = (_unitsOffenders select _i);

if ((_z distance prison) <= 50) then

{

//Do 'nothing', as the player is taking his or hers punishment

} else

{

//Unit is not in prison - he will be dealt with:

globalChat format ["%1 has been apprehended for team killing! %1 will be confined for %2 seconds. An unsuccessful escape will be rewarded with re-confinement :)", (name _z), _punishment];

_scriptReference = format ["imprison%1", _z];

//If the culprit tried escaping jail, reset imprison script:

if !(scriptDone _scriptReference) then

{

terminate _scriptReference;

};

//Spawn uniquely identified script that puts the criminal in prison, and counts down the timer (based on_punishment)

//The script will get the original position of the unit before imprisoning it and will return it there once the sentence has been served

//It will also remove the players nick from the Offenders list and broadcast the updated list

_scriptReference = [_z, _punishment] spawn "_imprison";

};

_i = _i + 1;

};

sleep _cycle;

};

Somehow I have a feeling the _scriptReference spawn thing won't work... Can anyone help with that? Finding any other problems is also appreciated wink_o.gif

Fixing those spaces took awhile...

dtctTK.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//Script called by eventhandler 'killed' - written with coops in mind, so it doesn't take side into consideration (yet)

_victim = _this select 0;

_killer = _this select 1;

if ( (_victim != _killer) && (isPlayer _killer) )then

{

//If a player has TK'ed, put his NICK on the list:

Offenders = Offenders + (name _killer);

publicVariable "Offenders";

removeAllWeapons _killer;

};

(this script should be working)

imprison.sqf isn't written yet tounge2.gif

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  

×