Jump to content
suffer4real

[BASICS] MrKraken's Gas Station Robbery Script

Recommended Posts

Hello, 

Here is a tutorial to add MrKraken's gas station robbery script.

Difficulty: Copy & paste

Author: MrKraken 

Source : Altisliferpg.com (cache recovery)

_____________________________________________________________________________________________________________________________________

1. Navigate to the core folder and then the functions folder, create a file called fn_robstore.sqf and paste the following:

/*
file: fn_robShops.sqf
Author: MrKraken
Description:
Executes the rob shob action!
*/
private["_robber","_shop","_kassa","_ui","_progress","_pgText","_cP","_rip","_pos"];
_shop = [_this,0,ObjNull,[ObjNull]] call BIS_fnc_param; //The object that has the action attached to it is _this. ,0, is the index of object, ObjNull is the default should there be nothing in the parameter or it's broken
_robber = [_this,1,ObjNull,[ObjNull]] call BIS_fnc_param; //Can you guess? Alright, it's the player, or the "caller". The object is 0, the person activating the object is 1
//_kassa = 1000; //The amount the shop has to rob, you could make this a parameter of the call (https://community.bistudio.com/wiki/addAction). Give it a try and post below ;)
_action = [_this,2] call BIS_fnc_param;//Action name

if(side _robber != civilian) exitWith { hint "You can not rob this Gas Station!" };
if(_robber distance _shop > 5) exitWith { hint "You need to be within 5m of the cashier to rob him!" };

if !(_kassa) then { _kassa = 1000; };
if (_rip) exitWith { hint "Robbery already in progress!" };
if (vehicle player != _robber) exitWith { hint "Get out of your vehicle!" };

if !(alive _robber) exitWith {};
if (currentWeapon _robber == "") exitWith { hint "HaHa, you do not threaten me! Get out of here you hobo!" };
if (_kassa == 0) exitWith { hint "There is no cash in the register!" };

_rip = true;
_kassa = 120000 + round(random 60000);
_shop removeAction _action;
_shop switchMove "AmovPercMstpSsurWnonDnon";
_chance = random(100);
if(_chance >= 50) then {[1,format["ALARM! - Gas Station: %1 is being robbed!", _shop]] remoteExec ["life_fnc_broadcast",west]; };

_cops = (west countSide playableUnits);
if(_cops < 1) exitWith{[_vault,-1] remoteExec ["disableSerialization;",2]; hint "There isnt enough Police to rob Gas Station!";};
disableSerialization;
5 cutRsc ["life_progress","PLAIN"];
_ui = uiNameSpace getVariable "life_progress";
_progress = _ui displayCtrl 38201;
_pgText = _ui displayCtrl 38202;
_pgText ctrlSetText format["Robbery in Progress, stay close (10m) (1%1)...","%"];
_progress progressSetPosition 0.01;
_cP = 0.0001;

if(_rip) then
{
while{true} do
{
sleep 3;
_cP = _cP + 0.01;
_progress progressSetPosition _cP;
_pgText ctrlSetText format["Robbery in Progress, stay close (10m) (%1%2)...",round(_cP * 100),"%"];
_Pos = position player; // by ehno: get player pos
				                _marker = createMarker ["Marker200", _Pos]; //by ehno: Place a Maker on the map
				                "Marker200" setMarkerColor "ColorRed";
				                "Marker200" setMarkerText "!ATTENTION! robbery !ATTENTION!";
				                "Marker200" setMarkerType "mil_warning";
if(_cP >= 1) exitWith {};
if(_robber distance _shop > 10.5) exitWith { };
if!(alive _robber) exitWith {};
};
if!(alive _robber) exitWith { _rip = false; };
if(_robber distance _shop > 10.5) exitWith { deleteMarker "Marker200"; _shop switchMove ""; hint "You need to stay within 10m to Rob registry! - Now the registry is locked."; 5 cutText ["","PLAIN"]; _rip = false; };
5 cutText ["","PLAIN"];

titleText[format["You have stolen $%1, now get away before the cops arrive!",[_kassa] call life_fnc_numberText],"PLAIN"];
deleteMarker "Marker200"; // by ehno delete maker
life_cash = life_cash + _kassa;

_rip = false;
life_use_atm = false;
sleep (30 + random(180));
life_use_atm = true;
if!(alive _robber) exitWith {};
[getPlayerUID _robber,name _robber,"211"] remoteExec ["life_fnc_wantedAdd",2];
};
sleep 300;
_action = _shop addAction["Rob the Gas Station",life_fnc_robstore];
_shop switchMove "";

2. Open your mission.sqm in the editor and go to a gas station you wish to rob and add then following to the init line of the NPC:

this addAction["Rob the Gas Station",life_fnc_robstore];

3. Go back to your root directory and open functions.hpp, once opened, find class Functions and at the end of the block add:

class robstore {};

4. ReCompile your mission and done :)

Edited by suffer4real
on request
  • Like 3

Share this post


Link to post
Share on other sites

how can i add a alarm to this so when you successfully start robbing the store the alarm goes of  for a few minutes? also multiple people can rob the same store at the same time, any way to fix this?

Edited by GpGamingX
add stuff

Share this post


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

how can i add a alarm to this so when you successfully start robbing the store the alarm goes of  for a few minutes? also multiple people can rob the same store at the same time, any way to fix this?

Just call a sound when the NPC puts his hand on his head. You can even call it to play from the NPC.

Share this post


Link to post
Share on other sites
8 hours ago, GpGamingX said:

i am still fairly new with coding, any examples or tut?

once you installed it it and try to rob it you get a progress bar once it's finished you get the money. 

Share this post


Link to post
Share on other sites

Corrections Here,

1. Navigate to the core folder and then the functions folder, create a file called fn_robstore.sqf and paste the following:

                              core                                 actions                                                fn_robShops.sqf

2. Open your mission.sqm in the editor and go to a gas station you wish to rob and add then following to the init line of the NPC:

this addAction["Rob the Gas Station",life_fnc_robstore];

     this addAction{"Rob the Gas Station",life_fnc_robShops];

3. Go back to your root directory and open functions.hpp, once opened, find class Functions and at the end of the block add:

class robstore {};

     class robShops {};

Share this post


Link to post
Share on other sites

multiple people can rob the same store at the same time, how can you fix this? also how can i add an "alarm". i tried using say3D but its not global so than i tried using say3D cba but i cant get it working. Thanks for any help:) 

Share this post


Link to post
Share on other sites

Gettiing this error and cantt start my server:

22:41:30 File mpmissions\__cur_mp.Altis\mission.sqm, line 36801: '/Mission/Entities/Item841/Entities/Item113/Attributes.init': Missing ';' at the end of line
22:41:30 Error context he Gas Station",life_fnc_robShops];";
ErrorMessage: File mpmissions\__cur_mp.Altis\mission.sqm, line 36801: '/Mission/Entities/Item841/Entities/Item113/Attributes.Rob': 't' encountered instead of '='

Line 36801 to 36804:

class Attributes
                    {
                        init="this enableSimulation false; this allowDamage false; this addAction[localize""STR_MAR_Station_Shop"",life_fnc_weaponShopMenu,""f_station_store""];this addAction[localize""STR_Shop_Station_Coffee"",life_fnc_virt_menu,""f_station_coffee""];this addAction["Rob the Gas Station",life_fnc_robShops];";
                        name="Station_shop_1";
                    };

Share this post


Link to post
Share on other sites
On 9/15/2016 at 6:53 AM, GpGamingX said:

how can i add a alarm to this so when you successfully start robbing the store the alarm goes of  for a few minutes? also multiple people can rob the same store at the same time, any way to fix this?

Open fn_robStore.sqf

Add this line of code just below this line of code: if(_chance >= 10) then {[1,format["ALARM! - Gas Station: %1 is being robbed!", _shop]] remoteExec ["life_fnc_broadcast",west]; };
so in term it would look like this:
 

if(_chance >= 10) then {[1,format["ALARM! - Gas Station: %1 is being robbed!", _shop]] remoteExec ["life_fnc_broadcast",west]; };
[[_shop, "robberyalarm",250],"life_fnc_playSound",true,false] spawn life_fnc_MP;

Navigate to description.ext

Add this piece of code under Class CfgSounds:
 

class robberyalarm
    {
        name = "robberyalarm";
        sound[] = {"\sounds\robberyalarm.ogg",2.0, 1};
        titles[] = {};
    };

Of course don't forget to add the sound called robberyalarm.ogg to your sounds file.

Any other questions feel free to ask

  • Like 2

Share this post


Link to post
Share on other sites
10 hours ago, lRoberth said:

Gettiing this error and cantt start my server:

22:41:30 File mpmissions\__cur_mp.Altis\mission.sqm, line 36801: '/Mission/Entities/Item841/Entities/Item113/Attributes.init': Missing ';' at the end of line
22:41:30 Error context he Gas Station",life_fnc_robShops];";
ErrorMessage: File mpmissions\__cur_mp.Altis\mission.sqm, line 36801: '/Mission/Entities/Item841/Entities/Item113/Attributes.Rob': 't' encountered instead of '='

Line 36801 to 36804:

class Attributes
                    {
                        init="this enableSimulation false; this allowDamage false; this addAction[localize""STR_MAR_Station_Shop"",life_fnc_weaponShopMenu,""f_station_store""];this addAction[localize""STR_Shop_Station_Coffee"",life_fnc_virt_menu,""f_station_coffee""];this addAction["Rob the Gas Station",life_fnc_robShops];";
                        name="Station_shop_1";
                    };

          {
                        init="this enableSimulation false; this allowDamage false; this addAction[localize""STR_MAR_Station_Shop"",life_fnc_weaponShopMenu,""f_station_store""];this addAction[localize""STR_Shop_Station_Coffee"",life_fnc_virt_menu,""f_station_coffee""];this addAction[""Rob the Gas Station"",life_fnc_robShops];";
                        name="Station_shop_1";
                    };

 

  • Like 1

Share this post


Link to post
Share on other sites

hum strange I get nothing when trying to rob the shop the scroll option comes up but nothing after that.

Never mind I found the problem

Edited by Iceman

Share this post


Link to post
Share on other sites

So i got the action to load and everything to load just fine but when a player goes to rob the said station / store it comes up with this error, c056583656.png  i'm not to sure on how to really fix this at the current moment but even through vscode i could not find an error, then again im not the smartest with code... any idea?? and im on altis frramework 4.5 can proved RPT files if needed.

Share this post


Link to post
Share on other sites
On 17-9-2016 at 11:12 PM, Mastermind said:

Corrections Here,

1. Navigate to the core folder and then the functions folder, create a file called fn_robstore.sqf and paste the following:

                              core                                 actions                                                fn_robShops.sqf

2. Open your mission.sqm in the editor and go to a gas station you wish to rob and add then following to the init line of the NPC:

this addAction["Rob the Gas Station",life_fnc_robstore];

     this addAction{"Rob the Gas Station",life_fnc_robShops];

3. Go back to your root directory and open functions.hpp, once opened, find class Functions and at the end of the block add:

class robstore {};

     class robShops {};

You made a small mistake in step 2. Your line: this addAction{"Rob the Gas Station",life_fnc_robShops];

                                                                                         { has to be [

Breaks the init of the NPC. Or just does not allow you to exit the NPC.

You are also stating in 1 that it has to be in Actions but it has to be in Functions.

 

Whenever you attempt to fix coding. Please fix it correctly.

 

Jeroen

Edited by Hammo00 [RipperRP]
Had more complaints about his edit skills...
  • Like 2

Share this post


Link to post
Share on other sites

What I post is how it worked for me. When other people say it doesn't work I, offer my solution.  Like most all programmers sometimes, I may leave a lil thing miss-spelled or such on purpose to get people to use their brains and try to problem solve it them selves. It's all about teaching people not just doing it for them. So those errors are there for a reason. Different versions may require it to be installed differently also. On another note people do make mistakes. But my mistakes usually are not and server a purpose.

                                                                                                 P.S. Best just to give your corrections and move on. No need to be rude.  Hell why don't you just write it yourself instead of complaining bout it. Extra comments like that start forum arguments and I'm just going to be the bigger man here and state the obvious and move on like you shoulda done.

Share this post


Link to post
Share on other sites
On 10/21/2016 at 9:09 AM, Mastermind said:

What I post is how it worked for me. When other people say it doesn't work I, offer my solution.  Like most all programmers sometimes, I may leave a lil thing miss-spelled or such on purpose to get people to use their brains and try to problem solve it them selves. It's all about teaching people not just doing it for them. So those errors are there for a reason. Different versions may require it to be installed differently also. On another note people do make mistakes. But my mistakes usually are not and server a purpose.

                                                                                                 P.S. Best just to give your corrections and move on. No need to be rude.  Hell why don't you just write it yourself instead of complaining bout it. Extra comments like that start forum arguments and I'm just going to be the bigger man here and state the obvious and move on like you shoulda done.

Love it.

Share this post


Link to post
Share on other sites
On 21/09/2016 at 1:42 AM, NatanBrody said:

Open fn_robStore.sqf

Add this line of code just below this line of code: if(_chance >= 10) then {[1,format["ALARM! - Gas Station: %1 is being robbed!", _shop]] remoteExec ["life_fnc_broadcast",west]; };
so in term it would look like this:
 

if(_chance >= 10) then {[1,format["ALARM! - Gas Station: %1 is being robbed!", _shop]] remoteExec ["life_fnc_broadcast",west]; };
[[_shop, "robberyalarm",250],"life_fnc_playSound",true,false] spawn life_fnc_MP;

Navigate to description.ext

Add this piece of code under Class CfgSounds:
 

class robberyalarm
    {
        name = "robberyalarm";
        sound[] = {"\sounds\robberyalarm.ogg",2.0, 1};
        titles[] = {};
    };

Of course don't forget to add the sound called robberyalarm.ogg to your sounds file.

Any other questions feel free to ask

I got the script and everything working fine however I was wondering how I could send a broadcast out to the other side (civ and medic) alerting everyone that there is a robery taking place.

  • Like 1

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...