Adding Skills into our RPG

This one was just a thought on the top of my head, but let’s say we want to add skills to our player in-game, for example if we want it to be a survival RPG style, and we want him to cut down trees, be able to cook, fish, mine, smith, etc (the point is, I want him to extract results from a skill, after a random amount of time, and that time decreases as his experience and levels increase. For example, what takes him 20 seconds to accomplish at level 1 might take him just 10 seconds at level 20). What’s a good starting point for us to start programming something like this into our game?

I would suggest running a coroutine/invoke function that is ran during a fishing, hunting, etc event, that checks to see if 10 seconds is passed at the start of the first hit/gunshot, and then when 10 seconds passed, to see if the task was completed

The time itself is relatively easy, and there are several ways to accomplish this…
If you’re just basing it on level, you can create a Stat like Stat.MiningTime that decreases as you level.

A more realistic approach may be to increase the skill level… for which you’d need a separate Skill Stats system like the Base Stats… You’d be tracking experience in each skill and levelling up the skill as the player earns experience by doing. Once again, you’d have some sort of either an array or formula for calculating skill time needed, or quality of loot gained by practicing the skill.

This one involves a bit of work, but all the building blocks are there within the courses.

Hi Christopher. That sounds like a solid start, but I want something… progressive, rather than time-dependant. I don’t want something that forcefully hits 10 seconds before outputting a result, especially when the stats are high

Hi Brian, I’ll definitely return to this comment in a while, as I have overloaded myself with questions and uncompleted tasks, it’s becoming a nightmare for me with this project. What similarities can be expected between the Progression Stat we built in the first course, and the task I did seek help for?

The skill advancement itself could be built very much like the Progression… You’ll need some sort of class that tracks the experience from a given skill. Using a skill would tell this component to increase experience in that skill, and then check to see if the skill has levelled up.

And quite possibly overloaded a certain Teaching assistant. :stuck_out_tongue:

Yeah, I get you, I might have originally misunderstood the question, and never realized it until I saw Brains reply, sorry I couldn’t help you out man.

I am certain I have overloaded you with me as well Brian. I sincerely apologize for that, I promise one day it will all end :slight_smile: (I’m just appreciative that there’s at least someone willing to help me out)

For now I’m just trying to debug my code, because for some reason the Abilities give me a Null Reference exception error, a problem I bought up to Udemy last night. Please do have a look at it (Lecture 37) whenever you have the time

No worries Christopher. Thank you for at least giving it a try :smiley:

1 Like

Anytime :relaxed:

1 Like

Whenever you get a null reference exception, the first thing to do is look at the specific line of code that is coming up null… in the post you referenced, it was in PlayerController.cs, and the line was

actionStore.Use(i, gameObject);

Null reference exceptions only happen on reference types… so of the three things listed here (actionStore, i, and gameObject), only two of them are reference types (i is an integer, which is a value type).
gameObject cannot be null, because it refers to the gameObject which the PlayerController is attached to, and since a MonoBehaviour like PlayerController can only exist on a GameObject, gameObject cannot be null.
This leaves actionStore.
Presumably, you have a line further up in your code

private ActionStore actionStore;

Or, you may have chosen to go the SerializedField route

[SerializeField] private ActionStore actionStore;

In the case of the SerializeField route, check to make sure that the actionStore is assigned in the inspector.
Otherwise, the issue is that it likely hasn’t been initialized in either Start() or Awake(). (In this case, it doesn’t matter which, as PlayerController is not an ISaveable component. If it’s not initialized with a GetComponent in one of those two methods, it will logically still be null in Update().

yup, it was created twice, once as a variable, and once as an Awake. I deleted the one in awake, and assigned the one we created as a Variable over there instead, and it worked. Thanks again Brian :slight_smile:

Privacy & Terms