Restrict Krixes SelfBloodBag only to a special Location

Good idea but a few pointers for you...

1. Your use of exitWith {} could lead to undefined behavior as per http://community.bistudio.com/wiki/exitWith. It is definitely not a good idea to use it the way you are using it within this script. It is for breaking out of loops... not exiting scripts.

2. Keep variables and comments in one language; don't mix.

3. Follow the standard conventions in terms of variable naming. In some cases you use proper camel case (_playerASL) and in others you don't (_Hospitalfound). Follow the same convention so it isn't painful to look through your code.

4. Don't use 1 and 0 for boolean operations; use true and false instead. Boolean comparisons are typically faster than numerical comparisons... Thus less server load.
 
How is that if I want to add the "HMMWV_Ambulance".

Is the right way?
Code:
_HospitalDistance = 21; //Max distancewithin Hospital
_AmbulanceDistance = 5; // Max. Distance to get Ambulancebonus
_Bloodmultiplier = 1; // Blood amount multiplier (1 if not in Hospital or near Ambulance, 1.5 if near an Ambulance, 2 if near a Hospital, The Multiplier for Ambulance and Hospital get set later)
_Infectionmultiplier = 0.5; // Multiplier for infectionchance if in Hospital 0.5, 0.75 for an Ambulance, 1 if not in a Hospital (The higher the Value the lower the chance to get infected (it must never get 0 because of division by 0)
_Hospital_enable = 1; // 1 enables SelfBloodbag in Hospitals
_Ambulance_enable = 1; // 1 enables SelfBloodbag near Ambulances
_Anywhere_enable = 0; // 1 enables SelfBloodBag anywhere; (Turns automatically on if _Hospital_enable = 0 and _Ambulance_enable = 0;)
 
_nearHospital = false;
if ((_Hospital_enable == 0) && (_Ambulance_enable == 0)) then { // Check if _Hospital_enable & _Ambulance_enable disabled
    _Anywhere_enable = 1;
    };
if (_Anywhere_enable == 1) then {
        _nearHospital = true;
};
if (_Hospital_enable == 1)  then { // if Hospital enabled
        _playerASL1 = getPosASL player;
        _playerASLx = _playerASL1  select 0;
        _playerASLy = _playerASL1  select 1;
        _playerASLz = _playerASL1  select 2;
        _playerASLz2 = _playerASLz + 40;
        _playerASL2 = [_playerASLx,_playerASLy,_playerASLz2];
        _decke = lineIntersects[_playerASL1,_playerASL2]; //überprüft ob sich zwischen dem Player und (Player+40m höhe) ein Objekt befindet (benötigt unbedingt ASL Koordinaten)
        _Hospitalfound = count nearestObjects[player,["Land_A_Hospital"],_HospitalDistance]; // check if near Hospital
        if ((_Hospitalfound > 0) && _decke) then {
                _nearHospital = true;
                _Bloodmultiplier = 2; // multiplier to Bloodamount
                _Infectionmultiplier = 0.5; //multiplier to Infectionchance
            };
    };
if (_Ambulance_enable == 1)  then {
        _Ambulancefound = count nearestObjects[player,["GAZ_Vodnik_MedEvac"],_AmbulanceDistance]; // check if near Vodnik
        _Ambulancefound = count nearestObjects[player,["HMMWV_Ambulance"],_AmbulanceDistance]; // check if near Vodnik
        if (_Ambulancefound > 0 ) then {
                _nearHospital = true;
                _Bloodmultiplier = 0.75;
            };
    };
_bloodAmount = _bloodAmount * _Bloodmultiplier; // Calculate bloodamount & Infectionchance with the multiplier
_infectionChance = _infectionChance / _Infectionmultiplier;
 
if(!_nearHospital) exitWith { // Abort messegas if Conditions not met
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 0)) then {
            cutText [format["You need to be inside a Hospital to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 0) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near a Hospital or an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
};
 
Good idea but a few pointers for you...

1. Your use of exitWith {} could lead to undefined behavior as per http://community.bistudio.com/wiki/exitWith. It is definitely not a good idea to use it the way you are using it within this script. It is for breaking out of loops... not exiting scripts.

2. Keep variables and comments in one language; don't mix.

3. Follow the standard conventions in terms of variable naming. In some cases you use proper camel case (_playerASL) and in others you don't (_Hospitalfound). Follow the same convention so it isn't painful to look through your code.

4. Don't use 1 and 0 for boolean operations; use true and false instead. Boolean comparisons are typically faster than numerical comparisons... Thus less server load.


Thanks for your suggestions. This was my first arma script snipplet :). I used exitWith, because Krixes also used it in the selfbloodbag :). As already mentioned yesterday, i will rewrite the script as soon as i can, because at moment im pretty busy with other scripts that have higher priority on our server. :)
 
Code:
 _Ambulancefound = count nearestObjects[player,["GAZ_Vodnik_MedEvac","HMMWV_Ambulance"],_AmbulanceDistance];
 
But this won't work with mods where you can change the skin.
You can read the humanity from database with
Code:
getVariable["humanity",0];
without any Problems.
Not really from database, but it does not matter.
You think I could use it to assign load-outs based on someone's humanity level? I could never seem to get it to work right.
 
You can also merge this with humanity restrictions, so that a Hero, who is basically a medic, can self blood bag anywhere and is exempt from needing to be near a medical building. Customizing further, you can give hero's more blood and/or less of a chance of infection too.

Good incentive for players who want to play a good guy.

Thanks for the enhancements to the script Panadur!



Hi, I know this is an old thread but this is exactly what I am trying to do, I have a humanity req for my selfBB

Code:
// ------------------------------------------------------------------------Krixes Self Bloodbag Start------------------------------------------------------------------------
PlayerHumanity = (player getVariable"humanity");
if ((getPlayerUID player) in ["XXXXXXXX"] or (PlayerHumanity < -15000) or (PlayerHumanity > 7000)) then {
_mags = magazines player;
 
// Krixes Self Bloodbag

and I want to merge it with this hospital restriction so only heroes can self BB and anyone else has to be in a hospital to do it. What I am wondering is if I have to change any of the code or just implement this as is... Dont want heroes to have to be in a hospital to bb you know? lol
 
So you want to have heroes able to do it anywhere but everyone else needs to be near a hospital right?

just add

_Hospitalfound = count nearestObjects[player,["Land_A_Hospital"],20]; // check if near Hospital

and

if ( (getPlayerUID player) in ["XXXXXXXX"] or (PlayerHumanity < -15000) or (PlayerHumanity > 7000) or (_Hospitalfound)) then {

you can change 20 to whatever you want the distance to be

EDIT: overlooked a section, sorry
 
well I got the BB with hosp/amb restriction to work flawlessy, however as soon as I add the humanity req code and make your suggested changes, (thank you btw) I lose everything and self BB doesnt even show up on scroll menu anymore heres my code maybe you can tell me where i went awry.


heres fn self actions; I have a feeling the problem is here as the self BB option no longer shows on the menu
Code:
// -----------------------------------------------------------------------Krixes Self Bloodbag Start------------------------------------------------------------------------
PlayerHumanity = (player getVariable"humanity");
if ((getPlayerUID player) in ["XXXXXXXX"] or (PlayerHumanity < -15000) or (PlayerHumanity > 5000) or (_Hospitalfound)) then {
_mags = magazines player;
// Krixes Self Bloodbag
if ("ItemBloodbag" in _mags) then {
hasBagItem = true;
} else { hasBagItem = false;};
if((speed player <= 1) && hasBagItem && _canDo) then {
if (s_player_selfBloodbag < 0) then {
s_player_selfBloodbag = player addaction[("<t color=""#c70000"">" + ("Self Bloodbag") +"</t>"),"Scripts\player_selfbloodbag.sqf","",5,false,true,"", ""];
};
} else {
player removeAction s_player_selfBloodbag;
s_player_selfBloodbag = -1;
};
 
// -------------------------------------------------------------------------Krixes Self Bloodbag End----------------------
heres the player_selfbloodbag.sqf;
Code:
private ["_bloodAmount","_humanityBool","_infectionChance","_humanityNegBool","_humanityNegAmount","_humanityAmount","_infectedLifeLost","_infectedLifeBool","_lastBloodbag","_bloodbagLastUsedTime","_bloodbagTime","_bloodbagUseTime","_bloodbagUsageTime","_HospitalDistance","_AmbulanceDistance","_Bloodmultiplier","_Infectionmultiplier","_Hospital_enable","_Ambulance_enable","_Anywhere_enable","_nearHospital","_playerASL1","_playerASLx","_playerASLy","_playerASLz","_playerASLz2","_playerASL2","_decke","_Hospitalfound","_Ambulancefound","_bloodAmount","_infectionChance"];
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Config Start-----------------------------------------------------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_bloodAmount = 4000; // Amount of blood to give to player
_bloodbagUseTime = 30; // Amount of time it takes in second for the player to use the self bloodbag
_bloodbagLastUsedTime = 60; // Amount of time in seconds before player can use self bloodbag again after a succesful use
_infectionChance = 10; // Percent chance of player infection on self bloodbag (10 = 10% | 2 = 50% | 1 = 100%)
_infectedLifeBool = true; // Whether the player can loose life if infected (True = On | False = off)
_infectedLifeLost = 1000; // Amount of life to loose in becomes infected
_humanityBool = false; // Whether the player can get humanity from giving self a bloodbag (True = On | False = off)
_humanityAmount = 50; // Amount of humanity to give player if _humanityBool is true (250 is default for normal bloodbags)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Config End-------------------------------------------------------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_HospitalDistance = 21; //Max distancewithin Hospital
_AmbulanceDistance = 5; // Max. Distance to get Ambulancebonus
_Bloodmultiplier = 1; // Blood amount multiplier (1 if not in Hospital or near Ambulance, 1.5 if near an Ambulance, 2 if near a Hospital, The Multiplier for Ambulance and Hospital get set later)
_Infectionmultiplier = 0.5; // Multiplier for infectionchance if in Hospital 0.5, 0.75 for an Ambulance, 1 if not in a Hospital (The higher the Value the lower the chance to get infected (it must never get 0 because of division by 0)
_Hospital_enable = 1; // 1 enables SelfBloodbag in Hospitals
_Ambulance_enable = 1; // 1 enables SelfBloodbag near Ambulances
_Anywhere_enable = 0; // 1 enables SelfBloodBag anywhere; (Turns automatically on if _Hospital_enable = 0 and _Ambulance_enable = 0;)
 
_nearHospital = false;
if ((_Hospital_enable == 0) && (_Ambulance_enable == 0)) then { // Check if _Hospital_enable & _Ambulance_enable disabled
    _Anywhere_enable = 1;
    };
if (_Anywhere_enable == 1) then {
        _nearHospital = true;
}; 
if (_Hospital_enable == 1)  then { // if Hospital enabled
        _playerASL1 = getPosASL player;
        _playerASLx = _playerASL1  select 0;
        _playerASLy = _playerASL1  select 1;
        _playerASLz = _playerASL1  select 2;
        _playerASLz2 = _playerASLz + 40;
        _playerASL2 = [_playerASLx,_playerASLy,_playerASLz2];
        _decke = lineIntersects[_playerASL1,_playerASL2]; //überprüft ob sich zwischen dem Player und (Player+40m höhe) ein Objekt befindet (benötigt unbedingt ASL Koordinaten)
        _Hospitalfound = count nearestObjects[player,["Land_A_Hospital"],20]; // check if near Hospital
        if ((_Hospitalfound > 0) && _decke) then {
                _nearHospital = true;
                _Bloodmultiplier = 2; // multiplier to Bloodamount
                _Infectionmultiplier = 0.5; //multiplier to Infectionchance
            };
    }; 
if (_Ambulance_enable == 1)  then {
        _Ambulancefound = count nearestObjects[player,["GAZ_Vodnik_MedEvac"],_AmbulanceDistance]; // check if near Vodnik
        if (_Ambulancefound > 0 ) then {
                _nearHospital = true;
                _Bloodmultiplier = 0.75;
            }; 
    };
_bloodAmount = _bloodAmount * _Bloodmultiplier; // Calculate bloodamount & Infectionchance with the multiplier
_infectionChance = _infectionChance / _Infectionmultiplier;
 
if(!_nearHospital) exitWith { // Abort messegas if Conditions not met
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 0)) then {
            cutText [format["You need to be inside a Hospital to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 0) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near a Hospital or an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
};
 
I only have a minute so I'll only address what I saw as I skimmed it, though it may be enough to fix it. In your fn_selfactions you have (_Hospitalfound) being used without being defined. If it's defined elsewhere then let me know and I'll look through it again when i have more time but if not then add

_Hospitalfound = count nearestObjects[player,["Land_A_Hospital"],20];

under

PlayerHumanity = (player getVariable "humanity");

let me know if this fixes it. Good luck!
 
_Hospitalfound = count nearestObjects[player,["Land_A_Hospital"],_nearHospital]; was already in plyer_selfbloodbag.sqf line 39 of the example but I altered it to look like your line. Also I tried to add this line into the fn_selfactions file but it didnt work for me, like I said self blood works perfectly in hospitals and amb's but when I add the humanity req it breaks.
 
I'm at a loss then, I'm sorry. You do understand that with the way you have it it should only work for anyone under -15000 or above 5000 humanity right? So anyone in between those two it wouldn't work for. I assume you do know this but I want to check anyway, I can't see why it wouldn't work.
 
yeah my humanity is currently at 7500 so it should work for me and I also cannot use BB in hospitals/ambulances anymore.. I am going to keep messing with it im sure it should work Thanks for all the help tho!
 
Hello guys !

I have problems adding this to epoch

fn selfactions

Code:
// ====================== Krixes Self Bloodbag Start ======================

    PlayerHumanity = (player getVariable"humanity");
    if ((getPlayerUID player) in ["uid"] or (PlayerHumanity < -15000) or (PlayerHumanity > 5000) or (_Hospitalfound)) then {

   _mags = magazines player;

   // Krixes Self Bloodbag
   if ("ItemBloodbag" in _mags) then {
       hasBagItem = true;
    } else { hasBagItem = false;};
    if((speed player <= 1) && hasBagItem && _canDo) then {
        if (s_player_selfBloodbag < 0) then {
            s_player_selfBloodbag = player addaction[("<t color=""#c70000"">" + ("Self Bloodbag") +"</t>"),"scripts\player_selfbloodbag.sqf","",5,false,true,"", ""];
        };
    } else {
        player removeAction s_player_selfBloodbag;
        s_player_selfBloodbag = -1;
    };
// ====================== Krixes Self Bloodbag End ======================

script

Code:
private ["_bloodAmount","_humanityBool","_infectionChance","_humanityNegBool","_humanityNegAmount","_humanityAmount","_infectedLifeLost","_infectedLifeBool","_lastBloodbag","_bloodbagLastUsedTime","_bloodbagTime","_bloodbagUseTime","_bloodbagUsageTime","_HospitalDistance","_AmbulanceDistance","_Bloodmultiplier","_Infectionmultiplier","_Hospital_enable","_Ambulance_enable","_Anywhere_enable","_nearHospital","_playerASL1","_playerASLx","_playerASLy","_playerASLz","_playerASLz2","_playerASL2","_decke","_Hospitalfound","_Ambulancefound","_bloodAmount","_infectionChance"];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Config Start-----------------------------------------------------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_bloodAmount = 4000; // Amount of blood to give to player
_bloodbagUseTime = 30; // Amount of time it takes in second for the player to use the self bloodbag
_bloodbagLastUsedTime = 60; // Amount of time in seconds before player can use self bloodbag again after a succesful use
_infectionChance = 10; // Percent chance of player infection on self bloodbag (10 = 10% | 2 = 50% | 1 = 100%)
_infectedLifeBool = true; // Whether the player can loose life if infected (True = On | False = off)
_infectedLifeLost = 1000; // Amount of life to loose in becomes infected
_humanityBool = false; // Whether the player can get humanity from giving self a bloodbag (True = On | False = off)
_humanityAmount = 50; // Amount of humanity to give player if _humanityBool is true (250 is default for normal bloodbags)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Config End-------------------------------------------------------------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_HospitalDistance = 21; //Max distancewithin Hospital
_AmbulanceDistance = 5; // Max. Distance to get Ambulancebonus
_Bloodmultiplier = 1; // Blood amount multiplier (1 if not in Hospital or near Ambulance, 1.5 if near an Ambulance, 2 if near a Hospital, The Multiplier for Ambulance and Hospital get set later)
_Infectionmultiplier = 0.5; // Multiplier for infectionchance if in Hospital 0.5, 0.75 for an Ambulance, 1 if not in a Hospital (The higher the Value the lower the chance to get infected (it must never get 0 because of division by 0)
_Hospital_enable = 1; // 1 enables SelfBloodbag in Hospitals
_Ambulance_enable = 1; // 1 enables SelfBloodbag near Ambulances
_Anywhere_enable = 0; // 1 enables SelfBloodBag anywhere; (Turns automatically on if _Hospital_enable = 0 and _Ambulance_enable = 0;)
_nearHospital = false;
if ((_Hospital_enable == 0) && (_Ambulance_enable == 0)) then { // Check if _Hospital_enable & _Ambulance_enable disabled
    _Anywhere_enable = 1;
    };
if (_Anywhere_enable == 1) then {
        _nearHospital = true;
};
if (_Hospital_enable == 1)  then { // if Hospital enabled
        _playerASL1 = getPosASL player;
        _playerASLx = _playerASL1  select 0;
        _playerASLy = _playerASL1  select 1;
        _playerASLz = _playerASL1  select 2;
        _playerASLz2 = _playerASLz + 40;
        _playerASL2 = [_playerASLx,_playerASLy,_playerASLz2];
        _decke = lineIntersects[_playerASL1,_playerASL2]; //überprüft ob sich zwischen dem Player und (Player+40m höhe) ein Objekt befindet (benötigt unbedingt ASL Koordinaten)
        _Hospitalfound = count nearestObjects[player,["Land_A_Hospital","Land_A_GeneralStore_01","Land_a_stationhouse"],20]; // check if near Hospital
        if ((_Hospitalfound > 0) && _decke) then {
                _nearHospital = true;
                _Bloodmultiplier = 2; // multiplier to Bloodamount
                _Infectionmultiplier = 0.5; //multiplier to Infectionchance
            };
    };
if (_Ambulance_enable == 1)  then {
        _Ambulancefound = count nearestObjects[player,["GAZ_Vodnik_MedEvac","HMMWV_Ambulance"],_AmbulanceDistance]; // check if near Vodnik
        if (_Ambulancefound > 0 ) then {
                _nearHospital = true;
                _Bloodmultiplier = 0.75;
            };
    };
_bloodAmount = _bloodAmount * _Bloodmultiplier; // Calculate bloodamount & Infectionchance with the multiplier
_infectionChance = _infectionChance / _Infectionmultiplier;
if(!_nearHospital) exitWith { // Abort messegas if Conditions not met
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 0)) then {
            cutText [format["You need to be inside a Hospital to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 0) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
        if ((_Hospital_enable == 1) && (_Ambulance_enable == 1)) then {
            cutText [format["You need to be near a Hospital or an Ambulance to do this !!!"], "PLAIN DOWN"];
        };
};

adding all this breaks my entire fn_selfactions.sqf
 
@Fox the second part from

private ["_bloodAmount","_humanityBool","_infectionChance"

You did paste it in the player_selfbloodbag.sqf , the first part only needs to go in fn_selfactions.sqf
 
You have an open If with no closing bracket....

You need to add a closing }; next to the fn_selfActions selfbloodbag closing bracket.
 
Back
Top