Jump to content

Help with Trait bonuses and detecting them - Answered


Spar10

Recommended Posts

I have found several instances where traits are checked from a 'character' object in timed action functions like below.

 

function ISInventoryTransferAction:new (character, item, srcContainer, destContainer, time)
...
	if character:HasTrait("Dextrous") then
		o.maxTime = o.maxTime * 0.5
	end
	if character:HasTrait("AllThumbs") then
		o.maxTime = o.maxTime * 4.0
	end
...
end

I have been able to use a similar call to check for the "Lucky" and "Unlucky" trait in a timed action function but I would like to use these checks in a recipe 'OnCreate' function.  The recipe functions pass a 'player' object instead of 'character' and doesn't seem to have the same class structure.  Below is a lua block I have tried to adjust crafting chance and it does not work.  Is there an easier way to find how the built-in function calls are defined?  For example the difference between 'character' and 'player' in these function calls.

-- (OnCreate) Function passed to Craft Sheet to complete crafting object
function stCreateSheet(items, result, player, selectedItem)

    -- Main Recipe uses line "RemoveResultItem:true," so item is created in function on success
    -- Base chance with no skill is 35% with master skill at 95%
    -- Comment:  Even an idiot can make a simple sheet 1/3 of the time.
    local successChance =  35 + (player:getPerkLevel(Perks.Tailoring)*6);

    ---[[
    --This code is breaking the function
    if player:HasTrait("Lucky") then
        successChance = successChance + ZombRand(5,15);
    elseif player:HasTrait("Unlucky") then
        successChance = successChance - ZombRand(5,15);
    end
    --]]

    if ZombRand(0,100) < successChance then
        -- Sucess, create sheet and gain some XP
        player:getXp():AddXP(Perks.Tailoring, 1);

        -- Create sheet item and give to player
        local objSheet = InventoryItemFactory.CreateItem("Base.Sheet");
        player:getInventory():AddItem(objThread);

    else
            -- Failed to make item have character comment
            -- Some code similar from TimedAction, may work here
            -- self.character:Say("I need to get better at tailoring!");
    end
end

I'll run a few more tests trying different ways to get the character object to do the check but any help is appreciated.  I'm still digging through code and learning about how the game mechanics work.

Link to comment
Share on other sites

Thank you I'll give that a try.  Might have to install Hydrocraft and look at it for fun and code.  :)

 

I might think of using another trait like Dextrous to give a slightly better outcome. 

 

Sad to see 'Lucky' get removed, I've always enjoyed RNG traits.  From looking around the game files they don't use it much except for loot drops.  Could be used much more in overall RNG calculations.

Link to comment
Share on other sites

  • Spar10 changed the title to Help with Trait bonuses and detecting them - Resolved
  • Spar10 changed the title to Help with Trait bonuses and detecting them - Answered
13 hours ago, Spar10 said:

Thank you I'll give that a try.  Might have to install Hydrocraft and look at it for fun and code.  :)

 

I might think of using another trait like Dextrous to give a slightly better outcome. 

 

Sad to see 'Lucky' get removed, I've always enjoyed RNG traits.  From looking around the game files they don't use it much except for loot drops.  Could be used much more in overall RNG calculations.

 

Main reason it's being removed (temporarily at least iirc) is that it's bugged and doesn't actually do anything in MP.

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
×
×
  • Create New...