Add skill experience

Users who are viewing this thread

I am encountering a null reference exception while attempting a simple test to add experience to the player's skills. The exception occurs when AddSkillXp() is called and since this is part of the game's native code I don't know how to investigate further. Does anyone know why the code below fails and can anyone provide any information at all on how to mod experience and character development using only custom DLLs or XMLs, without altering native game files?

C#:
public override void OnMissileHit(Agent attacker, Agent victim, bool isCanceled)
{
    if (attacker != null && attacker.IsHero)
    {
        //Boost crossbow xp for every missile hit.
        SkillObject xSkill = new SkillObject("Crossbow");
        CharacterObject xChar = (CharacterObject)attacker.Character;
        xChar.HeroObject.AddSkillXp(xSkill, 10000f);
        InformationManager.DisplayMessage(new InformationMessage("Crossbow XP gained."));
    }
}

(The code is implemented in a custom MissionBehaviour class.)
 
Solution
I would assume it's because you are creating a new SkillObject (and using it without calling Initialize).
You should use DefaultSkills.Crossbow, you really should not be creating a new SkillObject unless you are making a new skill. Also you don't check if the missile was from a crossbow, it could have been a thrown weapon or an arrow causing OnMissileHit to trigger, simply checking the attackers equipped weapons should work.
I would assume it's because you are creating a new SkillObject (and using it without calling Initialize).
You should use DefaultSkills.Crossbow, you really should not be creating a new SkillObject unless you are making a new skill. Also you don't check if the missile was from a crossbow, it could have been a thrown weapon or an arrow causing OnMissileHit to trigger, simply checking the attackers equipped weapons should work.
 
Upvote 0
Solution
Thank you for your response. I wasn't able to look into it right away because the red square of death bug had rendered the game unplayable for me, but it's fixed now and you are right about using the DefaultSkills class. The rest of it misses the point a bit but I appreciate the effort for more feedback.

My initial implementation was purely a simple test intended to add experience to a skill, nothing more and nothing less. I used the OnMissileHit event because it allowed me to trigger my code when desired, so I could step through and explore the outcomes of different methods of altering character skills, attributes and experience. Currently I have it set up so that the player's entire clan gain experience proportional to their current skill level, in all skills with each hour that passes on the campaign map. This is influenced by their learning rate and a scalar variable to control the overall progression rate. I've done this just to play around with different perks, without the monstrous grind associated with doing this in vanilla.

Ultimately I want remove the passive XP gain over time (mentioned above) and mod character development so that it's vanilla except that a character's learning rate is calculated:
Scalar * AttributeLevel * FocusPoints

So for example a character with 2 points in Vigour and 3 points in One Handed would have a learning rate for One Handed of:
Scalar * 2 * 3

Where Scalar would be a variable the player could set with a slider in the game options. Ideally this slider would only be available when starting a new game because I think it may feel like cheating to be able to change it at will after the game has started. A hard cap of perhaps 300 would also need to be introduced, as i don't want learning rate to be affected by any other factors such as current character and skill level.

Under this system the player could level all skills to a fixed maximum provided they had at least one point in each attribute and one focus point in each skill. Investing more points would of course increase the progression rate of a skill but it would not affect the maximum level attainable.

This seems more fun to me than having the maximum level achievable for a skill determined by the way a player has spent their points.
 
Upvote 0
Back
Top Bottom