Jump to content

Character Perk Creation, Assistance appreciated


Recommended Posts

Character Perks complete

 

Thanks to everyone that helped.

 

So I'm working on a character for my first mod, and I got a couple ideas for some basic changes.

 

The learning experience is the most important part, so any additional details explaining whats taking place are welcome.

 

1st Perk: Strong with some weapons, Weak with others

 

for my character I want when my character equips particular weapons (spear, boomerang, axe, pickaxe, etc) for his damage modifier to be reduced to 50%.  But when he equips other weapons (dark sword, blow darts) it increases his modifier.

 

In concept it seems like having the modifier change upon equipping/unequipping of the items would be the easiest way to get it done.  But I haven't done this before so I'm not sure how to make such an event.

 

 

2nd Perk: Strong with some armor, Weak with others

 

Similar to the first perk, but a little different.  When my character equips certain types of armor (like grass suit and log suit) they lose durability faster and have less damage absorb, where as others (nightmare armor, marble suit) have the reverse.

 

Not quite sure how to get that one to work.

 

 

3rd Perk: Has an item that can predict next hound attack.

 

I actually know the function to call for this one.  GetTimeToAttack() from hounded.  And I believe dividing the number by 480 and rounding down (or cutting off the decimal) gets me the day count (Unless I have that wrong)  I tested it in console and thats where I got the inspiration for it.  I also want to have it drain sanity (Mostly so I can know how to add these properties to future items) which I believe I can reference wickerbottoms books and maxwells book for how that can take place.

 

Now correct me if I'm wrong, but I believe I need to make a prefab for the item in question that gets used, and put the functions in accordingly similar to how other identical items work.  I would have the item get used, drain the necessary costs, then run a function that has my character state a string with the value obtained from hounded indicating the duration from the next hound attack.

Link to comment
Share on other sites

Great concepts! Sounds like a fun character.

 

1) You're right, applying the modifier upon equipping and resetting it upon unequipping is probably the best approach for this. If you take a look at the inventory component, you can listen for the respective events and fire the respective functions. As for the variable to change, I recommend the players combat component 'damagemultiplier', which changes the weapons damage for this prefab (only the bonus won't get multiplied, and I don't even know what that is).

 

2) This one is way trickier, since combat and armor are rather inflexible. You can probably change the armor itself though, using the same method as above (the event data of 'unequip' even gives you an item reference, so you can undo your changes).

 

3) For this one, you can use the 'book' component, or the 'useableitem' component. Both allow you to fire a function, in which you can call the players sanity component and 'DoDelta' with a negative value, and call the talker component to 'Say' how long until the next attack.

If you want to, you could add 'finiteuses' to it.

 

Pardon if I was a bit too complicated there.

Link to comment
Share on other sites

Great concepts! Sounds like a fun character.

 

1) You're right, applying the modifier upon equipping and resetting it upon unequipping is probably the best approach for this. If you take a look at the inventory component, you can listen for the respective events and fire the respective functions. As for the variable to change, I recommend the players combat component 'damagemultiplier', which changes the weapons damage for this prefab (only the bonus won't get multiplied, and I don't even know what that is).

 

2) This one is way trickier, since combat and armor are rather inflexible. You can probably change the armor itself though, using the same method as above (the event data of 'unequip' even gives you an item reference, so you can undo your changes).

 

3) For this one, you can use the 'book' component, or the 'useableitem' component. Both allow you to fire a function, in which you can call the players sanity component and 'DoDelta' with a negative value, and call the talker component to 'Say' how long until the next attack.

If you want to, you could add 'finiteuses' to it.

 

Pardon if I was a bit too complicated there.

Hardly that complicated at all my friend, I mentioned I was a computer science major in a previous thread :-).

 

So lets see if I can figure this out one piece at a time.

 

For number 1.  I'm guessing that my character should have

inst:ListenForEvent("equipped", onequipchange(inst))

Does this mean that when my character has an item "Equipped" it will run my local function onequipchange with inst passed to it?

 

as for my function

local function onequipchange(inst)--      if currently equipped weapon is a weak weapon then		inst.components.combat.damagemultiplier = 0.5	elseif -- currently equipped weapon is a strong weapon then		inst.components.combat.damagemultiplier = 2.0        else   -- currently equipped weapon is neither, so default the multiplier.                inst.components.combat.damagemultiplier = 1.0	endend

Am I on the right track here?

 

I'm trying to figure out how I can grab data on the players currently equipped weapon.

I found 

act.doer.components.inventory:GetEquippedItem(act.target.components.equippable.equipslot)

in the actions.lua

along with

function Combat:GetWeapon() 

in combat.lua

 

I'm testing in console right now and function Combat:GetWeapon() gives me the table value for my currently equipped weapon.  But it's not a string so I'm not sure what to do with it yet.

 

I'm right now looking for a way to grab the name of the item (Preferrably in a string format) so I can compare it to an array of items that my character should have adjustments for so I can make the adjustment.

 

I don't know what to do with a table variable.  I'm testing with an axe but essentially this is what I got so far.

local function onequipchange(inst)	print("Equip Change Test")	if inst.components.combat:GetWeapon() == "axe" then		inst.components.combat.damagemultiplier = 0.5	else		inst.components.combat.damagemultiplier = 2.0	endend

Except this doesn't work because it gives me a table variable which is not a string.  I'm trying to figure out what to do.

 

Link to comment
Share on other sites

Hardly that complicated at all my friend, I mentioned I was a computer science major in a previous thread :-).

For number 1.  I'm guessing that my character should have [...]

Am I on the right track here?

 

Yes, this is what I meant. The function you described fires whenever a new handheld item is equipped (and on loading the world too, I think. You should call the function in the main function 'fn' to make sure). You don't need a function for unequipping, since the variable you change only affects weapons. As such, the only thing missing here is...

 

I'm testing in console right now and function Combat:GetWeapon() gives me the table value for my currently equipped weapon.  But it's not a string so I'm not sure what to do with it yet.

 

I'm right now looking for a way to grab the name of the item (Preferrably in a string format) so I can compare it to an array of items that my character should have adjustments for so I can make the adjustment.

 

The table you get is the instance (or entity), a table with all basic data, components, position information, etc. Usually it's referred to by the variable 'inst', and it has an element called 'prefab'. So 'inst.prefab', or in your case 'inst.components.combat.GetWeapon().prefab' (as 'inst' is the player) returns the prefab name of the instance.

Keep in mind that you need to check for whether there is a weapon to begin with, or else the game will crash (attempt to index a nil value).

Link to comment
Share on other sites

Yes, this is what I meant. The function you described fires whenever a new handheld item is equipped (and on loading the world too, I think. You should call the function in the main function 'fn' to make sure). You don't need a function for unequipping, since the variable you change only affects weapons. As such, the only thing missing here is...

 

 

The table you get is the instance (or entity), a table with all basic data, components, position information, etc. Usually it's referred to by the variable 'inst', and it has an element called 'prefab'. So 'inst.prefab', or in your case 'inst.components.combat.GetWeapon().prefab' (as 'inst' is the player) returns the prefab name of the instance.

Keep in mind that you need to check for whether there is a weapon to begin with, or else the game will crash (attempt to index a nil value).

Cool, I'll be sure to check for a nil value before attempting to grab information from it. should I do this as a check?

	if inst.components.combat:GetWeapon() ~= nil then

havent tested it yet, but in theory it sounds like it should do the trick.

 

Trying to get the listener event to work.  Curious though, theres an "equip" event and an "equipped" event.  Do I want the "equip" event?  since that sounds like the act of equipping, where as "equipped" sounds like it would trigger whenever theres an item currently equipped.  I wouldn't know so I'm just gonna have to check it.

 

Edit: I think this event is meant for items.  I rechecked where it's used, and it looks like what it's actually checking is to see if the item itself is being held by somebody, not whether or not a player is holding something.  Since the character isn't an item, I don't know what exactly might be happening.

 

Edit 2: Okay I think "equip" is the event I'm looking for.  I just gotta check a couple of things.

 

Edit 3: Okay I've been trying but I can't get this event to trigger when I switch weapons.  I've tested the function by making it global and calling it with the console, but I can't get the ListenForEvent to trigger whenever I change weapons

 

Edit 4: Okay lesson learned, had to remove the (inst) from the ListenForEvent function.  It works fine now.

Link to comment
Share on other sites

Okay First perk is done, heres my functions

local weak_weapon = {"axe","pickaxe","goldenaxe","goldenpickaxe","shovel","goldenshovel","spear","boomerang"}local strong_weapon = {"nightsword","blowdart","firedart"}local function checkformatch(heldweapon,weapons)	local i = 1  --I see how it is, Lua arrays start at 1 instead of 0 	while weapons[i] ~= nil do		if heldweapon == weapons[i] then			return true		end		i = i + 1	end	return falseendlocal function onequipchange(inst)	if inst.components.combat:GetWeapon() ~= nil then		if checkformatch(inst.components.combat:GetWeapon().prefab,weak_weapon) then			inst.components.combat.damagemultiplier = 0.5		elseif checkformatch(inst.components.combat:GetWeapon().prefab,strong_weapon) then			inst.components.combat.damagemultiplier = 2.0		else			inst.components.combat.damagemultiplier = 1.0		end	endend

If anybody has any optimization suggestions feel free to suggest, but the function runs perfectly.

 

Now that I got a feel for it lets see what I can do about armor.

 

Edit: Okay, I have an idea to adjust the armor whenever it gets equipped on the character, it will relatively adjust it's current statistics while it's being worn, but the moment it unequips it needs to be reverted back to normal.  But when it reverts back to normal, it needs to retain the relative damage that it took (if it's 50% broken, it needs to be 50% broken)

 

More importantly, how can specify the armor to be readjusted when it gets unequipped or dropped?

 

 

Link to comment
Share on other sites

Okay First perk is done, heres my functions

EDIT: removed code

If anybody has any optimization suggestions feel free to suggest, but the function runs perfectly.

 

Now that I got a feel for it lets see what I can do about armor.

 

Great!

 

When a variable in Lua has a value other than nil or false, it automatically acts as true. As such, the ~= nil are unnecessary and can simply be removed.

Also, when going through tables, you can use a certain modification of for loops:

for key_variable, value_variable in pairs(table) do [...] end

Within the loop, the key_variable (usually called k)(in your code i) and value_variable (v)(weapons) are representing the elements, one by one.

There should be another explanation of this in the API docs (link in signature).

Link to comment
Share on other sites

 

Great!

 

When a variable in Lua has a value other than nil or false, it automatically acts as true. As such, the ~= nil are unnecessary and can simply be removed.

I'm guessing what you mean is, if it comes out as nil then it counts as false?  Well it was a force of habit of mine.

 

 

Also, when going through tables, you can use a certain modification of for loops:

for key_variable, value_variable in pairs(table) do [...] end

Within the loop, the key_variable (usually called k)(in your code i) and value_variable (v)(weapons) are representing the elements, one by one.

There should be another explanation of this in the API docs (link in signature).

In other words I should use a for loop instead of a while.  How would that look then?

 

Edit: Is this what you meant?

local function checkformatch(item,v)	for k, v in pairs(table) do		if item == v then			return true		end	end	return falseend
Link to comment
Share on other sites

I'll get to figuring out and optimizing that loop later, for the mean time I wanna learn some stuff for the second perk.

 

 

So I was looking into the armor.lua because I wanted to see if I can adjust the armor when it gets equipped.

 

I don't think it has a function I need, so I wanna make one for it.

 

 

I believe the term is called "overriding" correct me if i'm wrong, but I think what I need to do is create a components\armor.lua in my mod folder so I can create my own method for the armor.lua that will get added on to it.

 

 

I'm not sure exactly how to do this at the moment so I'm gonna see if I can figure it out and find references.  I'll edit this reply with what I make out of it.

 

Edit: Okay I figured it out by looking at another mod, so I just copy the armor lua into my mod folder in a folder where it would belong, then just add the function accordingly.

Link to comment
Share on other sites

@Zackreaver While it is possible to override entire files as you mentioned, it isn't very good for compatibility (and in many cases, performance). I recommend using the method described in this guide to override the functions you want to change, and only for your character's armour.

See the "Tables as objects (and how to modify their functions nicely)" section.

Link to comment
Share on other sites

@Zackreaver While it is possible to override entire files as you mentioned, it isn't very good for compatibility (and in many cases, performance). I recommend using the method described in this guide to override the functions you want to change, and only for your character's armour.

See the "Tables as objects (and how to modify their functions nicely)" section.

thank you for the advice blueberrys, this is why I'm sharing what I'm doing here on this thread, so people can correct me into the more preferrable methods.

 

Edit: Oh right rezecib, he linked me his guide before.  Guess I'm ready to start using his guide now that I got a good understanding on whats going on.

 

Edit2: Okay I get it, so I want to try and avoid overriding armor.lua if I can help it.  I understand exactly why too, since if armor.lua gets updated by klei or by another mod that uses it, it could cause problems.

 

Still trying to figure out exactly what I should do to get what I need though.

 

Edit3: Okay I sorta get it, so instead of changing the armor.lua, i'll have my lua script create a function that gets added to the armor.lua for what I need?

 

I kinda get that, still trying to narrow down exactly HOW I do that, but it makes sense.  Isn't that basically similar to overloading in java?

Link to comment
Share on other sites

Edit: Oh right rezecib, he linked me his guide before.  Guess I'm ready to start using his guide now that I got a good understanding on whats going on.

I'd recommend looking through the portions he points out in the beginning of the post, at least those which you aren't familiar with yet. 

 

Still trying to figure out exactly what I should do to get what I need though.

What are you stuck with right now? Perhaps I can help.

 

Example on what you can do with the armor. Changing the GetPercent fn through the character's instance lua file.

Edit 3: The instance below is referring to the armor's instance, not the player's instance.

local inst.components.armor.old_GetPercent = inst.components.armor.GetPercentinst.components.armor:GetPercent = function(amount)    amount = amount/2    return inst.components.armor:old_GetPercent(amount)end

Edit: Fixed syntax error above.

 

Edit 2: Fixed armour, haha.

 

Edit 4: The code above won't do anything because the "amount" parameter doesn't do anything in the original Armor:GetPercent function. Regardless, this example still stands on how functions can be modified.

Link to comment
Share on other sites

Edit3: Okay I sorta get it, so instead of changing the armor.lua, i'll have my lua script create a function that gets added to the armor.lua for what I need?   I kinda get that, still trying to narrow down exactly HOW I do that, but it makes sense.

Example on how to achieve it in my post above.

 

I kinda get that, still trying to narrow down exactly HOW I do that, but it makes sense.  Isn't that basically similar to overloading in java?

Not exactly. In Java, overloading works only when using the same function name with a different number of parameters. It's not intended for overwriting existing functions, it's to allow the usage of a varying number of parameters in function calls. As far as I know, you can't overwrite a function once it's created in Java.

In lua, functions are more flexible. You can overwrite them wherever you want, and even set them to nil or another type of variable during execution. It's more similar to Javascript functions than Java.

Link to comment
Share on other sites

 

What are you stuck with right now? Perhaps I can help.

 

Example on what you can do with the armour. Changing the GetPercent fn through the character instance.

local inst.components.armour:old_GetPercent = inst.components.armour.GetPercentinst.components.armour:GetPercent = function(amount)    amount = amount/2    return inst.components.armour:old_GetPercent(amount)end

Aside from your armor is named differently from mine, I see what your doing now.

 

your example is storing the old GetPercent function from armor into a function variable, then your creating a new version of the GetPercent function that would happen instead anytime it gets called, which after it does what it does, it returns the old original version of the function with the adjusted amount.

 

I can see how this would help in compatibility.  If multiple mods did this at once, they would basically just create a stack on top of each other, one would have the function do this, then another would have it do that, all in the order of when it loads in.  I probably worded that all wrong but I see whats happening.

 

So if I were to guess this right, your example there would have the GetPercent function always return half of the armors actual percentage, instead of it's full actual percentage.  And I'm guessing that this causes this to happen everytime GetPercent is called by anything.

 

Basically as it is without any conditional filtering, any mod that uses GetPercent would still work, but the numbers would be adjusted.

 

I'll try it myself and post it here.

Link to comment
Share on other sites

Aside from your armor is named differently from mine, I see what your doing now.

Whoops, sorry, haha. Fixed that.

 

For the rest, yup, that's it.

 

Edit: Upon further inspection, the amount parameter in Armor:GetPercent doesn't do anything. The code I provided won't do anything.

 

Also, I realized I didn't clarify, the "inst" refers to the armor's instance. Not the player's instance. Armors have the armour component, players do not.

You can access the armor's instance through the SetOnEquip and SetOnUnequip functions. More info on those here.

 

Edit 2: Sorry. Get the instance of the armor using this.

player_instance.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
Link to comment
Share on other sites

Okay, but lets say I wanted to do what you were essentially trying to do, where would I put those exactly?  Like what file, which part, should it be in a function or by itself.

 

Edit: Along with that, let me basically just state the current goal of what I'm looking for.

 

I want to get it so that when my character is wearing particular types of armor (Which I will store in a table) when damage is taken, the absorbed damage will be altered, and the durability lost from the armor will be altered.

 

For example, if my character is wearing a grass suit (which has 225 health and 60% absorption) and my character takes 100 damage from an attack, if my character adjusted the grass suit to only absorb 50% and caused it to lose durability 20% faster, then 50% of the 100 damage would get absorbed, which would be 50 damage towards the armor, but before it drains the durability, the damage would be amplified by 20% making the armor take 60 damage instead of 50.

 

Thats essentially what I'm looking to do right now, then i'll make adjustments after I've figured the process out.

Link to comment
Share on other sites

@Zackreaver That depends on your mod's design. In this case, you want it to only work with your character, so it would ideally be in your character's lua file.

local armor_on = function(armor)-- Save the old armor functions and-- replace them with your ownendlocal armor_off = function(armor)-- Restore old armor functions hereendlocal function isArmor(data)	return (data.eslot == EQUIPSLOTS.BODY) and (data.item.components.armor)endlocal OnEquip = function(self, data)	if isArmor(data) then		armor_on(data.item)	endendlocal OnUnequip = function(self, data)	if isArmor(data) then		armor_off(data.item)	endend-- ...-- In your character create fn-- inst refers to player instance-- These are fired by the inventory component, not the armor-- The ones fired by armor are not sent to the playerinst:ListenForEvent("equip", OnEquip)inst:ListenForEvent("unequip", OnUnequip)

Theoretical code, untested.

 

Edit: Regarding your edit, you should be able to accomplish that using the code above. Look through the armor component ("..\scripts\components\armor.lua") to see what you can mess with. Hint: TakeDamage function.

 

Edit 2: You'll notice that it also calls an ontakedamage function, which you can set using armour_inst.ontakedamage instead of modifying the TakeDamage function itself.

 

Edit 3: Example, extending code above.

local armor_on = function(armor)    armor.ontakedamage = function(inst, damage_amount, absorbed, leftover)        -- ...    endend local armor_off = function(armor)    armor.ontakedamage = nilend-- ...

Edit 4: Fixed parameters of OnEquip and OnUnequip.

 

Link to comment
Share on other sites

Okay your examples helps me out a bit.  I'm aware of the armor.lua and it's available functions, I'm trying to figure out a way to interact with them to get my desired results.

 

 

I can tell from what I'm reading that I can modify pre-existing functions when they are called, is there a way I can call local variables from armor that way too?  For example if I wanted to use the local variables condition and maxcondition, for reference and adjustment am I capable of it?  Or is it impossible since it's a local variable.  If it is impossible, what alternative could I do?  If any?

Link to comment
Share on other sites

@Zackreaver

You can not access local variables unless the module exposes a function to do so.

Elements of "self", such as "condition" and "maxcondition", are not the same as local variables. You can modify and access them just as you would for a basic table's elements.

armor_inst.maxcondition = armor_inst.maxcondition + 5print(armor_inst.maxcondition)

Edit: More on Lua Scope

Link to comment
Share on other sites

Okay I have some things working now for the armor, I have a couple issues with how I'm handling armor so I wanna see if I can go about it another way.

 

 

My first method is adjusting the armor when it gets equipped, but when I unequip the armor how does my code know where it went?  I need to readjust it back to it's original values when it gets unequipped from my character.

 

The "unequip" event works but I have no way of telling where the item went after this.

 

Edit: I surprise myself sometimes, I found the answer to my own question.

 

I tied an "unequipped" event listener to the armor itself when it gets equipped, then the moment it gets unequipped, the listener fires a function which resets the item and removes the listener.  I'm gonna test it to see how well it's working.

Link to comment
Share on other sites

@Zackreaver

Hmm. I don't understand the issue, why would you need to know where it went after that?

I provided code on how you can change it back to normal when unequipped, the armor_off function is given the armor's instance as a parameter. You can use that to reset the armor back to normal. After that, why would you need to keep a reference to it or know where (presumably, in the world) it is?

 

Flow of unequip:

  • Event unequip fired from inventory component to player instance
  • Event listener passes data from event to OnUnequip fn
  • OnUnequip fn checks if the data's item is an armor, then passes the item to armor_off fn
  • armor_off fn now has the armor instance which has been unequipped
Link to comment
Share on other sites

 

@Zackreaver

Hmm. I don't understand the issue, why would you need to know where it went after that?

I provided code on how you can change it back to normal when unequipped, the armor_off function is given the armor's instance as a parameter. You can use that to reset the armor back to normal. After that, why would you need to keep a reference to it or know where (presumably, in the world) it is?

 

Flow of unequip:

  • Event unequip fired from inventory component to player instance
  •  
  • Event listener passes data from event to OnUnequip fn
  •  
  • OnUnequip fn checks if the data's item is an armor, then passes the item to armor_off fn
  •  
  • armor_off fn now has the armor instance which has been unequipped

I actually went with a different method of approaching the problem, and you must have been writing the response as I was in the middle of editing my previous post, I found a solution thats working pretty good so far.

 

With the different method I was using I was editing the armor's values upon being equipped.  But with the "unequip" event it triggers when my character does the act of unequipping something, problem is when the code is running, the armors no longer in it's original slot, so I couldn't reference it there.

 

But I found an alternative to it.

local function resetitem(inst)	print("Item Unequipped Event")	if inst then		print(inst.prefab.." is about to be examined for reset")		if checkformatch(inst.prefab,weak_armor) then			inst.components.armor.condition = inst.components.armor.condition * 1.25			print(inst.prefab.." Condition = "..inst.components.armor.condition)			inst.components.armor.maxcondition = inst.components.armor.maxcondition * 1.25			print(inst.prefab.." Max Condition = "..inst.components.armor.maxcondition)			inst.components.armor.absorb_percent = inst.components.armor.absorb_percent + 0.1			print(inst.prefab.." Absorb Percent = "..inst.components.armor.absorb_percent)		elseif checkformatch(inst.prefab,strong_armor) then			inst.components.armor.condition = inst.components.armor.condition * (2 / 3)			print(inst.prefab.." Condition = "..inst.components.armor.condition)			inst.components.armor.maxcondition = inst.components.armor.maxcondition * (2 / 3)			print(inst.prefab.." Max Condition = "..inst.components.armor.maxcondition)			inst.components.armor.absorb_percent = inst.components.armor.absorb_percent - 0.05			print(inst.prefab.." Absorb Percent = "..inst.components.armor.absorb_percent)		else			--do nothing		end		inst:RemoveEventCallback("unequipped", resetitem)	endend	changeditem = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)	if changeditem then		print(changeditem.prefab.." is about to be examined")		if checkformatch(changeditem.prefab,weak_armor) then			changeditem.components.armor.condition = changeditem.components.armor.condition * 0.8			print(changeditem.prefab.." Condition = "..changeditem.components.armor.condition)			changeditem.components.armor.maxcondition = changeditem.components.armor.maxcondition * 0.8			print(changeditem.prefab.." Max Condition = "..changeditem.components.armor.maxcondition)			changeditem.components.armor.absorb_percent = changeditem.components.armor.absorb_percent - 0.1			print(changeditem.prefab.." Absorb Percent = "..changeditem.components.armor.absorb_percent)			changeditem:ListenForEvent("unequipped", resetitem)		elseif checkformatch(changeditem.prefab,strong_armor) then			changeditem.components.armor.condition = changeditem.components.armor.condition * 1.5			print(changeditem.prefab.." Condition = "..changeditem.components.armor.condition)			changeditem.components.armor.maxcondition = changeditem.components.armor.maxcondition * 1.5			print(changeditem.prefab.." Max Condition = "..changeditem.components.armor.maxcondition)			changeditem.components.armor.absorb_percent = changeditem.components.armor.absorb_percent + 0.05			print(changeditem.prefab.." Absorb Percent = "..changeditem.components.armor.absorb_percent)			changeditem:ListenForEvent("unequipped", resetitem)		else			--do nothing, this unnecessary, but I have it here in the event I think of something		end	end

it still has my debug print's in it for testing, but it's worked everytime I tried it.

 

My problem mostly happened because I'm still trying to figure out all my available options, but looking at the code you gave again I can see what you did that could have saved me the issue I had earlier.  I just didn't realize it was doing that.

 

For example, even though I'm using ListenForEvent("equip", fn) I have no idea what information is actually available for the function thats being fire off of it.  I didn't realize there was a way to reference the item that caused the event to trigger.  So I had to find the item other ways.

 

Which is where I got the problem for "unequip"

 

Edit: As it turns out I didn't need to adjust anything in the armor.lua to get what I needed done, adjusting the armor directly seems to be a pretty effective way of achieving the perk.

 

Also, I couldn't get your example code to work.  could you show me an example of an "unequip" event that adjusts the durability of the armor that gets unequipped?  Because outside of the workaround I made, I couldn't figure that part out.

Link to comment
Share on other sites

At any rate, Perk 2 complete!  (Adjustments might be necessary if problems arise)

 

Since the code I have for the 2nd perk is working fine for the most part I want to dive into the 3rd perk and learn something new.  Creating a unique item for my character.

 

The 3rd perk for my character will give him a starting item, which can be used to generate a message that signals when the hounds are going to attack next.  I already know how to grab this information from hounded, so all I really need to do is create the item and everything for it.

Link to comment
Share on other sites

Also, I couldn't get your example code to work.  could you show me an example of an "unequip" event that adjusts the durability of the armor that gets unequipped?  Because outside of the workaround I made, I couldn't figure that part out.
After testing it, I realized I made a slight mistake in the parameters of OnUnequip and OnEquip functions. The first param should be "self", and second is the "data". Sorry about that.
 
Tested working code using the procedure I mentioned previously:
local armor_off = function(armor)	print(armor.prefab, "unequipped")	armor.components.armor:SetPercent(0.5)endlocal function isArmor(data)	return (data.eslot == EQUIPSLOTS.BODY) and (data.item.components.armor)endlocal OnUnequip = function(self, data)	if isArmor(data) then		armor_off(data.item)	endendAddSimPostInit(function(inst)	inst:ListenForEvent("unequip", OnUnequip)end)
 
all I really need to do is create the item and everything for it.

Tutorial to character/item mods

Sample mods (see the prefab mod within, you can use it as a base)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...