sucking experience monster script help - SOLVED

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

sucking experience monster script help - SOLVED

Post by Drakkan »

could somebody please help me to script monster which will decrease experience on each sucesfull hit ? I think some onHit or onDealdamage hook for monster attack and regular gain exp with minus sign for damaged champion should work ?
Last edited by Drakkan on Wed Dec 24, 2014 12:33 am, edited 1 time in total.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Isaac
Posts: 3189
Joined: Fri Mar 02, 2012 10:02 pm

Re: sucking experience monster script help pls

Post by Isaac »

Example monster definition:

Code: Select all

defineObject{
	name = "life_leech",
	baseObject = "giant_snake",
	components = {

				{
			class = "MonsterAttack",
			name = "basicAttack",
			attackPower = 25,
			accuracy = 15,
			cooldown = 4,
			sound = "snake_attack",
			causeCondition = "paralyzed",
			conditionChance = 20,

			onDealDamage= function(self, champion, damage)
								local XPattackDamage = 100 -- How much XP damage the monster does.
								local pronoun = {["male"] = "He", ["female"] = "She"}
								if drainExp.script.loseExp(champion, -XPattackDamage) then
								hudPrint("") hudPrint("") hudPrint("")
									hudPrint(champion:getName().." feels weakened by the attack!")
									hudPrint(pronoun[champion:getSex()].." has lost "..XPattackDamage.." experience!")
									playSound("scramble_writer")
								end
								return true
							end,
		},
	},
}
Script Object: (name it drainExp)

Code: Select all

    --script name: drainExp
    function _minimumXP(level)
		local XPtable = {0,1000,3000,6000,10000,15000,21000,28000,36000,45000,55000,
					75000,100000,150000,200000,250000,300000,400000,500000,1000000}
		if level < 20 then
		   return XPtable[level]
		else
		   return level * 1000000
		end
	end

    function _adjustIfHuman(champion, amount)
		   if champion:hasTrait("human") then
			  amount = amount * 0.91
		   end
		   return amount
	end 
	        
    function loseExp(champion, amount)
       amount = _adjustIfHuman(champion, amount)
       local currentLevel = champion:getLevel()
       local currentExp = champion:getExp()
       local minimum = _minimumXP(currentLevel)
       if currentExp > minimum then
             if currentExp + amount >= minimum then
                champion:gainExp(amount)
                return true
             else
                champion:gainExp((currentExp - minimum)*-1)   
                champion:gainExp(_adjustIfHuman(champion, (minimum - champion:getExp())))   
                return true
             end   
       end   
       return false
    end
https://www.dropbox.com/s/84cn0jgyylkhb ... h.avi?dl=0
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: sucking experience monster script help pls

Post by Drakkan »

Isaac wrote:Example monster definition:

Code: Select all

defineObject{
	name = "life_leech",
	baseObject = "giant_snake",
	components = {

				{
			class = "MonsterAttack",
			name = "basicAttack",
			attackPower = 25,
			accuracy = 15,
			cooldown = 4,
			sound = "snake_attack",
			causeCondition = "paralyzed",
			conditionChance = 20,

			onDealDamage= function(self, champion, damage)
								local XPattackDamage = 100 -- How much XP damage the monster does.
								local pronoun = {["male"] = "He", ["female"] = "She"}
								if drainExp.script.loseExp(champion, -XPattackDamage) then
								hudPrint("") hudPrint("") hudPrint("")
									hudPrint(champion:getName().." feels weakened by the attack!")
									hudPrint(pronoun[champion:getSex()].." has lost "..XPattackDamage.." experience!")
									playSound("scramble_writer")
								end
								return true
							end,
		},
	},
}
Script Object: (name it drainExp)

Code: Select all

    --script name: drainExp
    function _minimumXP(level)
		local XPtable = {0,1000,3000,6000,10000,15000,21000,28000,36000,45000,55000,
					75000,100000,150000,200000,250000,300000,400000,500000,1000000}
		if level < 20 then
		   return XPtable[level]
		else
		   return level * 1000000
		end
	end

    function _adjustIfHuman(champion, amount)
		   if champion:hasTrait("human") then
			  amount = amount * 0.91
		   end
		   return amount
	end 
	        
    function loseExp(champion, amount)
       amount = _adjustIfHuman(champion, amount)
       local currentLevel = champion:getLevel()
       local currentExp = champion:getExp()
       local minimum = _minimumXP(currentLevel)
       if currentExp > minimum then
             if currentExp + amount >= minimum then
                champion:gainExp(amount)
                return true
             else
                champion:gainExp((currentExp - minimum)*-1)   
                champion:gainExp(_adjustIfHuman(champion, (minimum - champion:getExp())))   
                return true
             end   
       end   
       return false
    end
https://www.dropbox.com/s/84cn0jgyylkhb ... h.avi?dl=0
working perfectly as far as I have tried. thanks Isaac, this is big !
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply