Page 1 of 2

Catchable tiny_rats

Posted: Sun Oct 26, 2014 6:54 pm
by JKos
Just wanted to share this. This simple object definition makes tiny_rat-entities catchable by mouse click.

Code: Select all

defineObject{
   name = "tiny_rat",
   baseObject = "tiny_rat",
   components = {
	{ 
		class="Clickable",
		onClick=function(self)
			local item = getMouseItem()
			if item then
				hudPrint("You can't catch a rat with that junk in your hand")
				return
			end
			self.go:destroy()
			setMouseItem(spawn('rat_shank').item)
		end
	}
   }
}
This new component system gives so much possibilities.

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 6:59 pm
by NutJob
I agree, I can't wait to make Rope go UP! =)

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 7:05 pm
by cromcrom
Thanks for sharing, it's great ^^

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 7:16 pm
by JKos
Thanks. Updated the code so that you can't catch a rat if you have something selected as a "mouseitem". Previous version was destroying the current mouseitem.

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 7:27 pm
by Drakkan
wonderfull ! thanks for sharing :D

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 7:32 pm
by Skuggasveinn
This is good :D

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 8:42 pm
by cromcrom
Anybody got a champion/party:getStat(dexterity) kind of stuff working ? Because in a typical "Lost continent" fashion, the player will make a dex check, get some food if he succeeds, and a tiny amount of exp if he fails. Rat will disappear in both case (to prevent exploit)...

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 8:43 pm
by NutJob
cromcrom wrote:Anybody got a champion/party:getStat(dexterity) kind of stuff working ? Because in a typical "Lost continent" fashion, the player will make a dex check, get some food if he succeeds, and a tiny amount of exp if he fails. Rat will disappear in both case (to prevent exploit)...
Nope, I tried variations for a few hours, no luck.

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 9:35 pm
by cromcrom
So did I , with something like that

Code: Select all

function getPartyBestStat()
	local finalStat = 0 ; local p = party.party;
	for i = 1,4 do
		c = p:getChampion(i)
		if c:getEnabled() and c:isAlive() and c:getStat("dexterity") > finalStat 
			then finalStat = c:getStat("dexterity") 
		end
	end	
	hudPrint(finalStat)
	return finalStat
end
but that getStat doesn't seem to work anymore...

Re: Catchable tiny_rats

Posted: Sun Oct 26, 2014 9:58 pm
by cromcrom
Well, I added a little randomness. Just to have things more random and interactive, again, in a typical Lost Continent way :-). Next improvement will ba with adding a hunting skill...

Code: Select all

defineObject{
   name = "tiny_rat",
   baseObject = "tiny_rat",
   components = {
   { 
      class="Clickable",
      onClick=function(self)
         local item = getMouseItem()
		 local ratXP = 5
         if item then
            hudPrint("You can't catch a rat with that junk in your hand")
            return
         end
		 if math.random()<0.3 then
			 self.go:destroy()
			 setMouseItem(spawn('rat_shank').item)
			 hudPrint("Good Job ! Gotcha !")
		 else
			 hudPrint("Crap, missed it, better luck next time.")		 
			 self.go:destroy()
			 hudPrint("Aw well, at least I got"..ratXP.."XPs.")				 
			for n=1,4  do
				party.party:getChampion(n):gainExp(ratXP)
			end
         end
	 end
   }
  }
 }