Jump to content

Custom level system for custom character


Recommended Posts

Well i try to add level system for my character but it's not works i can't find the mistake i hope some one can help me here is the code

local function levelexp(inst, data)

	local max_exp = 999999999994650
	local level = math.min(inst.level, max_exp)
	
	local health_percent = inst.components.health:GetPercent()
	local sanity_percent = inst.components.sanity:GetPercent()
	local hunger_percent = inst.components.hunger:GetPercent()
	
	--level 0 (start)
if inst.level >0 and inst.level <=10 then
	inst.components.health.maxhealth = math.ceil (50)
	inst.components.hunger.maxhunger = math.ceil (50)
	inst.components.sanity.max = math.ceil (50)
	--level 1
elseif inst.level >10 and inst.level <=20 then
	inst.components.health.maxhealth = math.ceil (55)
	inst.components.hunger.maxhunger = math.ceil (55)
	inst.components.sanity.max = math.ceil (55)
    elseif inst.level >19 and inst.level <=20 then
	inst.components.talker:Say("Level Up! Well done! Level 1. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 2
elseif inst.level >20 and inst.level <=30 then
	inst.components.health.maxhealth = math.ceil (60)
	inst.components.hunger.maxhunger = math.ceil (60)
	inst.components.sanity.max = math.ceil (60)
	elseif inst.level >29 and inst.level <=30 then
	inst.components.talker:Say("Level Up! Well done! Level 2. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 3
elseif inst.level >30 and inst.level <=60 then
	inst.components.health.maxhealth = math.ceil (65)
	inst.components.hunger.maxhunger = math.ceil (65)
	inst.components.sanity.max = math.ceil (65)
	elseif inst.level >59 and inst.level <=60 then
	inst.components.talker:Say("Level Up! Well done! Level 3. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 4
elseif inst.level >60 and inst.level <=100 then
	inst.components.health.maxhealth = math.ceil (70)
	inst.components.hunger.maxhunger = math.ceil (70)
	inst.components.sanity.max = math.ceil (70)
	elseif inst.level >99 and inst.level <=100 then
	inst.components.talker:Say("Level Up! Well done! Level 4. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 5
elseif inst.level >100 and inst.level <=150 then
	inst.components.health.maxhealth = math.ceil (75)
	inst.components.hunger.maxhunger = math.ceil (75)
	inst.components.sanity.max = math.ceil (75)
	elseif inst.level >149 and inst.level <=150 then
	inst.components.talker:Say("Level Up! Well done! Level 5. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 6
elseif inst.level >150 and inst.level <=210 then
	inst.components.health.maxhealth = math.ceil (80)
	inst.components.hunger.maxhunger = math.ceil (80)
	inst.components.sanity.max = math.ceil (80)
	elseif inst.level >219 and inst.level <=210 then
	inst.components.talker:Say("Level Up! Well done! Level 6. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 7
elseif inst.level >210 and inst.level <=280 then
	inst.components.health.maxhealth = math.ceil (85)
	inst.components.hunger.maxhunger = math.ceil (85)
	inst.components.sanity.max = math.ceil (85)
	elseif inst.level >279 and inst.level <=280 then
	inst.components.talker:Say("Level Up! Well done! Level 7. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 8
elseif inst.level >280 and inst.level <=360 then
	inst.components.health.maxhealth = math.ceil (90)
	inst.components.hunger.maxhunger = math.ceil (90)
	inst.components.sanity.max = math.ceil (90)
	elseif inst.level >359 and inst.level <360 then
	inst.components.talker:Say("Level Up! Well done! Level 8. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 9
elseif inst.level >360 and inst.level <=450 then
	inst.components.health.maxhealth = math.ceil (95)
	inst.components.hunger.maxhunger = math.ceil (95)
	inst.components.sanity.max = math.ceil (95)
	elseif inst.level >449 and inst.level <=450 then
	inst.components.talker:Say("Level Up! Well done! Level 9. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 10
elseif inst.level >450 and inst.level <=550 then
	inst.components.health.maxhealth = math.ceil (100)
	inst.components.hunger.maxhunger = math.ceil (100)
	inst.components.sanity.max = math.ceil (100)
	elseif inst.level >549 and inst.level <=550 then
	inst.components.talker:Say("Sugoii (Nya~) demo mada aru (Nya~). Level Up 10. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 11
elseif inst.level >550 and inst.level <=660 then
	inst.components.health.maxhealth = math.ceil (110)
	inst.components.hunger.maxhunger = math.ceil (110)
	inst.components.sanity.max = math.ceil (110)
	elseif inst.level >659 and inst.level <=660 then
	inst.components.talker:Say("Level Up! Well done! Level 11. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 12
elseif inst.level >660 and inst.level <=780 then
	inst.components.health.maxhealth = math.ceil (120)
	inst.components.hunger.maxhunger = math.ceil (120)
	inst.components.sanity.max = math.ceil (120)
	elseif inst.level >779 and inst.level <=780 then
	inst.components.talker:Say("Level Up! Well done! Level 12. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 13
elseif inst.level >780 and inst.level <=910 then
	inst.components.health.maxhealth = math.ceil (130)
	inst.components.hunger.maxhunger = math.ceil (130)
	inst.components.sanity.max = math.ceil (130)
	elseif inst.level >909 and inst.level <=910 then
	inst.components.talker:Say("Level Up! Well done! Level 13. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 14
elseif inst.level >910 and inst.level <=1050 then
	inst.components.health.maxhealth = math.ceil (140)
	inst.components.hunger.maxhunger = math.ceil (140)
	inst.components.sanity.max = math.ceil (140)
	elseif inst.level >1049 and inst.level <=1050 then
	inst.components.talker:Say("Level Up! Well done! Level 14. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 15
elseif inst.level >1050 and inst.level <=1200 then
	inst.components.health.maxhealth = math.ceil (150)
	inst.components.hunger.maxhunger = math.ceil (150)
	inst.components.sanity.max = math.ceil (150)
	elseif inst.level >1199 and inst.level <=1200 then
	inst.components.talker:Say("Level Up! Well done! Level 15. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 16
elseif inst.level >1200 and inst.level <=1360 then
	inst.components.health.maxhealth = math.ceil (160)
	inst.components.hunger.maxhunger = math.ceil (150)
	inst.components.sanity.max = math.ceil (160)
	elseif inst.level >1359 and inst.level <=1360 then
	inst.components.talker:Say("Level Up! Well done! Level 16. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 17
elseif inst.level >1360 and inst.level <=1530 then
	inst.components.health.maxhealth = math.ceil (170)
	inst.components.hunger.maxhunger = math.ceil (170)
	inst.components.sanity.max = math.ceil (170)
	elseif inst.level >1529 and inst.level <=1530 then
	inst.components.talker:Say("Level Up! Well done! Level 17. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 18
elseif inst.level >1530 and inst.level <=1710 then
	inst.components.health.maxhealth = math.ceil (180)
	inst.components.hunger.maxhunger = math.ceil (180)
	inst.components.sanity.max = math.ceil (180)
	elseif inst.level >1709 and inst.level <=1710 then
	inst.components.talker:Say("Level Up! Well done! Level 18. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 19
elseif inst.level >1710 and inst.level <1900 then
	inst.components.health.maxhealth = math.ceil (190)
	inst.components.hunger.maxhunger = math.ceil (190)
	inst.components.sanity.max = math.ceil (190)
	elseif inst.level >1899 and inst.level <=1900 then
	inst.components.talker:Say("Level Up! Well done! Level 19. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 20
elseif inst.level >1900 and inst.level <=2100 then
	inst.components.health.maxhealth = math.ceil (200)
	inst.components.hunger.maxhunger = math.ceil (200)
	inst.components.sanity.max = math.ceil (200)
	elseif inst.level >2099 and inst.level <=2100 then
	inst.components.talker:Say("We come long way from the start. Level Up 20. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 21
elseif inst.level >2100 and inst.level <=2310 then
	inst.components.health.maxhealth = math.ceil (210)
	inst.components.hunger.maxhunger = math.ceil (210)
	inst.components.sanity.max = math.ceil (210)
	elseif inst.level >2309 and inst.level <=2310 then
	inst.components.talker:Say("Level Up! Well done! Level 21. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 22
elseif inst.level >2310 and inst.level <=2530 then
	inst.components.health.maxhealth = math.ceil (220)
	inst.components.hunger.maxhunger = math.ceil (220)
	inst.components.sanity.max = math.ceil (220)
	elseif inst.level >2529 and inst.level <=2530 then
	inst.components.talker:Say("Level Up! Well done! Level 22. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 23
elseif inst.level >2530 and inst.level <=2760 then
	inst.components.health.maxhealth = math.ceil (230)
	inst.components.hunger.maxhunger = math.ceil (230)
	inst.components.sanity.max = math.ceil (230)
	elseif inst.level >2759 and inst.level <=2760 then
	inst.components.talker:Say("Level Up! Well done! Level 23. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 24
elseif inst.level >2760 and inst.level <=3000 then
	inst.components.health.maxhealth = math.ceil (240)
	inst.components.hunger.maxhunger = math.ceil (240)
	inst.components.sanity.max = math.ceil (240)
	elseif inst.level >2999 and inst.level <=3000 then
	inst.components.talker:Say("Level Up! Well done! Level 24. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 25
elseif inst.level >3000 and inst.level <=3250 then
	inst.components.health.maxhealth = math.ceil (250)
	inst.components.hunger.maxhunger = math.ceil (250)
	inst.components.sanity.max = math.ceil (250)
	elseif inst.level >3249 and inst.level <=3250 then
	inst.components.talker:Say("Level Up! Well done! Level 25. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 26
elseif inst.level >3250 and inst.level <=3510 then
	inst.components.health.maxhealth = math.ceil (260)
	inst.components.hunger.maxhunger = math.ceil (260)
	inst.components.sanity.max = math.ceil (260)
	elseif inst.level >3509 and inst.level <=3510 then
	inst.components.talker:Say("Level Up! Well done! Level 26. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 27
elseif inst.level >3510 and inst.level <=3780 then
	inst.components.health.maxhealth = math.ceil (270)
	inst.components.hunger.maxhunger = math.ceil (270)
	inst.components.sanity.max = math.ceil (270)
	elseif inst.level >3779 and inst.level <=3780 then
	inst.components.talker:Say("Level Up! Well done! Level 27. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 28
elseif inst.level >3780 and inst.level <=4060 then
	inst.components.health.maxhealth = math.ceil (280)
	inst.components.hunger.maxhunger = math.ceil (280)
	inst.components.sanity.max = math.ceil (280)
	elseif inst.level >4059 and inst.level <=4060 then
	inst.components.talker:Say("Level Up! Well done! Level 28. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 29
elseif inst.level >4060 and inst.level <=4350 then
	inst.components.health.maxhealth = math.ceil (290)
	inst.components.hunger.maxhunger = math.ceil (290)
	inst.components.sanity.max = math.ceil (290)
	elseif inst.level >4349 and inst.level <=4350 then
	inst.components.talker:Say("Level Up! Well done! Level 29. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
	--level 30
elseif inst.level >=4350 and inst.level <=4650 then
	inst.components.health.maxhealth = math.ceil (300)
	inst.components.hunger.maxhunger = math.ceil (300)
	inst.components.sanity.max = math.ceil (300)
	elseif inst.level >4649 and inst.level <=4650 then
inst.components.talker:Say("Yeey! We did it! We reach the ultimate Level. Level Up 30. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/levelup")
end

	inst.components.health:SetPercent(health_percent)
	inst.components.hunger:SerPercent(hunger_percent)
	inst.components.sanity:SetPercent(sanity_percent)
end
	
local function onkill(inst, data)

	local victim = data.victim
	
	if (
		victim:HasTag("chester") or
		victim:HasTag("glommer") or
		victim:HasTag("catcoon") or
		victim:HasTag("hutch") or
		victim:HasTag("lavae_pet") 
	) then
	
	inst.level = inst.level - 50
	inst.components.talker:Say("Oh come on! Why i did that? I'm cursed now. Nya~")
end
	
	if (
		victim:HasTag("smallbird") or
		victim:HasTag("babybeefalo") or
		victim:HasTag("toddlerbeefalo") 
	) then
	
	inst.level = inst.level - 10
	inst.components.talker:Say("I feel bad about that. It was so cute. Nya~")
end
	if (
		victim:HasTag("pigman") or
		victim:HasTag("bunnyman") or
		victim:HasTag("rocky") 
	) then
	
	inst.level = inst.level - 5
	inst.components.talker:Say("Should i do that? I mean it feels bad. Nya~")
end
	
	if (
		victim:HasTag("butterfly") or
		victim:HasTag("crow") or
		victim:HasTag("robin") or
		victim:HasTag("robin_winter") or
		victim:HasTag("canary") or
	    victim:HasTag("rabbit") or
		victim:HasTag("mole") or
		victim:HasTag("grassgekko") or
		victim:HasTag("mandrake")
	) then
	
	inst.level = inst.level + 1
	inst.components.talker:Say("I can't be strong enought with that! Nya~")
end
	
	if (
		victim:HasTag("eyeplant") or
		victim:HasTag("bee") or
		victim:HasTag("spider") or
		victim:HasTag("frog") or
		victim:HasTag("batilisk") or
		victim:HasTag("mosquito") or
		victim:HasTag("deer") or
		victim:HasTag("deerantler") or
		victim:HasTag("perd") or
		victim:HasTag("monkey") or
		victim:HasTag("buzzard") or
		victim:HasTag("snurtle") 
	) then
	
	inst.level = inst.level + 2
	inst.components.talker:Say("That'll help to level up. But not much. Nya~")
end
	if (
		victim:HasTag("birchnutdrake") or
		victim:HasTag("killerbee") or
		victim:HasTag("tentacle") or
		victim:HasTag("tentacle_pillar") or
		victim:HasTag("spider_warrior") or
		victim:HasTag("teenbird") or
		victim:HasTag("little_walrus") or
		victim:HasTag("teenbeefalo") or
		victim:HasTag("penguin") or
		victim:HasTag("lightninggoat") or
		victim:HasTag("slurtle") 
	) then
	
	inst.level = inst.level + 3
	inst.components.talker:Say("Yeah, that'll help but i need more. Nya~")
end
	if (
		victim:HasTag("tallbird") or
		victim:HasTag("spider_spitter") or
		victim:HasTag("merm") or
		victim:HasTag("spider_hider") or
		victim:HasTag("spider_dropper") or
		victim:HasTag("pigguard") or
		victim:HasTag("koalefant_summer") or
		victim:HasTag("koalefant_winter") or
		victim:HasTag("beefalo") or
		victim:HasTag("walrus") 
	) then
	
	inst.level = inst.level + 5
	inst.components.talker:Say("Your soul makes me stronger. But still not enought. Nya~")
end
	if (
		victim:HasTag("hound") or
		victim:HasTag("firehound") or
		victim:HasTag("icehound") or
		victim:HasTag("knight") or
		victim:HasTag("rook") or
		victim:HasTag("bishop") or
		victim:HasTag("deer_red") or
		victim:HasTag("deer_blue") or
		victim:HasTag("lavae") or
		victim:HasTag("worm") or
		victim:HasTag("mossling") or
		victim:HasTag("beeguard") 
	) then
	
	inst.level = inst.level + 7
	inst.components.talker:Say("You were strong. And your soul will be stronger with me. Nya~")
end
	if (
		victim:HasTag("bishop_nightmare") or
		victim:HasTag("knight_nightmare") or
		victim:HasTag("rook_nightmare") or
		victim:HasTag("crawlinghorror") or
		victim:HasTag("crawlingnightmare") or
		victim:HasTag("shadow_knight") or
		victim:HasTag("shadow_bishop") or
		victim:HasTag("shadow_rook") or
		victim:HasTag("ghost") or
		victim:HasTag("werepig") or
		victim:HasTag("lureplant")
	) then
	
	inst.level = inst.level + 10
	inst.components.talker:Say("I can feel the power in my veins. Nya~")
end
	if (
		victim:HasTag("leif") or
		victim:HasTag("krampus") or
		victim:HasTag("warg") or
		victim:HasTag("spat") or
		victim:HasTag("deciduoustree") 
	) then
	
	inst.level = inst.level + 25
	inst.components.talker:Say("That's what i was talking about. Nya~")
end
	if (
		victim:HasTag("beequeen") or
		victim:HasTag("Goose") or
		victim:HasTag("dragonfly") or
		victim:HasTag("bearger") or
		victim:HasTag("spiderqueen") or
		victim:HasTag("deerclops") or
		victim:HasTag("minotaur") or
		victim:HasTag("klaus") or
		victim:HasTag("toadstool") 
	) then
	
	inst.level = inst.level + 50
	inst.components.talker:Say("Hell Yea! With this i can be the strongest queen ever! Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/bosskill")
end
end
	
local function onkilled(inst, data)

    if data.victim.components.health:IsDead() then
        
    inst.components.health:DoDelta(5)
    
        local random = math.random()

        if random >= .8 then
            inst.components.talker:Say("Your soul is sleeping now. Nya~")
        elseif random >= .6 and random < .8 then    
            inst.components.talker:Say("I told you to run. Nya~")
        elseif random >= .4 and random < .6  then    
            inst.components.talker:Say("Did you die already? Nya~")
        elseif random >= .2 and random < .4 then    
            inst.components.talker:Say("Noone can be better than me... Exempt me! Nya~")
        else    
            inst.components.talker:Say("Well you were tough... For a baby. Nya~")
        end
    end
end

local function master_init(inst)
	inst:ListenForEvent("killed", onkilled)
end
                                           
this one for master_postinit
                                           
	--level up
	inst:ListenForEvent("killed", onkill)
	inst:ListenForEvent("levelup", levelexp)
	inst.level = 0
                                          
and this one for common_postinit
                                           
inst.level = 0
                                           
local function onsave(inst, data)
	data.level = inst.level
 end

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...