Need Help, why isn't this working? CODE HELP
1 1

4 posts in this topic

Recommended Posts

Hello. I'm working on a personal mod and have run into something that I can't seem to figure out, the code below is meant to prevent death for the player while an item is in the inventory, this is done by checking the player health then fully restoring it if the player has my spark in the inventory and the health is equal or less than 90 as test. The check for a black spark is a test to see what it would do.. I predicted a constantly set Health to 50.. but I want to adjust max health from 100 to 250 for example.. but setHealth(250) doesn't work.

What i'd really like is to find a way to make it so the player can go to say 10 health but won't fall below it, so that as he is mauled by the zombies, he can kill his way out then heal normally (or sped up). I want to see all the scars from the various over runs instead of the instant heal. 

I played with a way to get the current health into a local variable then setHealth(currentHealth+10) to simulate fast healing but couldn't figure it out.

Anyway, any advice or examples would be great.



function iGod_Immortal()
    local player = getSpecificPlayer(0);
    local inv = player:getInventory();
    -- Checks if the player has a spark in the inventory
    if inv:contains("iGod.iGod_DivineSpark") == true and player:getBodyDamage():getHealth() <=90 then
    elseif inv:contains("iGod.iGod_DivineSpark") == false and inv:contains("iGod.iGod_DivineSpark_Black") == true then




Share this post

Link to post
Share on other sites
12 hours ago, Morry said:

I think you're missing the "end" of function iGod_Immortal(). The only "end" in this code snippet is of the elseif. In that case the Events.OnPlayerUpdate.Add does not work.

Hey thanks for catching that, though sadly so far it isn't the issue, I guess something else is wrong. I can get it to work if I do it in a simple function but maybe I have an issue with my items? From what I know, it seems right.. bleh I just dont know enough lua lol


Edited by Berdryn83

Share this post

Link to post
Share on other sites

Try something like this while having the item in your inventory.

local check = inv:contains("iGod.iGod_DivineSpark") 
print (check)

This prints the value to the console, so if you do it in the update it's going to be printed a lot. Or you could check the value of the local variable in debug mode.

Share this post

Link to post
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
1 1