Jump to content

Craft bike/motor as fresh-spawn


Infinity

Recommended Posts

  • 2 weeks later...

This is a great script. But does anyone know how to configure it so that you need two wheels and a scrap metal to construct it? And that you lose those parts instead of the toolbox?

 

I guess add/remove-Magazine "PartWheel", "PartWheel", "PartGeneric" instead of player addWeapon "ItemToolbox";. But it needs a check for those parts in the inventory doesn't it? And a error message if you don't have them?

 

*looks at cen and JoSchaap*

Link to comment
Share on other sites

No that's not quite what I'm thinking. What I'm thinking is you need a toolbox to enable the option to craft a bike, but you can't do it untill you have two wheels and scrap metal in your inventory. If you try to do it, there shold be a message like "You need 2 more car wheels to craft a bike.".

 

When you have all the item, you right click the toolbox and press "Craft bike". The wheels and the scrap metal dissapear from your inventory, and a bike appears. Nothing happens to the toolbox. When you deconstruct the bike, you get two wheels and a scrap metal in your inventory.

Link to comment
Share on other sites

maybe that will help if you know a little about ArmA scripting, I've added a few global helper functions to Epoch 1.0.4,

so client side scripts can make use of those, here an overview of the added functions:

 

 

player_hasTools 

Checks whether the player has the required tools equipped or not
and displays a message if a tool is missing from the tool belt.
 
Parameter(s):
_this: <array> list of tool names the player is required to have
 
Returns:
Boolean (true if the player has all required tools)
    
How to use:
_hasTools = ["ItemToolbox", "ItemCrowbar"] call player_hasTools;
 
 

player_checkItems 

Checks whether the player has the required items (magazines) or not

and displays a message if an item is missing.
 
Parameter(s):
_this: <array> list of item names the player is required to have (can also be an sub-array with item name and quantity)
 
Returns:
Boolean (true if the player has all required items)
    
How to use:
_hasItems = [["PartGeneric",4], "PartEngine", ["ItemGenerator"]] call player_checkItems;
 
 

player_removeItems 

Removes the items (magazines) from the player's inventory

and performs a double check for the required items.
 
Parameter(s):
_this: <array> list of item names to be removed (can also be an sub-array with item name and quantity)
 
Returns:
Boolean (true if all items have been removed from the player's inventory)
    
How to use:
_removed = [["PartGeneric",4], "PartEngine", ["ItemGenerator"]] call player_removeItems;
 
 
player_checkAndRemoveItems
combination of check and remove items
 
 
so in your case you could use the convenience function player_checkAndRemoveItems to remove the wheels and other stuff,
if the payer doesn't have the items a message will be shown by default (same way as if you would build something and don't have the items, or sell items at the trader)
if ([["PartWheel",2], "PartGeneric"] call player_checkAndRemoveItems) then {
    // build the bike, player had 2 wheels and scrap metal and they have been removed
};

that's easy, right? :)

Link to comment
Share on other sites

 

if ([["PartWheel",2], "PartGeneric"] call player_checkAndRemoveItems) then {
    // build the bike, player had 2 wheels and scrap metal and they have been removed
};

that's easy, right? :)

 

Thank you so much for the introduction and the pedagogical approach. Very appreciated! *kisses on forehead*

But I'm afraid coding ain't easy for me. But I do like to play around.

 

 

deploy.sqf

if (false) then {
    cutText [format["You cannot build a bike while in combat."], "PLAIN DOWN"];
} else {
    player removeAction s_player_deploybike;
    player playActionNow "Medic";
    r_interrupt = false;
    if ([["PartWheel",2], "PartGeneric"] call player_checkAndRemoveItems) then {
    _dis=10;
    _sfx = "repair";
    [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
    [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
    sleep 6;
 
    _object = "Old_bike_TK_INS_EP1" createVehicle (position player);
    _object setVariable ["ObjectID", "1", true];
    _object setVariable ["ObjectUID", "1", true];
 
    player reveal _object;
 
    cutText [format["You've used built a bike! Now that's magic!"], "PLAIN DOWN"];
    r_interrupt = false;
    player switchMove "";
    player playActionNow "stop";
 
    sleep 10;
 
    cutText [format["Warning: Spawned bikes DO NOT SAVE after server restart! If you wish to keep it - deconstruct it!"], "PLAIN DOWN"];
 
};
};

pack.sqf

if (false) then { 
// player is in combat and cant pack his bike
    cutText [format["You are in combat and cannot re-pack your bike."], "PLAIN DOWN"];
} else {
	if (typeOf cursorTarget == "Old_bike_TK_INS_EP1" || typeOf cursorTarget == "Old_bike_TK_CIV_EP1") then {
	// player is looking at a bike and the target has a bike classname
	// delete it first to avoid player changing to another target
		deletevehicle cursorTarget; 
		player removeAction s_player_deploybike2;
		player playActionNow "Medic";
		r_interrupt = false;
		player addMagazine "ItemWheel";
		player addMagazine "ItemWheel";
		player addMagazine "ItemGeneric";		
		_dis=10;
		_sfx = "repair";
		[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
		[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
		sleep 6;
		cutText [format["You have deconstructed the bike and the parts is in your inventory."], "PLAIN DOWN"];
		r_interrupt = false;
		player switchMove "";
		player playActionNow "stop";
	} else {
		// player is not looking at a bike, or target does not have a bike classname
		cutText [format["You have to be facing your bike to deconstruct it!"], "PLAIN DOWN"];
	};
};

I've included your snippet in deploy.sqf and used the good old "player addMagazine" x3 for the pack.sqf. Does it look right? I feel like a two year old  being proud of drawing a stick man, even though all the proportions are fucked up and both arms are missing  :unsure:

Link to comment
Share on other sites

Look good, but you n eed to use the correct item names, there is no "ItemWheel", replace that with PartWheel like in the other script!?

anyway there is no easy way of telling if that will work, just try it yourself on a test server or whatever you use for testing :D

Link to comment
Share on other sites

Look good, but you n eed to use the correct item names, there is no "ItemWheel", replace that with PartWheel like in the other script!?

anyway there is no easy way of telling if that will work, just try it yourself on a test server or whatever you use for testing :D

Yeah, my bad on that one. Will try it out tonight and tell you how it went. Thanks a bunch for all the help!  :D

Link to comment
Share on other sites

Rewrote it a bit (no need for fn_selfActions):

 

loop.sqf

s_player_deploybike   = -1;
s_player_packbike     = -1;

waitUntil{!isNull player};

while {true} do {
	// -------------------- //
	// Deployable Bike Mod  //
	// -------------------- //
	private ["_hasToolbox", "_hasScrap", "_isBike", "_canDo", "_onLadder"];
        _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
	_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder);
	_hasToolbox = "ItemToolbox" in items player;
	_hasScrap = "PartGeneric" in magazines player;
	_isBike = typeOf cursorTarget in ["Old_bike_TK_INS_EP1","Old_bike_TK_CIV_EP1"];
	 
	//BIKE DEPLOY
	if((speed player <= 1) and _hasToolbox and _hasScrap and _canDo) then {
		if (s_player_deploybike < 0) then {
			s_player_deploybike = player addaction["Deploy Bike","custom\deployBike.sqf","",5,false,true,"", ""];
		};
	} else {
		player removeAction s_player_deploybike;
		s_player_deploybike = -1;
	};

	
	//PACK BIKE
	if((_isBike) and _canDo) then {
		if (s_player_packbike < 0) then {
			s_player_packbike = player addaction["Re-Pack Bike","custom\packBike.sqf","",5,false,true,"", ""];
		};
	} else {
		player removeAction s_player_packbike;
		s_player_packbike = -1;
	};
};

Custom variables.sqf:

DZE_safeVehicle = DZE_safeVehicle + ["Old_bike_TK_INS_EP1","Old_bike_TK_CIV_EP1"];

custom/deployBike.sqf:

private ["_dis", + "_object","_sfx"]; 
if (false) then {
    cutText [format["You are in combat and cannot build a bike."], "PLAIN DOWN"];
} else {
    player removeAction s_player_deploybike;
    player playActionNow "Medic";
    r_interrupt = false;
    if (["PartGeneric"] call player_checkAndRemoveItems) then {
		_dis=10;
		_sfx = "repair";
		[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
		[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
	 
		sleep 6;
	 
		_object = "Old_bike_TK_INS_EP1" createVehicle (position player);
		_object setVariable ["ObjectID", "1", true];
		_object setVariable ["ObjectUID", "1", true];
	 
		player reveal _object;
	 
		cutText [format["You have crafted a bicycle, a scrap has been removed."], "PLAIN DOWN"];
	 
		r_interrupt = false;
		player switchMove "";
		player playActionNow "stop";
	 
		sleep 10;
	 
		cutText [format["Warning: Spawned bikes DO NOT SAVE after server restart!"], "PLAIN DOWN"];
	};
};

packBike.sqf:

private ["_dis", "_sfx"];
if (false) then { 
// player is in combat and cant pack his bike
    cutText [format["You are in combat and cannot re-pack your bike."], "PLAIN DOWN"];
} else {
	if (typeOf cursorTarget == "Old_bike_TK_INS_EP1" || typeOf cursorTarget == "Old_bike_TK_CIV_EP1") then {
	// player is looking at a bike and the target has a bike classname
	// delete it first to avoid player changing to another target
		deletevehicle cursorTarget; 
		player removeAction s_player_packbike;
		player playActionNow "Medic";
		r_interrupt = false;
		player addMagazine "PartGeneric";		
		_dis=10;
		_sfx = "repair";
		[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
		[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
		sleep 6;
		cutText [format["You have packed your bike and been given back your scrap metal"], "PLAIN DOWN"];
		r_interrupt = false;
		player switchMove "";
		player playActionNow "stop";
	} else {
		// player is not looking at a bike, or target does not have a bike classname
		cutText [format["You have to be facing your bike to re-pack it!"], "PLAIN DOWN"];
	};
};

Did some minor changes, still mostly cen's script ( made private vars array, changed requirements, removed a weird global variable that wasnt really needed.

Infistar note: s_player_packbike and s_player_deploybike are whitelisted in default infistar YEY.

 

This should work :P

Link to comment
Share on other sites

deploy.sqf

if (false) then {
    cutText [format["You cannot build a bike while in combat."], "PLAIN DOWN"];
} else {
    player removeAction s_player_deploybike;
    player playActionNow "Medic";
    r_interrupt = false;
    if ([["PartWheel",2], "PartGeneric"] call player_checkAndRemoveItems) then {
    _dis=10;
    _sfx = "repair";
    [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
    [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
    sleep 6;
 
    _object = "Old_bike_TK_INS_EP1" createVehicle (position player);
    _object setVariable ["ObjectID", "1", true];
    _object setVariable ["ObjectUID", "1", true];
 
    player reveal _object;
 
    cutText [format["You've used built a bike! Now that's magic!"], "PLAIN DOWN"];
    r_interrupt = false;
    player switchMove "";
    player playActionNow "stop";
 
    sleep 10;
 
    cutText [format["Warning: Spawned bikes DO NOT SAVE after server restart! If you wish to keep it - deconstruct it!"], "PLAIN DOWN"];
 
};
};

pack.sqf

if (false) then { 
// player is in combat and cant pack his bike
    cutText [format["You are in combat and cannot re-pack your bike."], "PLAIN DOWN"];
} else {
	if (typeOf cursorTarget == "Old_bike_TK_INS_EP1" || typeOf cursorTarget == "Old_bike_TK_CIV_EP1") then {
	// player is looking at a bike and the target has a bike classname
	// delete it first to avoid player changing to another target
		deletevehicle cursorTarget; 
		player removeAction s_player_deploybike2;
		player playActionNow "Medic";
		r_interrupt = false;
		player addMagazine "PartWheel";
		player addMagazine "PartWheel";
		player addMagazine "PartGeneric";		
		_dis=10;
		_sfx = "repair";
		[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
		[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
		sleep 6;
		cutText [format["You have deconstructed the bike and the parts is in your inventory."], "PLAIN DOWN"];
		r_interrupt = false;
		player switchMove "";
		player playActionNow "stop";
	} else {
		// player is not looking at a bike, or target does not have a bike classname
		cutText [format["You have to be facing your bike to deconstruct it!"], "PLAIN DOWN"];
	};
};

Confimed working as of 1.4.0.2!

 

Thank you so much to AxeCop for all the help and to the original creators of the script  :)

Link to comment
Share on other sites

Hey, guys. New day, new question.

 

The script is working, but I want to modify it a little bit more. I don't want the "Deploy Bike" as an option on the scrolling menu, but rather when you right click the toolbox in the inventory. Is such an approach possible?

yes. search the forums, maca posted an HowTo add options to items in the inventory. but it's not easy for script beginners I think

Link to comment
Share on other sites

Yiiihaw! Got it working!

 

Deploy bike by using car wheels and scrap metal. Deploy by right clicking toolbox, deconstruct by scrolling the bike.

 

Step 1

- Allow for custom variables.sqf in your init.sqf.

- In you custom variables.sqf change DZE_safeVehicle = ["ParachuteWest","ParachuteC"] to ["ParachuteWest","ParachuteC","Old_bike_TK_INS_EP1"];

 

Step 2

- Download this folder, containing deploy.sqf, pack.sqf and extra_rc.hpp to your mission folder.

 

Step 3

- Create a custom ui_selectSlot.sqf and include it from your custom compiles.sqf.

- After the bracket on line 56, paste the snippet below.

// Add extra context menus
_erc_cfgActions = (missionConfigFile >> "ExtraRc" >> _item);
_erc_numActions = (count _erc_cfgActions);
if (isClass _erc_cfgActions) then {
    for "_j" from 0 to (_erc_numActions - 1) do 
    {
        _menu =  _parent displayCtrl (1600 + _j + _numActions);
        _menu ctrlShow true;
        _config =  (_erc_cfgActions select _j);
        _text =  getText (_config >> "text");
        _script =  getText (_config >> "script");
        _height = _height + (0.025 * safezoneH);
        uiNamespace setVariable ['uiControl', _control];
        _menu ctrlSetText _text;
        _menu ctrlSetEventHandler ["ButtonClick",_script];
    };
};

Step 4

- Create a custom fn_selfActions.sqf and include it from your custom compiles.sqf.

- At the very bottom of the fn_selfActions paste the following snippet

_weapons = [currentWeapon player] + (weapons player) + (magazines player);
_isBike = typeOf cursorTarget in ["Old_bike_TK_INS_EP1","Old_bike_TK_CIV_EP1"];
 
//PACK BIKE
if((_isBike) and _canDo) then {
if (s_player_deploybike2 < 0) then {
        s_player_deploybike2 = player addaction[("<t color=""#007ab7"">" + ("Re-Pack Bike") +"</t>"),"path\to\pack.sqf","",5,false,true,"", ""];
    };
} else {
    player removeAction s_player_deploybike2;
    s_player_deploybike2 = -1;
};

Step 5

- At the bottom of description.ext, add #include "path\to\extra_rc.hpp".

 

And voila, the script should work. The different components of the script are taken from great scripters (I think cen made the original bike-crafting script), but this is patched together by a newbie to fit my taste for needing two car wheels and scrap metal + right clicking toolbox, so I'm sure there is much room for improvement. But it's been a fun few hours trying and failing -and in the end succeeding   :D

Link to comment
Share on other sites

Hey guys, I also have found a issue with this script on our server.  Once I deploy a bike, I cannot scroll on it if I get off it either inside or on top of a building.  You come up to it and it's like it doens't even recognize the target, you get no scroll options for getting in it or repairing it or packing it.  Works fine parked on the ground.

 

Anybody else having this issue?  Any ideas?

Link to comment
Share on other sites

I just redirected the fn_selfactions in compiles.sqf like so:

 

fnc_usec_selfActions = compile preprocessFileLineNumbers "custom\fn_selfActions.sqf"; //Checks which actions for self

In the ui_

 

Was there something else I needed in compiles.sqf?  This is the only change I made for this script (then I added the self actions to the fn_selfactions.sqf, of course, but that is working fine).  I can build and pack the bike, just not when it is parked on a building or in a building like a barn.  Also, I can enter and exit a bike, just not when it is in a building or on a building...

 

Thanks!

 

-Shawn

Link to comment
Share on other sites

Ok so I changed a few lines to allow the MMT_USMC to be used instead and only be one scrap metal.

It deploys just fine.. But I cant pack it?

_weapons = [currentWeapon player] + (weapons player) + (magazines player);
_isBike = typeOf cursorTarget in ["MMT_USMC","MMT_USMC"];

if (false) then {
    cutText [format["You cannot build a bike while in combat."], "PLAIN DOWN"];
} else {
    player removeAction s_player_deploybike;
    player playActionNow "Medic";
    r_interrupt = false;
    if (["PartGeneric"] call player_checkAndRemoveItems) then {
    	_dis=10;
    	_sfx = "repair";
    	[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
    	[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
   	 sleep 6;
 
   	 _object = "MMT_USMC" createVehicle (position player);
   	 _object setVariable ["ObjectID", "1", true];
   	 _object setVariable ["ObjectUID", "1", true];
 
   	 player reveal _object;
 
    	cutText [format["You've used built a bike! Now that's Purgatory magic!"], "PLAIN DOWN"];
   	 r_interrupt = false;
   	 player switchMove "";
   	 player playActionNow "stop";
 
    	sleep 10;
 
   	 cutText [format["Warning: Spawned bikes DO NOT SAVE after server restart! If you wish to keep it - deconstruct it!"], "PLAIN DOWN"];
 
	};
};
_weapons = [currentWeapon player] + (weapons player) + (magazines player);
_isBike = typeOf cursorTarget in ["MMT_USMC","MMT_USMC"];

This is at the very bottom of my self actions

//PACK BIKE
if((_isBike) and _canDo) then {
if (s_player_deploybike2 < 0) then {
        s_player_deploybike2 = player addaction[("<t color=""#007ab7"">" + ("Re-Pack Bike") +"</t>"),"bike\pack.sqf","",5,false,true,"", ""];
    };
} else {
    player removeAction s_player_deploybike2;
    s_player_deploybike2 = -1;
};
Link to comment
Share on other sites

  • 1 year later...

I might also recommend in your deploy and pack scripts you add a unique variable so players aren't able to repack any bicycle they come across, only one that has been deployed. Also I recommend having it placed directly in front of the player.For example in the deploy script

   	 sleep 6;
	_Offset = [0,5,0]; //change how far from player vehicle spawns
	_worldPos = player modelToWorld _Offset; // spawn in front of player
    _object = "MMT_USMC" createVehicle (_worldPos);
   	_object setVariable ["ObjectID", "1", true];
   	_object setVariable ["ObjectUID", "1", true];
	_object setVariable ["Deployed", "1", true];
 	_degrees = getDir player;
	_object setDir _degrees;
   	 player reveal _object;

and in the pack script

if ((typeOf cursorTarget == "Old_bike_TK_INS_EP1" or typeOf cursorTarget == "MMT_USMC") and (cursorTarget getVariable ["Deployed", "0"] == "1")) then {

Now if someone could help me figure out a way to cancel the build by moving, lets say you suddenly change your mind or you're getting shot at and need to move... that would be spectacular. I have it working on my overwatch server but that uses a scroll wheel option to deploy. I can't seem to get it working on the right click script. Here's my deploy script

_weapons = [currentWeapon player] + (weapons player) + (magazines player);
closeDialog 0;

_toolbox = "ItemToolbox" in _weapons;

if (!_toolbox) then {
    cutText [format["Missing Toolbox"], "PLAIN DOWN"];
} else {
    player removeAction s_player_deploybike;
    player playActionNow "Medic";
    r_interrupt = false;
	player removeWeapon "ItemToolbox";
    	_dis=10;
    	_sfx = "repair";
    	[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
    	[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
   	 sleep 6;
	_Offset = [0,5,0]; //change how far from player vehicle spawns
	_worldPos = player modelToWorld _Offset; // spawn in front of player
    _object = "MMT_USMC" createVehicle (_worldPos);
   	_object setVariable ["ObjectID", "1", true];
   	_object setVariable ["ObjectUID", "1", true];
	_object setVariable ["Deployed", "1", true];
 	_degrees = getDir player;
	_object setDir _degrees;
   	 player reveal _object;
 
    	cutText [format["Here's your bike you lazy bum!"], "PLAIN DOWN"];
   	 r_interrupt = false;
   	 player switchMove "";
   	 player playActionNow "stop";
 
    	sleep 10;
 
   	 cutText [format["Warning: Spawned bikes DO NOT SAVE after server restart! If you wish to keep it - deconstruct it!"], "PLAIN DOWN"];
 
	
};

Link to comment
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
  • Advertisement
×
×
  • Create New...