Jump to content

random chance for nearby pigs to turn into werepigs?


Recommended Posts

1563796823_PreviewImage.png.46ba780c7c830d012369e279afe15a54.png

I am updating my unfortunate girl Darna, and a "bad luck with a good twist" perk idea I had is for any pig around her to have a 5% chance to turn into a werepig regardless of time of the day, with a timer of a life minute for this chance to be triggered. Does it sound too powerful? I want it to be a risk reward thing that you can't control and may happen at unfortuante times, with the reward of werepig drops if you can kill it.

In any case, could someone help me with an idea of how the code would look like for this? I figure an aura radius must be set, (pretty big, almost screen wide)  but I really don't know how to influence pig transformations trough code.

Link to comment
Share on other sites

You'll need inst:DoPeriodicTask(PERIOD, fn) to call a check fn every PERIOD seconds, TheSim:FindEntites(x, y, z, RANGE, MUST_TAGS, CANT_TAGS) to find nearby pigs, and the SetWere method of the werebeast component.
Something like this:

local WERE_CHECK_PERIOD = 10
local WERE_RANGE = 15
local WERE_CHANCE = 0.05
local STAY_WERE_TIME = TUNING.SEG_TIME * 4
local WERE_MUST_TAGS = {"pig"}
local WERE_CANT_TAGS = {"werepig"}

local function turn_were(inst, pig)
    pig.components.werebeast:SetWere(STAY_WERE_TIME)
end

local function werepig_turner(inst)
    local x, y, z = inst.Transform:GetWorldPosition()
    local ents = TheSim:FindEntities(x, y, z, WERE_RANGE, WERE_MUST_TAGS, WERE_CANT_TAGS)

    for i, pig in ipairs(ents) do
        if math.random() < WERE_CHANCE then
            turn_were(inst, pig)
        end
    end
end

--------------------
--in character prefab init fn
    inst:DoPeriodicTask(WERE_CHECK_PERIOD, werepig_turner)

 

Edited by Friendly Grass
Link to comment
Share on other sites

image.thumb.png.2554187f589d7f45e646e6361d7d6c6a.png

Alright!, it took a bit of fiddling because of silly mistakes on my part but it works! Thank you!

May I ask what unit of time does the 10 represent in WERE_CHECK_PERIOD = 10? it would help me fine tune it.

I don't want to make more threads about my character so if its ok with you all i would like to ask about a different perk idea:

I saw this line of code in the forums regarding ways to make enemies target the character more often:
if ent.components.combat then
  ent.components.combat:SuggestTarget(inst)
end
but if I understand this correctly, its missing the part where it looks around to check what entities are around the characters before it can see if they are in combat right? is there a simple way to integrate this?

To be specific, I don't want all enemies to target Darna all the time unprovoked in a multiplayer setting, I just want that, if there are many enemies around multiple players, engaged in combat (like a hound wave or going to clear a spider biome with friends) then enemies will tend to preffer attacking Darna about 30% of the time. Does it make sense? I don't want to guarantee safety to the other players, but still be helpful as a lure.

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