How to make NPC level up with the player?

A place to post your add ons and ideas for them

Moderator: Moderator

Post Reply
Message
Author
wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

How to make NPC level up with the player?

#1 Post by wuxiangjinxing »

It's lonely to fight in the infinite dungeon all by myself. So I would like to make some NPC followers. Currently I have been able to generate the NPC and let the player gain EXP when they kill monsters. However, I cannot figure out how to let them level up with the player, just like an alchemy golem.

I have found the code to false the golem to level up in Actor.lua:

-- Force levelup of the golem
if self.alchemy_golem then
self.alchemy_golem.max_level = self.max_level -- make sure golem can level up with master
self.alchemy_golem:forceLevelup(self.level)
end

However, I cannot figure out how to use the similiar strategy for those NPCs I made. So is it possible for you to teach me how to make it work? Thanks.

Crim, The Red Thunder
Sher'Tul Godslayer
Posts: 2000
Joined: Fri May 07, 2004 8:26 pm
Location: Nahgharash

Re: How to make NPC level up with the player?

#2 Post by Crim, The Red Thunder »

You should take a look at some of the for-sale allies in infinite farportal addon. Starkeep did this for some of his. Depending on the version you either got a static one, or one that leveled like golem. Not sure which ones have which version though. But it would give you code to copy over.
Currently playing under the name Aura of the Dawn 4 down, 227 to go!
Proud author of Orc Pit Restoration Project, Faction Allies, Dwarven Adventurer addons
SadistSquirrel wrote:DarkGod has two arms, one with an opened hand, one with a closed fist. You got the fist.

StarKeep
Uruivellas
Posts: 703
Joined: Sun Feb 03, 2013 12:29 am
Location: Turtlemire

Re: How to make NPC level up with the player?

#3 Post by StarKeep »

Unless I am really out of the loop with my own stuff, I've never applied leveling to companions.


For a quick and dirty solution:

Apply the attribute 'companion' to the npcs.

Superload Actor, and add the following code to actBase: (For examples on how to do this, check nearly any class addon out there.)

Code: Select all

if self and self.companion and self.summoner and self.summoner.level > self.level then
	self:forceLevelup(self.summoner.level)
end

Alternatively, if you like, I could go back and apply this to my old companions addon, and add support for ID into it.
<mex> have you heard the good word about archmage?
<mex> I'm here to tell you about your lord and savior shalore archmage
<mex> have you repented your bulwark sins yet?
<mex> cornac shall inherit the Eyal

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#4 Post by wuxiangjinxing »

StarKeep wrote:Unless I am really out of the loop with my own stuff, I've never applied leveling to companions.


For a quick and dirty solution:

Apply the attribute 'companion' to the npcs.

Superload Actor, and add the following code to actBase: (For examples on how to do this, check nearly any class addon out there.)

Code: Select all

if self and self.companion and self.summoner and self.summoner.level > self.level then
	self:forceLevelup(self.summoner.level)
end

Alternatively, if you like, I could go back and apply this to my old companions addon, and add support for ID into it.
Perfect, thanks a lot.

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#5 Post by wuxiangjinxing »

One more question, to add the attribute "companion" to the npc, shall I just add "companion = true" in the newEntity of that npc? Thanks.

StarKeep
Uruivellas
Posts: 703
Joined: Sun Feb 03, 2013 12:29 am
Location: Turtlemire

Re: How to make NPC level up with the player?

#6 Post by StarKeep »

Yep.
<mex> have you heard the good word about archmage?
<mex> I'm here to tell you about your lord and savior shalore archmage
<mex> have you repented your bulwark sins yet?
<mex> cornac shall inherit the Eyal

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#7 Post by wuxiangjinxing »

StarKeep wrote:Yep.
Well that does not work in my game. I did exactly what you teached me but the npc still cannot level up.

Can you update your old companion MOD and let me have an example? Thanks.

StarKeep
Uruivellas
Posts: 703
Joined: Sun Feb 03, 2013 12:29 am
Location: Turtlemire

Re: How to make NPC level up with the player?

#8 Post by StarKeep »

:oops: So used to dealing with summons for this kind of thing.

This worked correctly after testing:

Code: Select all

if self and self.companion and game.player.level > self.level then
	self:forceLevelup(game.player.level)
end

For insight as to why the first code didn't work, the code was based off my Tower Defense addon.
The issue is that the towers from that addon correctly think of the player as a summoner, so I could easily reference that.
For random companions, however, they had no summoner, and were in no way linked to you, so you instead just reach globally for the player's level.
<mex> have you heard the good word about archmage?
<mex> I'm here to tell you about your lord and savior shalore archmage
<mex> have you repented your bulwark sins yet?
<mex> cornac shall inherit the Eyal

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#9 Post by wuxiangjinxing »

StarKeep wrote::oops: So used to dealing with summons for this kind of thing.

This worked correctly after testing:

Code: Select all

if self and self.companion and game.player.level > self.level then
	self:forceLevelup(game.player.level)
end

For insight as to why the first code didn't work, the code was based off my Tower Defense addon.
The issue is that the towers from that addon correctly think of the player as a summoner, so I could easily reference that.
For random companions, however, they had no summoner, and were in no way linked to you, so you instead just reach globally for the player's level.
Thanks, I'm going to try that.

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#10 Post by wuxiangjinxing »

Unfortunately that does not work for me either, maybe I made some mistakes and I'm checking it.

This is what I did:

(1) Add the command "Companion = true" at the very end of the newEntity of the NPC

(2) in games/addons/MyMod/Overload/mod/class/Actor.lua, add the following commands at the beginning of function _M:actBase():

if self and self.companion and game.player.level > self.level then
self:forceLevelup(game.player.level)
end

However this does not work for me. Is there anything wrong?

StarKeep
Uruivellas
Posts: 703
Joined: Sun Feb 03, 2013 12:29 am
Location: Turtlemire

Re: How to make NPC level up with the player?

#11 Post by StarKeep »

Superload, not Overload.

Look to other addons for examples on how to do so.
<mex> have you heard the good word about archmage?
<mex> I'm here to tell you about your lord and savior shalore archmage
<mex> have you repented your bulwark sins yet?
<mex> cornac shall inherit the Eyal

wuxiangjinxing
Wayist
Posts: 29
Joined: Fri May 16, 2014 6:30 pm

Re: How to make NPC level up with the player?

#12 Post by wuxiangjinxing »

OK finally I solved the problem I had. Actually I set the level range of the NPC as (1 to game.player.level) in its newEntity. This caused the NPC to be limited.

In order to let NPC level up, I need to set the max_level of that NPC to either nil or game.player.max_level.

Thank you for all your help.

Post Reply