John

Script assistance request

21 posts in this topic

Hi friends.

Just looking for some help with this.

So, on my server I have configured it so when you are shot, you can bleed to death. This is a very simple change that piggy backs off the current system where when a player is at 0% hunger and thirst they slowly die. There is some code that looks for isBleeding and if this is true, applies the exact effects. Anyways.. Here is my code with my questions included.

Basically, the bleeding works marvelously however, the issue I have is when a player bleeds out, the killer does not get credit for the kill so below, I am trying to get around this by saving the last source of damage that was not Null.

I know this can be done, I have just exhausted my research and have come up with this, and rather than spend hours of time testing it I was looking for some advice by some more experienced people that me, to filter out the mistakes if I have made any =)

Thanks - 

File = ExileClient_object_event_onHandleDamage.sqf

So below, what I am trying to do with the last 4 lines is if the source of damage is NOT null, I want to save it and call it in MPKilled. The onMPkilled file is below this block of code.

private["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile"];
_unit             = _this select 0;
_selectionName    = _this select 1;
_amountOfDamage   = _this select 2;
_sourceOfDamage   = _this select 3;
_typeOfProjectile = _this select 4;

if (_typeOfProjectile == "") then // Filters out fall damage, car crashing etc.
{
}
else
{	
	player setBleedingRemaining 90; // Bleed ofr 90 seconds.
};

// Get the last source of damage that was not null (IE player damage) and save it as a global variable
if (!isNull _sourceOfDamage) then 
{
	_unit setVariable ["LastDamaged",_sourceOfDamage];
};

ExileClient_object_player_event_onMPKilled.sqf

I have not inserted the entire onMPKilled, only the first section and have noted by custom block by "Unrest Custom"

private["_victim","_killer","_victimPosition","_addDeathStat","_addKillStat","_normalkill","_killerRespectPoints","_fragAttributes","_player","_grpvictim","_grpkiller","_log","_lastVictims","_victimUID","_vehicleRole","_vehicle","_lastKillAt","_killStack","_distance","_distanceBonus","_flagNextToKiller","_homieBonus","_flagNextToVictim","_raidBonus","_overallRespectChange","_newKillerScore","_killMessage","_newKillerFrags","_newVictimDeaths"];
if (!isServer || hasInterface) exitWith {};
_victim = _this select 0;
_killer = _this select 1;
//Unrest Custom
if (isNull _killer) then //If _killer is object null then get the LastDamaged variable set from HandleDamage
{
	_lastDamaged = getVariable "LastDamaged";

	if (!isNull _lastDamaged) then 
	{	
		_killer = _lastDamaged; // Set _killer as the last source of damage, the rest of the code then does its thaang.
	};
};
//Unrest custom End
if( isNull _victim ) exitWith {};
_victim setVariable ["ExileDiedAt", time];
if !(isPlayer _victim) exitWith {};
_victimPosition = getPos _victim;
format["insertPlayerHistory:%1:%2:%3:%4:%5", getPlayerUID _victim, name _victim, _victimPosition select 0, _victimPosition select 1, _victimPosition select 2] call ExileServer_system_database_query_fireAndForget;
format["deletePlayer:%1", _victim getVariable ["ExileDatabaseId", -1]] call ExileServer_system_database_query_fireAndForget;
_victim setVariable ["ExileIsDead", true];
_victim setVariable ["ExileName", name _victim, true]; 
_victim call ExileServer_object_flies_spawn;
_addDeathStat = true;
_addKillStat = true;
_normalkill = true;
_killerRespectPoints = [];
_fragAttributes = [];
if (_victim isEqualTo _killer) then

 

1 person likes this

Share this post


Link to post
Share on other sites

hey John,

 

Ok so your def headed the right direction! :)

 

quick a few questions... are you allowing the player to stop their bleeding in say another script? EG:     _unit setVariable ["LastDamaged",isNull]; 

because i can just see if they can stop their bleeding but fall off a cliff... well the handledamage is still going to tell the mpkilled that they were killed by whoever last caused their bleeding... tho it may exit out with there not being a "victim" as such... not sure havent tested it...

Ok so anyway have been playing with ur code a little bit. pretty similar to how i am doing a revive script been mucking around with.

One thing, you need to also pass the distance the player was at when you started the bleeding out... otherwise you will get players distance 90seconds after they were shot... A) the shooter drives off and gets a 2km kill shot B) the killer moves in from a sniper spot and gets only a regular kill.

Was rewriting your script how i would do it and then just realised this:

    _lastDamaged = getVariable "LastDamaged";

should be:

    _lastDamaged = _victim getVariable "LastDamaged";

havent tested if it works now but im assuming you tested with hints/diag_log's to make sure the structure was executing right in your code and it just wasnt working?

If thats the case then your just not getting the variable from the victim as to who killed them.

regarding updating distance just do something like this: onmpkilled....

_distance = _victim getVariable "LastDamagedDistance"; //update distance the killer was at! 

if (_distance > 0) then { //checks if variable was passed!
_distance = floor(_distance);
} else {
_distance = floor(_victim distance _killer); //default distance calculation just in case???
};

onhandledamage...

_savedistance = _unit distance _sourceOfDamage;
_unit setVariable ["LastDamagedDistance", _savedistance];

 

let me know if it all works. if not i half wrote how i would have done the same script :) and ill finish that off.

 

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement
1 hour ago, happydayz said:

 

@happydayz Hey mate thanks for the reply.

So. To answer your questions, players can stop bleeding using a bandage.

So my thoughts are, it never matters if the variable is null, because lets say a player gets shot and he bleeds. the variable will be _lastEnemy (bob for example) but if they player stops his bleeding the variable remains? ok thats fine. For the player to die he must again take damage. Which will update the variable to whichever is needed and so onMPKilled should be relevant?

Not sure why I need to pass distance though? Are u meaning if im using kill feed or something? If so I don't care about that at all.

 

Share this post


Link to post
Share on other sites

distance is used in the mpkilled to determine how far the killer was yeah?  so you are adding in a bleedout that acts like a delay in the amount of time that the victim could run around bleeding out before they die. Now the question is - do you want the original shooter who caused the bleeding to get the respect? If yes then while the player runs around looking for a bandage while bleeding out, the distance hasnt been set in mpkilled. it doesnt get set until the victim actually dies. so if they ran say 200m in that 90 second bleedout, the shooter that caused them to die will gain an extra 200m worth of bonus respect as the distance isnt determined until they actually die when it takes the current position at time of death of the victim and killer.

1 person likes this

Share this post


Link to post
Share on other sites

the variable wont get updated if the player falls off a building. it stays as the last person who shot them. you need to set it to null if they take fall damage.

Share this post


Link to post
Share on other sites
1 hour ago, happydayz said:

 

Ok, so distance is not needed for me, I dont care about distance.

Regarding your second one about fall damage.

I see what you mean, if the shooter hits the target then he later takes fall damage and dies, the shooter is still the last enemy. I need to work around this.

I think a simple timeout can get rid of this. I am on the right track it seems!

Edited by John

Share this post


Link to post
Share on other sites

no timeout needed :) 

 

if (_typeOfProjectile == "") then // Filters out fall damage, car crashing etc.
{
	_unit setVariable ["LastDamaged",nil];
}

Share this post


Link to post
Share on other sites
6 minutes ago, happydayz said:

no timeout needed :) 

 


if (_typeOfProjectile == "") then // Filters out fall damage, car crashing etc.
{
	_unit setVariable ["LastDamaged",nil];
}

Yeh. that wont work because. Bleed damage is "" which means every bleed tick will overwrite lastDamaged and im back at square one! =(

 

edit - actually its not , bleed damage is setDamage... so im not even sure what that is. Maybe it is null..?

 

Edited by John

Share this post


Link to post
Share on other sites

the nil should make the variable not exist. whereas the "" is still a string... just an empty string... I think??? lol

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.