Connecting a level system to prefab drops

Vahalla

Member
So I would like an exp bag to drop when n enemy dies, I made the prefab, I have a leveling script, which works, the problem is connecting the fuction to this controller, I also thought maybe on the enemy dying, although I thought a bag would be better that way I can use it , I also thought about maybe making an item definition, and maybe do an on click event on the icon maybe idk I have tried many roads to failure any suggestions would be great
Also how to I give the player a base damage and defense with this controller, I noticed it is all really based on whe weapons equipped including the body as a weapon
 
You could create a custom ObjectPickup which would increment your exp using your leveling system when picked up. In the demo, HealthPickup is an example of a simple custom ObjectPickup - it uses TriggerEnter to increase the character's health using Health.Heal. So you could do something similar, i.e. create a ObjectPickup subclass and use TriggerEnter to call your own leveling system's logic.

For "base damage" I assume you mean being able to increase the damage of all items by some kind of attribute. One simple way to do this could be to directly modify the DamageAmount property of MeleeWeapon/ShootableWeapon items during runtime. E.g. you could have a script that increases them based on an attribute of the character's. All you need to do is get a reference to the MeleeWeapon/ShootableWeapon component, then you can modify DamageAmount directly.
 
Ok so can I give a damage attribute, and somehow base that amount increase in the modify attribute in the inventory system like you did with the assault rifle in the video, when you created a damage float?
 
Sorry that was not clear
So in the attribute manager of ucc
Create a damage stat
Then is there a way to link that amount to the uis, like a main category that is a parent of all weapons, that can control all the float damage as in the video tutorial, then something like
Var damage= GetComonent<AttributeManager>().GetAttribute(“Damage”);
Var adddamage= GetComponent<attributeModifier>”something “;
If(!onlevelup)//a bool
damage.MaxValue= damage.Value;
damage.Value+= 100 ;
//what ever gain one wants
adddamage.Value = damage.Value + adddamage.Value;
?
 
I was thinking you could just directly modify ShootableWeapon.DamageAmount:

C#:
ShootableWeapon shootableWeapon; // get this reference somehow, e.g. as a public in the inspector, or by looping through all items' itemactions
var damageAttribute = AttributeManager.GetAttribute("MyDamageAttribute");
shootableWeapon.DamageAmount = 10 + damageAttribute;

The same approach could be taken for MeleeWeapon, etc.
 
Yeah I accessed the float I created in the inventory manager, under the attribute part, it changes but does not seem to update to the weapons, when I stop the game , it shows in the parent category it changes, I inherited all the way down to the definition, when I click on the attribute float it changes value , is there a way to call an update to the value
 
Ah you're using UIS. Well that could be a different approach then. I was assuming using the base UCC inventory system and modifying the DamageAmount properties directly.

Moving this to the UIS integration forum.
 
No worries, I made a parent category that I assigned an attribute to as a float, and made my weapons category a child of it, so it works just need to know how to get it to update the value at runtime, since it updates the override value , just does not add the extra damage it stays at the starting value
 
Could you show What attribute you are changing?
It is possible you are trying to modify the wrong attribute.
Check out the documentation example here:

You should get the unique reference to the item within your inventory. There are many ways you can go about that. whether it is by checking the specific slot inside an item collection or by selecting it in the UI and get a reference to it in an ItemAction

You can always check the Inventory Inspector to view your item attributes at runtime. That will at least tell you if you are actually changing the correct value. (Do not change the attribute values in the inspector at runtime, that won't update binding values)
 
I got the item category then the item attributes then the value then I set the override value it show correctly in the editor just does not update until I stop the game
 
You shouldn not change the value on the item cateogry. You should change it on the Item itself.
Item Cateogries and Item Definitions are Scriptable Objects, if you change them at runtime, the value will persist even after playmode. We strongly advise people not to change ItemCategory and ItemDefinition attributes at runtime unless they know exactly what they are doing.

Instead of changing the attribute on the ItemCategory you should do it on the Item, which is not a Scriptable Object, it is a simple object. So your first step should be to get the item from your Inventory, then you can start editing its Item Attributes at runtime.

If you are struggling to understand the difference between Item, ItemDefinition and ItemCategory make sure to read the documentation and watch the introductary video tutorials.
 
I have it all working by doing what I did and yes I know it stays even after runtime, I just change it back, my problem is it does not update the damage at all, I adjusted the binding as it was done in the video, is there an way to update it some how this is the last piece to the puzzle of having base stats that change on character level up, then I will do upgrades as you stated for individual weapons.
 
You are changing the override value on the ItemCategory (I strongly advise against it because it will cause you issues down the line, but if you are sure of what you are doing then I won't stop you).
The Items precompute their attribute values such that we don't have to recompute it every time we check for the value of an attribute. So to update your values on your items after changing it on the category you need to tell the item to recompute it's attribtue values.

Code:
item.ReevaluateAttributes();
if you want to get all the items in the system that has that itemcategory you can do:
Code:
var items = InventorySystemManager.ItemRegister.ItemsWithItemCategory(itemCategory,true)

Once again I want to reiterate that I advise against doing so. ItemCategory attribute values shouldn't be changed at runtime in my opinion. If you want to compute the damage using character and item stats, then you should compute it outside of the item. That's my opinion though, your solution might work for your game though
 
I tried it could not get to that fuction, as it is read only, it is ok I give up, I’m going to have to find another way to have base stats connect to the over all damage of every weapon, I’m surprised there are no base stats on characters , guess I will have to just make it to where they craft runes or better weapons to get more damage idk ?‍♂️
 
Ok so I have an idea not sure it work so is there a way to make an attribute in the attribute manager and call it’s value in the damage amount for all weapons?
 
Are you trying to change the damage you deal depending on your weapon and external stat or custom values?

If so I would recommend you have a look at the DamageProcessor. Its very new so there's room for improvement and there's not a lot of documentation on it, but it might help you achieve what you want.

Essentially it allows you to write your own custom code to compute damage. It's a scriptable object.

Here is an example of the custom Damage Processor for the AdventureKit project I am working on. It checks if that attack does a critical hit depending on the characters luck.
You won't have access to some of these classes so it won't compile in your project but at least it gives you an idea of how you can code your own custom Damage Processor.

Code:
using Opsive.Shared.Game;
using Opsive.StatSystem;
using Opsive.UltimateCharacterController.Traits.Damage;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "AdventureKitDamageProcessor", menuName = "Ultimate Character Controller/Damage Processors/Adventure Kit Damage Processor")]
public class AdventureKitDamageProcessor : DamageProcessor
{
    public class AdventureKitDamageData : DamageData
    {
        protected bool m_CriticalHit;

        public bool CriticalHit { get => m_CriticalHit; set => m_CriticalHit = value; }

        public override void Copy(DamageData damageData)
        {
            base.Copy(damageData);
            if (damageData is AdventureKitDamageData adventureKitDamageData) {
                m_CriticalHit = adventureKitDamageData.CriticalHit;
            }
        }
    }

    protected AdventureKitDamageData m_AdventureKitDamageData = new AdventureKitDamageData();
    
    public override void Process(IDamageTarget target, DamageData damageData)
    {
        m_AdventureKitDamageData.Copy(damageData);

        var startDamage = m_AdventureKitDamageData.Amount;
        
        var strength = m_AdventureKitDamageData.DamageOriginator.Owner.GetCachedComponent<ObjectStats>()?.GetStat("STR")?.Value ?? 0;
        var defense = m_AdventureKitDamageData.DamageTarget.Owner.GetCachedComponent<ObjectStats>()?.GetStat("DEF")?.Value ?? 0;
        
        var random = Random.Range(0.9f, 1.1f);
        
        m_AdventureKitDamageData.Amount += strength - defense;
        m_AdventureKitDamageData.Amount *= random;

        m_AdventureKitDamageData.CriticalHit = Random.value < 0.2f;

        if (m_AdventureKitDamageData.CriticalHit) {
            m_AdventureKitDamageData.Amount *= 2;
        }

        m_AdventureKitDamageData.UserData = m_AdventureKitDamageData.CriticalHit ? 1 : 0;

        m_AdventureKitDamageData.DamageTarget.Damage(m_AdventureKitDamageData);
    }
}

Then to set that Damage Processor you can set in on the Item Prefab.
1629974696486.png

As mentioned before this feature is very new so if you find anything wrong or if you have ideas to improve it do let us know. I hope that helps
 
Top