Jump to content
TheBUTTERY_T

[How To] CPR Kit

Recommended Posts

Hello guys today i'm just going to start off by introducing my self, hi! I'm buttery and I like to do a lot of this in my spare time.. which is all the time to be honest

_____________________________________________________________________________________________________________________________________________________________________

What are we making?

What we are going to be doing here is making a CPR Kit which you can buy from the market.

What does it do?

The CPR Kit is used on down players, it has a 15% chance of revival every time it is used(has unlimited uses) and after every try it automatically restart the process till the player is picked up, unless you cancel the action.

_____________________________________________________________________________________________________________________________________________________________________

In core\items make a file called fn_cprkit.sqf

#include "..\..\script_macros.hpp"

private["_target","_revivable","_targetName","_ui","_progressBar","_titleText","_cP","_title"];
_target = [_this,0,Objnull,[Objnull]] call BIS_fnc_param;
if(isNull _target) exitWith {};

_revivable = _target getVariable ["Revive",false];
if (_revivable) exitWith {};
if(player distance _target > 5) exitWith {};
if(life_action_inUse) exitWith {};
if(player isEqualTo _target) exitWith {};

_title = format[localize "STR_CPR_Progress"];
life_action_inUse = true;

_target setVariable ["Reviving",player,TRUE];
//Setup our progress bar
disableSerialization;
5 cutRsc ["life_progress","PLAIN"];
_ui = uiNamespace getVariable ["life_progress",displayNull]; 
_progressBar = _ui displayCtrl 38201;
_titleText = _ui displayCtrl 38202;
_titleText ctrlSetText format["%2 (1%1)...","%",_title];
_progressBar progressSetPosition 0.01;
_cP = 0.01;

while {true} do {
	if(animationState player != "AinvPknlMstpSnonWnonDnon_medic_1") then {
		[player,"AinvPknlMstpSnonWnonDnon_medic_1"] remoteExecCall ["life_fnc_animSync",RCLIENT];
		player playMoveNow "AinvPknlMstpSnonWnonDnon_medic_1";
	};

	sleep .15;
	_cP = _cP + 0.01;
	_progressBar progressSetPosition _cP;
	_titleText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_title];
	if(_cP >= 1 OR !alive player) exitWith {};
	if(life_istazed) exitWith {};
	if(life_isknocked) exitWith {};
	if(life_interrupted) exitWith {};
	if((player getVariable ["restrained",false])) exitWith {};
	if(player distance _target > 4) exitWith {_badDistance = true;};
	if(_target getVariable ["Reviving",ObjNull] != player) exitWith {};
	if(player isEqualTo _target) exitWith {};
	if (_revivable) exitWith {};
	if(isNull _target) exitWith {};
};

5 cutText ["","PLAIN"];
player playActionNow "stop";

_target setVariable ["Reviving",NIL,TRUE];

if(!alive player OR life_istazed OR life_isknocked) exitWith {life_action_inUse = false;};
if(_target getVariable ["Revive",FALSE]) exitWith {hint localize "STR_Medic_RevivedRespawned"};
if((player getVariable ["restrained",false])) exitWith {life_action_inUse = false;};
if(!isNil "_badDistance") exitWith {titleText[localize "STR_Medic_TooFar","PLAIN"]; life_action_inUse = false;};
if(life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;};
if(player isEqualTo _target) exitWith {life_action_inUse = false;};
if (_revivable) exitWith {life_action_inUse = false;};
if(isNull _target) exitWith {life_action_inUse = false;};

life_action_inUse = false;

_break = floor (random 100);

if (_break < 84) exitWith {[_target] spawn life_fnc_cprkit;};

_target setVariable ["Revive",TRUE,TRUE];
[] remoteExecCall ["life_fnc_cprrevived",_target];

sleep .6;
player reveal _target;

Now you are going to need to set the stringtable for "STR_CPR_Progress"

Under 

        <Key ID="STR_Medic_Progress">
            <Original>Reviving %1</Original>
            <Czech>Oživení %1</Czech>
            <Spanish>Reviviendo %1</Spanish>
            <Russian></Russian>
            <German>Wird wiederbelebt %1</German>
            <French>Réanimations %1</French>
            <Italian>Rianimando %1</Italian>
            <Portuguese>Revivendo %1</Portuguese>
            <Polish>Reanimacja %1</Polish>
        </Key>

add

        <Key ID="STR_CPR_Progress">
          <Original>Performing CPR</Original>
        </Key>

Now we also need to add the function, so in Functions.hpp add

        class cprkit {};

inside 

    class Items {
        file = "core\items";

Now we need to make life_fnc_cprrevived actually do something

In core\medical create a new file called fn_cprrevived.sqf

#include "..\..\script_macros.hpp"

private ["_dir"];

[life_save_gear] spawn life_fnc_loadDeadGear;
life_corpse setVariable ["realname",nil,true];
[life_corpse] remoteExecCall ["life_fnc_corpse",RANY];

_dir = getDir life_corpse;

closeDialog 0;
life_deathCamera cameraEffect ["TERMINATE","BACK"];
camDestroy life_deathCamera;

player setDir _dir;
player setPosASL (visiblePositionASL life_corpse);
life_corpse setVariable ["Revive",nil,true];
life_corpse setVariable ["name",nil,true];
[life_corpse] remoteExecCall ["life_fnc_corpse",RANY];
deleteVehicle life_corpse;

life_action_inUse = false;
life_is_alive = true;

player setVariable ["Revive",nil,true];
player setVariable ["name",nil,true];
player setVariable ["Reviving",nil,true];
[] call life_fnc_playerSkins;
[] call life_fnc_hudUpdate;
[] call SOCK_fnc_updateRequest;

player setDamage 0.60;

Now we also need to make this a function, so in Functions.hpp add

class cprrevived {};

inside

    class Medical_System {
        file = "core\medical";

Next we are going to set the item to be usable which we will create in a moment

In fn_useItem.sqf add

    case (_item isEqualTo "cprKit"):
    {
        [cursorObject] spawn life_fnc_cprKit;
        closeDialog 0;
    };

Now im gonna make so when the CPR kit is dropped it will create the defibrillator item on the floor

In fn_dropItems.sqf add

        case "cprKit": {
            if (_value > 0) then {
                _pos = _unit modelToWorld[0,3,0];
                _pos = [(_pos select 0), (_pos select 1), 0];
                _obj = "Land_Defibrillator_F" createVehicle _pos;
                [_obj] remoteExecCall ["life_fnc_simDisable",RANY];
                _obj setPos _pos;
                _obj setVariable ["item",[_item,_value],true];
                missionNamespace setVariable [_itemName,0];
            };
        };

Now we make the cprkit an actual item..

in Config_vItems.sqf where all the other items are listed add

    class cprKit {
        variable = "cprKit";
        displayName = "STR_Item_CPRMediKit";
        weight = 5;
        buyPrice = 20000;
        sellPrice = 7500;
        illegal = false;
        edible = -1;
        icon = "icons\ico_defib.paa";
    };  

We will add STR_Item_CPRMediKit in a moment

If you want an icon make one otherwise use the one listed below

Under 

class VirtualShops {

is where you can choose what shops you can but these from for example lets say we want only gang shops to get this

it would look like such

    class gang {
        name = "STR_Shops_Gang";
        side = "civ";
        conditions = "";
        items[] = { "waterBottle", "rabbit", "apple", "redgull", "tbacon", "pickaxe", "fuelFull", "peach", "boltcutter", "blastingcharge", "cprKit" };
    };

Now we add another stringtable

Under STR_Item_Goat

add

        <Key ID="STR_Item_CPRMediKit">
             <Original>CPR MediKit</Original>
         </Key>

Now we want the cprkit to save in players and vehicles inventories

Config_Master.hpp

Were gonna add

,"cprKit"

in

saved_virtualItems[] = { 

and

save_vehicle_items[] = { 

Lastly we gotta make being revived able to be run remotely

In CfgRemoteExec.hpp add

        F(life_fnc_cprrevived,CLIENT)

Under

/* Client only functions */

_____________________________________________________________________________________________________________________________________________________________________

CPR Kit Icon Download

put in icons\

_____________________________________________________________________________________________________________________________________________________________________

If you have any questions at all just leave a comment and I will help you out!

Edited by TheBUTTERY_T
  • Like 5

Share this post


Link to post
Share on other sites
7 hours ago, Pegasus said:
 
You can make it work only when there is no medic online?

add at the top under 

if(isNull _target) exitWith {};

in fn_cprkit.sqf

if (independent countSide playableUnits > 0) exitWith { hint "You can only CPR when medics are not awake."; };

 

Share this post


Link to post
Share on other sites
3 minutes ago, TulparHAN said:

Would you take a video about the script?

If you want to know how it works, try it for yourself or make one yourself.. Not trying to be rude but people who don't know how to script shouldn't be making a server.

Share this post


Link to post
Share on other sites
55 minutes ago, TheBUTTERY_T said:

Nasıl çalıştığını bilmek isterseniz, kendiniz deneyin veya kendiniz yapın .. Kaba olmaya çalışmayın, ancak komut dosyası yapmayı bilmeyenler, bir sunucu oluşturmamalıdır.

I do not know your language exactly

I did not understand the purpose of the scenario and how it was used
This is the reason for the video request

I'm sorry if I was upset and rude.

Share this post


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

I do not know your language exactly

I did not understand the purpose of the scenario and how it was used
This is the reason for the video request

I'm sorry if I was upset and rude.

You make own script, or you test script.. English good enough? lol

By you asking for a video and not being able to tell what this does by just clearly looking at the script, than you are not fit to run a server. Sorry but the truth can be harsh.

Edited by TheBUTTERY_T

Share this post


Link to post
Share on other sites
On 20/2/2017 at 10:37 PM, TheBUTTERY_T said:

By you asking for a video and not being able to tell what this does by just clearly looking at the script, than you are not fit to run a server.

No one was born knowing scripting and the best way to learn is by starting (and running) an educational server. I find your phrase void in a circular way if you see what I mean. Therefore I assume you did not mean exactly this.

Anyway, back to the script, which is the interesting part of this thread, have you thought of making it accessible from the ActionKeyHandler instead? Are you afraid of potential conflicts with other actions or it is just a matter of preference? I understand adding too many actions in the ActionKeyHandler requires a lot of attention but... What do you think?

Share this post


Link to post
Share on other sites
12 minutes ago, Nikos said:

No one was born knowing scripting and the best way to learn is by starting (and running) an educational server. I find your phrase void in a circular way if you see what I mean. Therefore I assume you did not mean exactly this.

Anyway, back to the script, which is the interesting part of this thread, have you thought of making it accessible from the ActionKeyHandler instead? Are you afraid of potential conflicts with other actions or it is just a matter of preference? I understand adding too many actions in the ActionKeyHandler requires a lot of attention but... What do you think?

I think it is better to keep the regular revive way (action key) from the CPR Kit way (y menu) you can do so if you feel but its a matter of preference and I prefer it from the y menu its really not that much of a hassel as it automatically restarts the cycle after failing to CPR.

Edited by TheBUTTERY_T

Share this post


Link to post
Share on other sites

how do you increase the chances of revive? to like 25%, ive been using this and i have noticed it sometimes takes like a bit of excessivly long time to revive (9-10+ tries)

Share this post


Link to post
Share on other sites

Awesome Script, thanks man,.. can you give me a hint how change the use to limitied,... i want that the people buy more of this and so you cant use it unlimitied. Sorry for my bad english... best regards

Share this post


Link to post
Share on other sites
On 5/3/2017 at 3:21 PM, Alpha Hawk said:

how do you increase the chances of revive? to like 25%, ive been using this and i have noticed it sometimes takes like a bit of excessivly long time to revive (9-10+ tries)

_break = floor (random 100);

if (_break < 85) exitWith {[_target] spawn life_fnc_cprkit;};

For 25% change _break < 84 to _break < 74

Edited by TheBUTTERY_T

Share this post


Link to post
Share on other sites
On 5/4/2017 at 9:32 AM, skiT said:

Awesome Script, thanks man,.. can you give me a hint how change the use to limitied,... i want that the people buy more of this and so you cant use it unlimitied. Sorry for my bad english... best regards

at the top somewhere add 

if (!([false,"cprkit",1] call life_fnc_handleInv)) exitWith {};

 

Share this post


Link to post
Share on other sites

I probarly fucked up somewhere but im gonna ask anyways because i cant find out where.

My CPR kit works just fine but say if i die and it drops to the ground noone can pick it up.. Do you know how to fix this?

Share this post


Link to post
Share on other sites

This script look so good !

But I'm on 5.0 and seems to not work... Somebody can help ?

When I'm close to a dead body, I open "y" menu and use the CPR kit but nothing happens....

I follow this tuto a few times and can't find the solution... Any advice would be great !! :)

 

Edited by chevrier

Share this post


Link to post
Share on other sites

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

×