Jump to content

Drainable item that gives xp to certain skill when used.


DeadlyStr1ke

Recommended Posts

Hello everyone!

I've recently ran into some trouble while trying to make an item, that is drainable(I believe I succeeded in that part) and when used will slowly be usedu p while giving xp to a particular skill.

 

I am super new to scripting, so sorry if my methods of executing some of my ideas will make you facepalm.

 

Here's an example of what I'm trying to achieve, if that is even possible:

 

I have an item. The item is a punching bag, I already have a working recipe to craft it.

Now what I wan't the player to do is to use it for a long period of time, gaining say, 20xp to strenght at the end of every use. The item will slowly degrade and eventually I'll have to replace the bag with a new one to continue exercising with it.

 

 

Now, beeing new and complete 0 at scripting when it comes to Zomboid, this is how I planned to execute it via a recipe.

Recipe Code:

recipe Exercise with Punching Bag
    {
    ETPunchingBag = 1,
CanBeDoneFromFloor:true,
OnGiveXP:TrainPunchingBag_OnGiveXP,
OnCreate:recipe_removedummytrain,
Result:ETDummyResult,
    Time:400.0,
    }

 

Now the OnGiveXp and OnCreate functions that are in one lua file. Here's the full file how I have it:

 

function TrainPunchingBag_OnGiveXP(recipe, ingredients, result, player)
    player:getXp():AddXP(Perks.Strength, 10);
end
 
 
----Dummy Result Item 
--Result creates dummy item when using the training recipes, which then gets instantly removed by the function
function recipe_removedummytrain(items, result, player)
local inv = player:getInventory();
inv:RemoveItem("ETDummyResult");

 

 The problem I run into is that the item isn't craftable when OnCreate line is present in the recipe. I can use the recipe if I take it out, but OnGiveXP also gives no xp.(Misspelled "Strength" was to blame for that one. Thanks Dimitri Valko!)

Edit: Still doesn't give the 10 xp in Strength after using it.

 

Now, I know that the way I'm trying to execute this without proper knowledge may be the worst possible way to do it and there's a straight easy way of doing it, so I reach out to you guys, to help me out with this one, give some advice or point to the right way of executing this, if it is possible.

Thanks in advance!

Link to comment
Share on other sites

Oh, thanks a lot! Don't know how I haven't noticed that after going through the code couple of times. Guess 24 hours without sleep is beginning to take it's toll.

That one's one me then, now I just need to figure out how to remove the dummy result item as soon as it is crafted, if not a completely different way of executing the idea.

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
×
×
  • Create New...