Jump to content
Rez

[Tutorial] Gang Capturable Areas

Recommended Posts

A tutorial by: @Fuel

 

MISSION SIDE

Step 1

Create a new file in core>>gangs called fn_areaCapture.sqf

and paste this

#include "..\..\script_macros.hpp"
/*
    File: fn_areaCapture.sqf
    Author: Fuel RebornRoleplay.com

    Description:
    checks the area for gangs or police before allowing you to capture an area
*/
private["_gangNum","_gName","_group","_area","_nil","_pos","_xname","_text","_action","_cpRate","_cP","_nearUnits","_areaContested","_progressBar","_title","_titleText","_ui"];

_area = getpos player nearestObject "Flag_Red_F"; //finds the flag
_group = _area getVariable ["gangOwner",grpNull]; //gets the owner of the flag
_xname = ""; //setup for popo name
_nearUnits = _area nearEntities ["Man",500]; //searches area for players
 _areaContested = false; //sets the area to not contested
if ((player distance _area) > 10) exitWith { hint "You must be closer to the flag to capture this area!"; }; //too far away

/*
#########################################
#       The Police Capture System       #
#########################################
*/

if (playerside isEqualTo west) exitWith {

//inform the server the police are trying to capture it.
[[0,1],"STR_GNOTF_CaptureAreaAttemptPopo",true,[name player]] remoteExecCall ["life_fnc_broadcast",RCLIENT];

//set the cp rate
if (!isNull _group) then {
    _cpRate = 0.0045;
} else {
    _cpRate = 0.0075;
};

//Police officer checks
{
        
    //check for other members of same side
    if ((isPlayer _x) && (_x != player) && (side _x == west)) then {
        _areaContested = false;
    };

    //checks for rebels
    if ((isPlayer _x) && (_x != player) && (side _x == civilian)) then {
        _areaContested = true;
        _xname = "Rebels";
    };

    //closes the capture
    if (_areaContested && _xname isEqualTo "Rebels") then {
        hint "Rebels are nearby!\nGet rid of them first!";
    };

} forEach _nearUnits;

//exit if contested
if (_areaContested) exitWith {};

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

if (!(_areaContested)) then {
    for "_i" from 0 to 1 step 0 do {
        sleep 3; //police capture time * 100
        _cP = _cP + _cpRate;
        _progressBar progressSetPosition _cP;
        _titleText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_title];

        //sets the area to incapture
        _area setVariable ["inCapture",true,true];

        //interuption checks
        if (_cP >= 1 || !alive player) exitWith {_area setVariable ["inCapture",false,true];};
        if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
        if (_areaContested) exitWith {hint "Area Contested";}; //Future testing
        if (life_istazed) exitWith {_area setVariable ["inCapture",false,true];}; //Tazed
        if (life_isknocked) exitWith {_area setVariable ["inCapture",false,true];}; //Knocked
        if (life_interrupted) exitWith {_area setVariable ["inCapture",false,true];}; //interupted
    };
          if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
};

//Kill the UI display and check for various states
5 cutText ["","PLAIN"];
        if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
if (!alive player || life_istazed || life_isknocked) exitWith {life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //knocked out or tazed revert state
if (player getVariable["restrained",false]) exitWith {life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //restrained revert state
if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_GNOTF_CaptureCancel","PLAIN"]; life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //interupted revert state
life_action_inUse = false;
titleText[localize "STR_GNOTF_CapturedArea","PLAIN"];

//marker system
_gangNum = _area getVariable ["gangNum", ""];

_gName = group player getVariable "gang_name";
_pText = format["Neutralized Area"];

if (_gangNum == "Gang_Area_1") then {
    "gang_cap_1" setMarkerText _pText;
};

if (_gangNum == "Gang_Area_2") then {
    "gang_cap_2" setMarkerText _pText;
};

if (_gangNum == "Gang_Area_3") then {
    "gang_cap_3" setMarkerText _pText;
};

_area setVariable ["inCapture",false,true];
_area setVariable ["gangOwner",group player,true];

};

/*
#############################################
#       End Of Police Capture System        #
#############################################
*/

/*
#########################################
#       The Rebel Capture System        #
#########################################
*/

_area = getpos player nearestObject "Flag_Red_F"; //finds the flag
_group = _area getVariable ["gangOwner",grpNull]; //gets the ownerr of the flag
_xname = ""; //setup for popo name
_nearUnits = _area nearEntities ["Man",500]; //searches area for players
if (isNil {group player getVariable "gang_name"}) exitWith { hint "You must be in a gang to capture a gang area!"; }; //not in a gang
if (_group isEqualTo group player) exitWith { hint "Your gang already has control over this area!"; }; //already own it
if ((_area getVariable ["inCapture",FALSE])) exitWith {hint "Only one person shall capture at once!"; }; //stops 2 people capturing at the same time

[[0,1],"STR_GNOTF_CaptureAreaAttempt",true,[name player,(group player) getVariable "gang_name"]] remoteExecCall ["life_fnc_broadcast",RCLIENT]; //tells the server someone is trying to capture the outpost

if (!isNull _group) then {

_gangName = _group getVariable ["gang_name",""]; //gets the gang name

    //check if they want to capture someones elses area
    _action = [
        format[localize "STR_GNOTF_AlreadygangControlled",_gangName],
        localize "STR_Gang_captuerr",
        localize "STR_Global_Yes",
        localize "STR_Global_No"
    ] call BIS_fnc_guiMessage;

    _cpRate = 0.0045;
} else {
    _cpRate = 0.0075;
};

//check if area is contested
{

    //check for other members of same gang
    if ((isPlayer _x) && (_x != player) && (side _x == civilian) && (group _x == group player)) then {
        _areaContested = false;
    };

    //check for other rebels
    if ((isPlayer _x) && (_x != player) && (side _x == civilian) && (!(group _x == group player))) then {
        _areaContested = true;
    };

    //checks for cops
    if ((isPlayer _x) && (_x != player) && (side _x == west)) then {
        _areaContested = true;
        _xname = "Police Force";
    };

    //closes the capture
    if (_areaContested) exitWith {
        if (_xname isEqualTo "Police Force") then {
            hint "The Police Force are nearby!\nGet rid of them first!";
        } else {
            hint "Other rebels are nearby!\nGet rid of them first!";
        };
    };

} forEach _nearUnits;
   
//exit if contested 
if (_areaContested) exitWith {};

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

if (!(_areaContested)) then {
    for "_i" from 0 to 1 step 0 do {
        sleep  3; //rebel capture time * 100
        _cP = _cP + _cpRate;
        _progressBar progressSetPosition _cP;
        _titleText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_title];

        //sets the area to incapture
        _area setVariable ["inCapture",true,true];

        //interuption checks
        if (_cP >= 1 || !alive player) exitWith {_area setVariable ["inCapture",false,true];};
        if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
        if (_areaContested) exitWith {hint "Area Contested";};
        if (life_istazed) exitWith {_area setVariable ["inCapture",false,true];}; //Tazed
        if (life_isknocked) exitWith {_area setVariable ["inCapture",false,true];}; //Knocked
        if (life_interrupted) exitWith {_area setVariable ["inCapture",false,true];}; //interupted
    };
    if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
};

//Kill the UI display and check for various states
5 cutText ["","PLAIN"];
if (player distance _area > 100) exitWith {_area setVariable ["inCapture",false,true];}; //how far they can go from the hideout while capturing
if (!alive player || life_istazed || life_isknocked) exitWith {life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //knocked out or tazed revert state
if (player getVariable["restrained",false]) exitWith {life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //restrained revert state
if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_GNOTF_CaptureCancel","PLAIN"]; life_action_inUse = false;_area setVariable ["inCapture",false,true];}; //interupted revert state
life_action_inUse = false;

titleText[localize "STR_GNOTF_CapturedArea","PLAIN"];

//marker system
_gangNum = _area getVariable ["gangNum", ""];

_gName = group player getVariable "gang_name";
_Text = format["Area Controlled By %1",_gName];

if (_gangNum == "Gang_Area_1") then {
    "gang_cap_1" setMarkerText _text;
};

if (_gangNum == "Gang_Area_2") then {
    "gang_cap_2" setMarkerText _text;
};

if (_gangNum == "Gang_Area_3") then {
    "gang_cap_3" setMarkerText _text;
};

//Tell the world
[[0,1],"STR_GNOTF_CaptureAreaSuccess",true,[name player,(group player) getVariable "gang_name"]] remoteExecCall ["life_fnc_broadcast",RCLIENT];

_area setVariable ["inCapture",false,true];
_area setVariable ["gangOwner",group player,true];

/*
#############################################
#       End Of The Rebel Capture System     #
#############################################
*/

Step 2

then open Functions.hpp

and paste the below inside of core/gangs

class areaCapture {};

Step 3

This is the funcky part, you need to go into the map editor and setup 3 map locations

Location 1

place a "Flag_Red_F"

note down the position information of the flag (it will be needed later)

the init of the flag should be:

this allowDamage false; this enableSimulation false; this setVariable ["gangNum","Gang_Area_1", true];

place a marker on the flags position called:

"gang_cap_1"

The marker test should be:

"Uncontrolled Area"

Location 2

place a "Flag_Red_F"

note down the position information of the flag (it will be needed later)

the init of the flag should be:

this allowDamage false; this enableSimulation false; this setVariable ["gangNum","Gang_Area_2", true];

place a marker on the flags position called:

"gang_cap_2"

The marker test should be:

"Uncontrolled Area"

Location 3

place a "Flag_Red_F"

note down the position information of the flag (it will be needed later)

the init of the flag should be:

this allowDamage false; this enableSimulation false; this setVariable ["gangNum","Gang_Area_3", true];

place a marker on the flags position called:

"gang_cap_3"

The marker test should be:

"Uncontrolled Area"

I also suggest placing a 500m circle around the area so people know its a redzone but thats personal preference.

Step 4

Open up your stringtable.xml and add:

        <Key ID="STR_GNOTF_CaptureAreaAttemptPopo">
            <Original>%1 and the police are trying to neutralize an area!</Original>
        </Key>

        <Key ID="STR_GNOTF_CapturingArea">
            <Original>Claiming Area</Original>
        </Key>

        <Key ID="STR_GNOTF_CapturedArea">
            <Original>Area has been captured.</Original>
        </Key>

        <Key ID="STR_Gang_captuerr">
            <Original>Capture Area</Original>
        </Key>

        <Key ID="STR_GNOTF_CaptureAreaSuccess">
            <Original>%1 and his gang: %2 - have claimed an area!</Original>
        </Key>

Step 5

open up fn_setupActuons.sqf and paste the below inside west and civilian

//Gang
life_actions = life_actions + [player addAction["<t color='#FF0000'>Capture Gang Location</t>",life_fnc_areaCapture,"",0,false,false,"",' ((typeOf cursorTarget) == "Flag_Red_F") ']];

SERVER SIDE

Step 6

create a new file in life_server>>functions>>gang

called fn_gangCash.sqf

and paste in it the below:

#include "\life_server\script_macros.hpp"
/*
    File: fn_gangCash.sqf
    Author: Fuel RebornRoleplay.com

    Description:
    checks the gang areas, then rewards the gang if they own them
*/

 /*
	#########################
 	#	  north outpost		#
 	#########################
 */

//gets the flag locations
_area = [4870.743,21934.35,0] nearestObject "Flag_Red_F";

//gets the gang names of the flag owners
_owner = _area getVariable ["gangOwner",grpNull];

//get the gang funds
_gFund = _owner getVariable ["gang_bank",0];

//set the new gang funds
_owner setVariable ["gang_bank",round(_gFund+((count playableUnits)*2000)),true];

//push gang funds to DB
[1,_owner] call TON_fnc_updateGang;
 
 /*
	#########################
 	#	south pen outpost	#
 	#########################
 */

//gets the flag locations
_area2 = [11207.171,8699.596,0] nearestObject "Flag_Red_F";

//gets the gang names of the flag owners
_owner = _area2 getVariable ["gangOwner",grpNull];

//get the gang funds
_gFund = _owner getVariable ["gang_bank",0];

//set the new gang funds
_owner setVariable ["gang_bank",round(_gFund+((count playableUnits)*2000)),true];

//push gang funds to DB
[1,_owner] call TON_fnc_updateGang;

 /*
	#########################
 	#	   east outpost		#
 	#########################
 */

//gets the flag locations
_area3 = [20079.65,6744.436,0] nearestObject "Flag_Red_F";

//gets the gang names of the flag owners
_owner = _area3 getVariable ["gangOwner",grpNull];

//get the gang funds
_gFund = _owner getVariable ["gang_bank",0];

//set the new gang funds
_owner setVariable ["gang_bank",round(_gFund+((count playableUnits)*2000)),true];

//push gang funds to DB
[1,_owner] call TON_fnc_updateGang;

//time between scripts
Sleep 900;

[] spawn TON_fnc_gangCash;

Step 7

Now the locations of the flags saved earlier needs to be put in the above script in the obvious places.

Step 8

Open Config.cpp and add the below inside of "\life_server\Functions\Gangs"

class gangCash {};

Step 9

now open the server init.sqf and underneath [] spawn TON_fnc_initHouses; paste the below:

[] spawn TON_fnc_gangCash;

Annnnnd you're done, let me know if anything is missing or wrong, thanks to Fuel for letting me post this FULL credit goes to him, I take ZERO credit for anything in the tutorial.

And if you think that I posted this without his permission, then here you go :)

https://gyazo.com/5b31e2e3a90da8054c03910311418a59

Edited by Rez
  • Like 4

Share this post


Link to post
Share on other sites

Everything works so far except getting money from the actual areas. I created a gang and captured it and waited 40 minutes and nothing has changed so far. Am i missing something? How is the cash supposed to work like? 

Share this post


Link to post
Share on other sites
56 minutes ago, Rasmus said:

Everything works so far except getting money from the actual areas. I created a gang and captured it and waited 40 minutes and nothing has changed so far. Am i missing something? How is the cash supposed to work like? 

When you capture the area it should put 2k in the gang balance every 15 minutes

Edited by [IL] KingCrazyHunter
  • Like 1

Share this post


Link to post
Share on other sites
11 hours ago, Rasmus said:

Everything works so far except getting money from the actual areas. I created a gang and captured it and waited 40 minutes and nothing has changed so far. Am i missing something? How is the cash supposed to work like? 

Yep, what @[IL] KingCrazyHunter Said, you can change this as needed.

Share this post


Link to post
Share on other sites
Just now, [IL] KingCrazyHunter said:

I would double check your markers and your gangcash.sqf

Just did. Everything seems to be good in there. I just capped one 5 minutes ago so i'll probably come back here in 10 minutes and see what happens :)

Share this post


Link to post
Share on other sites
9 minutes ago, [IL] KingCrazyHunter said:

alright, let me know if it works or not

Been like 20 minutes now. I started up the server, created a gang, captured the gang and waited there. No fund change at all. Nothing in the .rpt either as far as i can see

Share this post


Link to post
Share on other sites

Show me the init that you put in the flag, the flag type, and then link the gangcash.sqf you are using, you may have an error somewhere.

Share this post


Link to post
Share on other sites
54 minutes ago, Fuel said:

Show me the init that you put in the flag, the flag type, and then link the gangcash.sqf you are using, you may have an error somewhere.

Init:

init="this allowDamage false; this enableSimulation false; this setVariable [""gangNum"",""Gang_Area_3"", true];";

Type:

type="Flag_Red_F";

And here is my gangCash.sqf file:

http://pastebin.com/0CgkF9Rs

Thanks! :)

EDIT: Obviously on the 2 other flags i have Gang_Area_2 and 1 in there instead of 3 :P

EDIT2: Almost an hour now and still no change at all.

Edited by Rasmus

Share this post


Link to post
Share on other sites
2 hours ago, Rasmus said:

Init:

init="this allowDamage false; this enableSimulation false; this setVariable [""gangNum"",""Gang_Area_3"", true];";

Type:

type="Flag_Red_F";

And here is my gangCash.sqf file:

http://pastebin.com/0CgkF9Rs

Thanks! :)

EDIT: Obviously on the 2 other flags i have Gang_Area_2 and 1 in there instead of 3 :P

EDIT2: Almost an hour now and still no change at all.

This may sound idiotic but you are checking you gang balance not your cash and/or bank right?
In addition have you checked the pos of your flags with the code? In the gang cash file double check your cords... Just go to the editor and look at the x,y,z cords...

Share this post


Link to post
Share on other sites

I cant see any issues in your code mate, I know it works as I have had it running on my server for nearly 2 months, I suggest starting from scratch and going over it again just to be sure. set the sleep in gang cash to like 1 second so you dont have to wait either. and make sur you have gang cash in the server init

Share this post


Link to post
Share on other sites
18 minutes ago, Fuel said:

I cant see any issues in your code mate, I know it works as I have had it running on my server for nearly 2 months, I suggest starting from scratch and going over it again just to be sure. set the sleep in gang cash to like 1 second so you dont have to wait either. and make sur you have gang cash in the server init

Yup will do. I think the place i am messing up is the coordinates. Is the coordinates i wanna put in the gangCash.sqf file differently formatted than in the mission.sqm?

This is the mission.sqm flag position coordinates.

position[]={21492.381,15.649413,10828.369};

And this is my in editor coordinates set up. Which one do i wanna put in the gangCash?

Yiz5cc9.png 

 

Seems like that is the error. I gotta use the editor format and not the mission.sqm position format :) Thanks!

Edited by Rasmus

Share this post


Link to post
Share on other sites

I'm pretty sure if you read my last posted comment you can figure out that it works.

it works yes. Just make sure to not use the position from your mission.sqm :)

Share this post


Link to post
Share on other sites

Just a real quick question I have my markets labeled as

 

gang_cap_3 etc. and thats how they show on the map?

 

Does this script allow me to make it so people know which area is taken over and if it can say anything different on the markers?

 

Sorry for noob question. 

Share this post


Link to post
Share on other sites
21 hours ago, Johnny Honeybee said:

Just a real quick question I have my markets labeled as

 

gang_cap_3 etc. and thats how they show on the map?

 

Does this script allow me to make it so people know which area is taken over and if it can say anything different on the markers?

 

Sorry for noob question. 

If a gang captures an area it changes the name of the area to their gang name by default

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...