Jump to content
Sign in to follow this  
razzored

Grinding Script HELP

Recommended Posts

Hi, So i am working on a RPG... And i need some grinding features.. 
However, i lack creativity with a specific funtion :S

Im trying to make a script which i can attach to the init of certian objects ect, gold and iron ores.. trees and such, which basically should do the following.
If player has X object, Play X animation for X time then have X% chance of giving X item, else display hint.
If player does not have X object, Display hint "You are missing X Item".

 

Basically, to mine, pick fruits and all sorts of stuff.
I already have all the stuff setup.. custom equipment, custom objects and all..

But this specific feature is bugging me for some reason.
Any ideas?

Share this post


Link to post
Share on other sites

In a nutshell, addAction to the object with condition checking if player has an item, if yes, show action. If player activates action play animation. 

Share this post


Link to post
Share on other sites

I thought along the same lines.. problem is, i suck at addActions..

I always end up making various syntax erros or similar.

To demonstrate my lack of experience..
These are my two most "advanced" add actions i've ever made

 

This addAction ["Give MAP", "this addWeapon ItemMap", [] , 1 , true , true , "" , "_this == _target"]; 

player addAction ["GOD ON", "player allowdamage false", [] , 1 , true , true , "" , "_this == _target"]; 

Share this post


Link to post
Share on other sites

@razzored,

Quote

Does anybody have an example i could use?

Here's an addAction example,

player addAction ["God Mode", {

if (player getVariable ["godMode", 0]==0) then {
			player allowDamage false;
			player setVariable ["godMode", 1];
            systemChat "God Mode Enabled";
} else {
			player allowDamage true;
			player setVariable ["godMode", 0];
			systemChat "God Mode Disabled";
	};
}];

The "grinding" game mechanic must consider many variables.

Without the details it's impossible to say exactly but these functions may give you an idea,

This function configures an addAction for the caller (this one is more-or-less functional),

Spoiler

you_fnc_action=
{	params [["_caller", objNull], ["_actionNAME", ""], ["_message", ""], ["_duration", 1]];

	theOBJ=_caller;
	theMESS=_message;
	theDuration=_duration;
interactTHIS=[ player, _actionNAME,
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",

"theOBJ distance vehicle player < 3", "alive player",{},{}, 
{
	if (player getVariable ["hasTool", 0]==1) then {
		systemChat theMESS;
		//[theOBJ, true, 0, 0] spawn you_fnc_harvest;// see below
		player removeAction interactTHIS;
	} else {
		systemChat "You need a tool to harvest this resource";
	};
},{},[],theDuration,0,false,true] call BIS_fnc_holdActionAdd;
};

// call with: [objNAME, "Harvest", "Harvesting...", 5] call you_fnc_action;
// set variable: player setVariable ["hasTool", 1];

 


And this is the kind of idea you might use for your harvest (hypothetical pseudo-code),

Spoiler

you_fnc_harvest=
{	params [["_caller", objNull], ["_hasTool", false], ["_typeReward", objNull], ["_typeAnim", ""]];

	if (_hasTool) exitWith {
				_caller enableSimulation false;
				_caller switchmove _typeAnim; //from array or call
				_luck= selectRandom [1,2,3];
sleep 5;
		if (_luck==1) then {
					player additem _typeReward;
					systemChat "Harvest was successful";
			} else {systemChat "Harvest was unsuccessful"};
					_caller enableSimulation true;
					_caller switchMove "";
	};
};

 


Good timing though. I'm working on something similar you may be able to use when finished.

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites

Thank you so much wogz187.
And yeah, lucky timing ^^


The pseudo code odly enough makes a lot of sense to me.

 

The first one however, i failed to see anywhere in the code where it "adds reward" to players inventory.
But i will implement it and see if i can get it working ASAP 🙂 Will reply once i´ve checked it out.

  • Like 1

Share this post


Link to post
Share on other sites

@razzored,

Consider this,

By creating arrays of potential resources with rewards corresponding in another array the same "select" variable could assign the needful reward to the collected resource. Ditto for something like "hasTool" provided you require separate tools for each resource. Three arrays with corresponding entries 1) resources, 2) rewards, 3) requirements-- this would make it easiest to create a single, ambiguous function to handle every event.

The logic being:
if (resource (x) and hasTool (x)) then {reward (x)} else {wrong tool}

Quote

i failed to see anywhere in the code where it "adds reward"

In the pseudo-code,

player additem _typeReward;

However in many cases the "reward" will be a variable and not a physical object.

_resourceX = player getvariable "resourceX";
player setvariable ["resourceX",_resourceX + 1];
_totalX= player getvariable "resourceX";

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

Hi @wogz187 i had no luck with the script.
Most likely due to me, being an absolute retard.

 

I first tried, putting it in a script (replacing the values) and calling it from the item via an addaction, that did not work, prolly due to me being retarded as said.
Then i tried running code straight from INIT inside the object, It would not accept it, no matter how much i altered it.

As for why i'd like it to be inventory items rather than a variable, thats because. A i already have a trading/ shop system in place using objects. Only the currency is a variable.
B. Having them as objects makes it much easier for people to Rob each other and trade on the spot.. no need to make UI,s and stuff for that.. just kill them or force them to drop it..
It also limits the amount of X they can carry, without any scripting needed, since carryweight/inventory space is already in the game.

Im getting a feeling, this might become more complicated than i initially expected ^^ 

Though you definitely seem to get what i am after, which is great.
 

Also the _Luck variable is something i do not quite understand. neither does the game it seems.
I understand its a variable, but is it probably defined? The game does not seem to know what to do with it. 

Sorry if that is a bunch of questions in one message, i hope its not too much of a flusterfuk

Share this post


Link to post
Share on other sites

@razzored,

Quote

Also the _Luck variable is something i do not quite understand. neither does the game it seems.


I don't think that block of pseudo-code will compile...

The idea was something like,

_luck= selectRandom [1,2,3]; 
if (_luck==1) then { success};

You will almost undoubtedly need something else to determine success though. For example: a "skill" variable.
 

Quote

Im getting a feeling, this might become more complicated than i initially expected ^^ 

Yeah but totally do-able.

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

@razzored,

Here's a simplified version of yesterday's idea,

Spoiler

you_fnc_simpleHarvest=
{ params [["_reward", objNull], ["_tool", false], ["_duration", 0]];
duration=_duration;
reward=_reward;
if (_tool) then {
harvest=[ player, "Harvest Resource", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"(cursorTarget getvariable ""isResource"") ==1", "alive Player", {}, {}, { 
	player additem reward;
	systemChat "Resource Harvested";
}, {}, [], duration, 0, false, true] call BIS_fnc_holdActionAdd;
	};
};

//call example: ["NVGoggles", true, 5] call you_fnc_simpleHarvest;
//this setVariable ["isResource", 1];

Will allow player to "harvest" from any object with variable "isResource" provided "_tool" is true.

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

@wogz187 Hi, So the way i tried the script was.
Added it to init.sqf and used the call example in init of the object aswell as the setVariable..
That did not work well, did i set it up incorrectly?

Share this post


Link to post
Share on other sites

@razzored,

To see how the function works,
a) paste this into an object's init properties:

this setVariable ["isResource", 1];

b) paste the function into the debug console or  pretty much anywhere script will stick (ex. init properties or init file) along with the call. Like this:

Spoiler

you_fnc_simpleHarvest=
{ params [["_reward", objNull], ["_tool", false], ["_duration", 0]];
duration=_duration;
reward=_reward;
if (_tool) then {
harvest=[ player, "Harvest Resource", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"(cursorTarget getvariable ""isResource"") ==1 && player distance cursorTarget<3", "alive Player", {}, {}, { 
	player additem reward;
	systemChat "Resource Harvested";
}, {}, [], duration, 0, false, true] call BIS_fnc_holdActionAdd;
	};
};

["NVGoggles", true, 5] call you_fnc_simpleHarvest;

 

c) when you use the "isresource" object you will get the reward

Note: Once called the function is always running. Any object with "isResource" will be harvestable. Replace "NVGoggles" with needful rewards.

Have fun!

Edited by wogz187
added additional condition to make sure player is near resource to initiate harvest
  • Like 1

Share this post


Link to post
Share on other sites

@razzored,
This function goes along with the one from above to randomly place the harvest-able resource,

Spoiler

you_fnc_randomLoot=
{	params [["_caller", objNull], ["_typeVeh", objNull], ["_resourceCount", 1]];
for "_i" from 0 to _resourceCount do 
	{
	_pos = _caller getPos [1000 * sqrt random 1, random 360];
	_obj = _typeVeh createVehicle _pos;
	_obj setVariable ["isResource", 1];
	};
};

//call example: [player, "Land_paperBox_closed_f", 20] call you_fnc_randomLoot;

 

Have fun!

Thanks to @killzone_kid for the sqrt!

  • Like 1

Share this post


Link to post
Share on other sites

Holy cow, thanks @wogz187
I havent had much testing time, due to having a busy week.

But once the week is over, i hope to get it all setup 🙂

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×