How to make NPC level up with the player?
Moderator: Moderator
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
How to make NPC level up with the player?
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.
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.
-
- 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?
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
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.
Re: How to make NPC level up with the player?
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.)
Alternatively, if you like, I could go back and apply this to my old companions addon, and add support for ID into it.
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
<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
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
Perfect, thanks a lot.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.
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
One more question, to add the attribute "companion" to the npc, shall I just add "companion = true" in the newEntity of that npc? Thanks.
Re: How to make NPC level up with the player?
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
<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
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
Well that does not work in my game. I did exactly what you teached me but the npc still cannot level up.StarKeep wrote:Yep.
Can you update your old companion MOD and let me have an example? Thanks.
Re: How to make NPC level up with the player?

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
<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
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
Thanks, I'm going to try that.StarKeep wrote: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.
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
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?
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?
Re: How to make NPC level up with the player?
Superload, not Overload.
Look to other addons for examples on how to do so.
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
<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
-
- Wayist
- Posts: 29
- Joined: Fri May 16, 2014 6:30 pm
Re: How to make NPC level up with the player?
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.
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.