Custom Leveling & XP Rewards
Posted: Fri Oct 26, 2012 6:38 am
Hello modders! I've lurked this forum too long, so here's some of my contribution 
I'm relatively new to programming, and lua has been really fun to work with so far.
This is a custom leveling script I made for the purpose of having control over skill point distribution for my party members. It gives a character +1 to all skills on level up and 2 points for the player to invest. I did this because I wanted classes to be able to have some diversity in skills and not feel entirely "locked in" to one skill.
objects.lua
And the script itself.
custom_leveling
Champions are awarded +4 skill points in the hard code, so you'll need to add or subtract from there.
I also made a custom EXP system that only cares if the monster dies, and not who hit the monster. This takes a little bit of extra effort because you'll need a new monster definition and not a cloneObject of it.
I added a roll for 70-100% of the XP award so characters level at slightly different rates. I deleted the "exp = " in monster definitions since that uses the hard coded XP system. Here is an example snail monster for extra clarity.
monsters.lua
Let me know if you find these useful!
I'm relatively new to programming, and lua has been really fun to work with so far.
This is a custom leveling script I made for the purpose of having control over skill point distribution for my party members. It gives a character +1 to all skills on level up and 2 points for the player to invest. I did this because I wanted classes to be able to have some diversity in skills and not feel entirely "locked in" to one skill.
objects.lua
SpoilerShow
Code: Select all
cloneObject
{
name = "party",
baseObject = "party",
onLevelUp = function()
custom_leveling.customLevelUp()
end,
}custom_leveling
SpoilerShow
Code: Select all
-- custom leveling script
nextLevel1 = party:getChampion(1):getLevel() + 1
nextLevel2 = party:getChampion(2):getLevel() + 1
nextLevel3 = party:getChampion(3):getLevel() + 1
nextLevel4 = party:getChampion(4):getLevel() + 1
function customLevelUp()
for i = 1,4 do
ordinal = party:getChampion(i):getOrdinal()
if ordinal == 1 then
currentLevel = party:getChampion(i):getLevel()
if currentLevel == nextLevel1 then
nextLevel1 = nextLevel1 + 1
if party:getChampion(i):getClass() == "Fighter" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("maces", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("athletics", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
end
if party:getChampion(i):getClass() == "Rogue" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("daggers", 1, true)
party:getChampion(i):trainSkill("assassination", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
party:getChampion(i):trainSkill("dodge", 1, true)
party:getChampion(i):trainSkill("missile_weapons", 1, true)
party:getChampion(i):trainSkill("throwing_weapons", 1, true)
end
if party:getChampion(i):getClass() == "Mage" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
party:getChampion(i):trainSkill("ice_magic", 1, true)
party:getChampion(i):trainSkill("spellcraft", 1, true)
party:getChampion(i):trainSkill("staves", 1, true)
end
if party:getChampion(i):getClass() == "Ranger" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
end
end
end
if ordinal == 2 then
currentLevel = party:getChampion(i):getLevel()
if currentLevel == nextLevel2 then
nextLevel2 = nextLevel2 + 1
if party:getChampion(i):getClass() == "Fighter" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("maces", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("athletics", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
end
if party:getChampion(i):getClass() == "Rogue" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("daggers", 1, true)
party:getChampion(i):trainSkill("assassination", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
party:getChampion(i):trainSkill("dodge", 1, true)
party:getChampion(i):trainSkill("missile_weapons", 1, true)
party:getChampion(i):trainSkill("throwing_weapons", 1, true)
end
if party:getChampion(i):getClass() == "Mage" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
party:getChampion(i):trainSkill("ice_magic", 1, true)
party:getChampion(i):trainSkill("spellcraft", 1, true)
party:getChampion(i):trainSkill("staves", 1, true)
end
if party:getChampion(i):getClass() == "Ranger" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
end
end
end
if ordinal == 3 then
currentLevel = party:getChampion(i):getLevel()
if currentLevel == nextLevel3 then
nextLevel3 = nextLevel3 + 1
if party:getChampion(i):getClass() == "Fighter" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("maces", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("athletics", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
end
if party:getChampion(i):getClass() == "Rogue" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("daggers", 1, true)
party:getChampion(i):trainSkill("assassination", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
party:getChampion(i):trainSkill("dodge", 1, true)
party:getChampion(i):trainSkill("missile_weapons", 1, true)
party:getChampion(i):trainSkill("throwing_weapons", 1, true)
end
if party:getChampion(i):getClass() == "Mage" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
party:getChampion(i):trainSkill("ice_magic", 1, true)
party:getChampion(i):trainSkill("spellcraft", 1, true)
party:getChampion(i):trainSkill("staves", 1, true)
end
if party:getChampion(i):getClass() == "Ranger" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
end
end
end
if ordinal == 4 then
currentLevel = party:getChampion(i):getLevel()
if currentLevel == nextLevel4 then
nextLevel4 = nextLevel4 + 1
if party:getChampion(i):getClass() == "Fighter" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("maces", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("athletics", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
end
if party:getChampion(i):getClass() == "Rogue" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("daggers", 1, true)
party:getChampion(i):trainSkill("assassination", 1, true)
party:getChampion(i):trainSkill("unarmed_combat", 1, true)
party:getChampion(i):trainSkill("dodge", 1, true)
party:getChampion(i):trainSkill("missile_weapons", 1, true)
party:getChampion(i):trainSkill("throwing_weapons", 1, true)
end
if party:getChampion(i):getClass() == "Mage" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
party:getChampion(i):trainSkill("ice_magic", 1, true)
party:getChampion(i):trainSkill("spellcraft", 1, true)
party:getChampion(i):trainSkill("staves", 1, true)
end
if party:getChampion(i):getClass() == "Ranger" then
party:getChampion(i):addSkillPoints(-2)
party:getChampion(i):trainSkill("swords", 1, true)
party:getChampion(i):trainSkill("axes", 1, true)
party:getChampion(i):trainSkill("armors", 1, true)
party:getChampion(i):trainSkill("air_magic", 1, true)
party:getChampion(i):trainSkill("earth_magic", 1, true)
party:getChampion(i):trainSkill("fire_magic", 1, true)
end
end
end
end
end
I also made a custom EXP system that only cares if the monster dies, and not who hit the monster. This takes a little bit of extra effort because you'll need a new monster definition and not a cloneObject of it.
SpoilerShow
Code: Select all
onDie = function()
-- exp override
local xp = 75
hudPrint("+" .. xp .. " XP")
for i = 1,4 do
rollExp = math.random(70, 100) * 0.01
party:getChampion(i):gainExp(xp * rollExp)
end
end,monsters.lua
SpoilerShow
Code: Select all
defineObject
{
name = "snail",
class = "Monster",
model = "assets/models/monsters/snail.fbx",
meshName = "snail_mesh",
animations = {
idle = "assets/animations/monsters/snail/snail_idle.fbx",
moveForward = "assets/animations/monsters/snail/snail_walk.fbx",
turnLeft = "assets/animations/monsters/snail/snail_turn_left.fbx",
turnRight = "assets/animations/monsters/snail/snail_turn_right.fbx",
attack = "assets/animations/monsters/snail/snail_attack.fbx",
getHitFrontLeft = "assets/animations/monsters/snail/snail_get_hit_front_left.fbx",
getHitFrontRight = "assets/animations/monsters/snail/snail_get_hit_front_right.fbx",
getHitBack = "assets/animations/monsters/snail/snail_get_hit_back.fbx",
getHitLeft = "assets/animations/monsters/snail/snail_get_hit_left.fbx",
getHitRight = "assets/animations/monsters/snail/snail_get_hit_right.fbx",
fall = "assets/animations/monsters/snail/snail_get_hit_front_left.fbx",
},
moveSound = "snail_walk",
attackSound = "snail_attack",
hitSound = "snail_hit",
dieSound = "snail_die",
hitEffect = "hit_goo",
turnAnimSpeed = 1.25,
capsuleHeight = 0.2,
capsuleRadius = 0.7,
health = 110,
sight = 2.5,
attackPower = 9,
accuracy = 0,
protection = 0,
evasion = -80,
movementCoolDown = 4,
coolDown = {0.5, 4},
noRecoilInterval = {0.2, 0.8},
lootDrop = {90, "snail_slice"},
brain = "Melee",
onDie = function()
-- exp override
local xp = 75
hudPrint("+" .. xp .. " XP")
for i = 1,4 do
rollExp = math.random(70, 100) * 0.01
party:getChampion(i):gainExp(xp * rollExp)
end
end,
}