Jump to content

help in character perks pls


Recommended Posts

hola no hablo ingles.
tengo este codigo, deberia de subir la vida maxima al matar una entidad(mob)

pero quiero hacer que varie el +0.5

Hello I do not speak English.
I have this code, it should raise the maximum life when killing an entity (mob)
but I want to change the +0.5

-----------------------------------------------------

local function onsave(inst, data)
    data.maxhealth = inst.components.health.maxhealth or nil

end

local function onpreload(inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)
end

local function subirnivel(inst)
    if  inst.components.health.maxhealth >= (1)  and inst.components.health.maxhealth < (300) then
        inst.components.health.maxhealth = (inst.components.health.maxhealth + 0.5)
   end
end

local master_postinit = function(inst)
    inst.components.health:SetMaxHealth(TUNING.KIRA_HEALTH)
    inst:ListenForEvent("killed", function(inst) subirnivel(inst) end
   inst.OnSave = onsave
   inst.OnPreLoad = onpreload
end

-------------------------

pensaba en algo como esto

i was thinking of something like this

---------------------------

local function onsave(inst, data)
    data.maxhealth = inst.components.health.maxhealth or nil

end

local function onpreload(inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)

end

local function subirnivel(inst)    
    vmph=1
    if inst.components.health.maxhealth >= (1)and inst.components.health.maxhealth < (300)then
            inst.components.health.maxhealth = (inst.components.health.maxhealth + vmph)
            vmph=vmph*0.99
    elseif inst.components.health.maxhealth > (300) then
            inst.components.health.maxhealth = (300)
    elseif inst.components.health.maxhealth < (1) then
            inst.components.health.maxhealth = (1)
    end

end

local master_postinit = function(inst)
    inst.components.health:SetMaxHealth(TUNING.KIRA_HEALTH)
    inst:ListenForEvent("killed", function(inst) subirnivel(inst) end
   inst.OnSave = onsave
   inst.OnPreLoad = onpreload
end

pero no inicia con el segundo meto alguien sabe que puedo hacer?

but it does not start with the second method, does anyone know what I can do?

Edited by orlando gonzalez
Link to comment
Share on other sites

Why your numbers have parenthesis around?

Do you get any error log from your server?
If your world is not initializing after a customization, you can see the problem in the server_log or in the client_log
Look your Klei folder (under your documents)

BUT I think I spotted the problem
The variable: "vmph"

I didnt see any declaration for this one
So I think you had to say or its local, or its associated to your instance
local vmph = 1     --- OR --- inst.vmph=1

And looking your code, I can imagine that what you want to do is every time you kill an enemy, you gain +vmph in you max health, and this value of vmph will decrease each kill, making it a capacitor charging curve

The way you wrote it, it will not work, since every time you kill an enemy you reset the value of vmph to 1, so you will get +1 max health each kill

If you are trying to do what I'm imagining, you need to attach the vmph variable to your master_postinit, like inst.vmph
AND you need to save and load this variable, or the character can "re-log" into the server to reset the exponential decrease and get better bonuses

 

Link to comment
Share on other sites

Exactly,

I want the value of the variable to be saved and added to life every time it kills,
when it leaves the server it remains as it was when it left when entering.

but how should i do it exactly

 

función local onsave (inst, data)
    data.maxhealth = inst.components.health.maxhealth o nil

final

función local onpreload (inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)

final

función local subirnivel (inst)    
    local inst.vmph = 1
    si inst.components.health.maxhealth> = (1) e inst.components.health.maxhealth <(300) entonces
            inst.components.health.maxhealth = (inst.components.health. maxhealth + vmph)
            vmph = vmph * 0.99
    elseif inst.components.health.maxhealth> (300) luego
            inst.components.health.maxhealth = (300)
    elseif inst.components.health.maxhealth <(1) luego
            inst.components. health.maxhealth = (1)
    fin

final

master_postinit local = función (inst)
    inst.components.health:SetMaxHealth(TUNING.KIRA_HEALTH)
    inst: ListenForEvent ("muerto", función (inst) subirnivel (inst) end
   inst.OnSave = onsave
   inst.OnPreLoad = onpreload
end

the numbers are the minimum and maximum life parameters of the character

Link to comment
Share on other sites

You need to write your commands in English
"function" is a line given to the interpreter, not a translatable word
 

1 hour ago, orlando gonzalez said:

función local onsave (inst, data)

    data.maxhealth = inst.components.health.maxhealth o nil

final

función local onpreload (inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)

final

 

You need to save 2 values here, vmph and maxhealth

So

function local onsave(inst,data)
    data.maxhealth = inst.components.health.maxhealth o nil

    data.vmph = inst.vmph or 1
end

function local onpreload (inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)
    inst.vmph = data.maxhealth

end

 

1 hour ago, orlando gonzalez said:

función local subirnivel (inst)    

    local inst.vmph = 1
    si inst.components.health.maxhealth> = (1) e inst.components.health.maxhealth <(300) entonces
            inst.components.health.maxhealth = (inst.components.health. maxhealth + vmph)
            vmph = vmph * 0.99
    elseif inst.components.health.maxhealth> (300) luego
            inst.components.health.maxhealth = (300)
    elseif inst.components.health.maxhealth <(1) luego
            inst.components. health.maxhealth = (1)
    fin

final


since vmph is associated with inst, its not a local variable
here you are doing the same thing, you are re-seting your value of vmph to 1 everytime you lvl up, so you will not achiev the exponential decrease/capacitor charging

and you need to write inst.vmph, not vmph, since its associated to your inst

Link to comment
Share on other sites

1 hour ago, Gleenus said:

You need to write your commands in English
"function" is a line given to the interpreter, not a translatable word
 

You need to save 2 values here, vmph and maxhealth

So

function local onsave(inst,data)
    data.maxhealth = inst.components.health.maxhealth o nil

    data.vmph = inst.vmph or 1
end

function local onpreload (inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)
    inst.vmph = data.maxhealth

end

 


since vmph is associated with inst, its not a local variable
here you are doing the same thing, you are re-seting your value of vmph to 1 everytime you lvl up, so you will not achiev the exponential decrease/capacitor charging

and you need to write inst.vmph, not vmph, since its associated to your inst

as I do with a "write" I look on the internet and only examples out of functions and with numbers without instances appear ...and I can't understand in practice

ininitially 
inst.vmph=1 
and
UNING.KIRA_HEALTH = 1 (data.maxhealth = inst.components.health.maxhealth or nil)
-----------------------
 

function local onsave(inst,data)
    data.maxhealth = inst.components.health.maxhealth o nil

    data.vmph = inst.vmph or 1
end

 

local function subirnivel(inst) 

   local i=1
   while (i<2)
   do
            inst.components.health.maxhealth >= (1)and inst.components.health.maxhealth < (300)then
            inst.components.health.maxhealth = (inst.components.health.maxhealth + vmph)
            inst.vmph=inst.vmph*0.9
            i=i+1
   end
end

 

function local onpreload (inst, data)
    inst.components.health:SetMaxHealth(data.maxhealth)
    inst.vmph = data.maxhealth
end


local master_postinit = function(inst)
   inst.components.health:SetMaxHealth(TUNING.KIRA_HEALTH)
   inst:ListenForEvent("killed", function(inst) subirnivel(inst) end
   inst.OnSave = onsave
   inst.OnPreLoad = onpreload
end

"my result was a mindless crash"
:c

 

 

 

Edited by orlando gonzalez
Link to comment
Share on other sites

You need to read the crash log
You will notice the "line number" in the log and this will help you to fix the problem
(always mod in dedicated server, it makes the process much easier)

you can not set a value to inst outside inst

" inst.vmph=1 "

This should be inside your master_postinit
master_postinit is a function of "inst", so "inst" exists in this context

And the while thing you have done, I just don't get it
You approach was right the last time, just need to fix

I strongly suggest you to start with something easier than making a character
Like, make an machine that produces Ice every X seconds, this will make you get the programming notation for Lua and DST
I have videos about this, but it is in Portuguese

https://www.youtube.com/watch?v=ZmRBPq0wqqs&list=PLE8tdlJ93hif17w4Hli3lYZt9qblagV03

 

Link to comment
Share on other sites

13 hours ago, Gleenus said:

You need to read the crash log
You will notice the "line number" in the log and this will help you to fix the problem
(always mod in dedicated server, it makes the process much easier)

you can not set a value to inst outside inst

" inst.vmph=1 "

This should be inside your master_postinit
master_postinit is a function of "inst", so "inst" exists in this context

And the while thing you have done, I just don't get it
You approach was right the last time, just need to fix

I strongly suggest you to start with something easier than making a character
Like, make an machine that produces Ice every X seconds, this will make you get the programming notation for Lua and DST
I have videos about this, but it is in Portuguese

https://www.youtube.com/watch?v=ZmRBPq0wqqs&list=PLE8tdlJ93hif17w4Hli3lYZt9qblagV03

 

hi this is my file, I was watching your videos a bit but my time is very short :c
I can make my life go up 1 in 1 in that case, but I want it to go up for example 1, 2.25, 3.375 ...

my problem is setting the maxcounter variable to be saved and loaded from onsave and onpreload

what I want is to make a character so far I have the textures and they look good,
it is about a girl disappeared so she is somewhat short in stature, what I am drowning now is putting perks on her

kira.lua

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...