Jump to content

Code help please!


kilenator

Recommended Posts

hey guys, im making a character of my own, im great at art but im so bad at coding (well not bad just not into it that much) so before i made the art i wanted to get the code first. started few days ago, coded the character, gave him a book (like maxwells) and bound another monster to the book instead of maxwells shadows. everything is working fine, i can summon the monster using the book and it is friendly, attacks when i do follows me, everything is fine. its almost finished i just have 2 more issues left that i dont know how to deal with.

1. after i summon the first monster i need to make the book not spawn anymore of them when i click it until the summoned one dies

2.i would like to remove the standard nightmare fuel and sanity/hp cost and replace it with half the character hp cost

i cant seem to get those right, i just dont know the code for it, i can remove the nightmare fuel cost but that just keeps spawning them while im keeping clicking, the first problem i have i think has something to do with "if TUNING.MONSTER_ALIVE" but i dont know how to use it.

 

please help, if you can write me the code for those or just point me to the right path that would mean so much to me

thank you guys in advance

1000000000 times!

Link to comment
Share on other sites

Just throwing an idea out, maybe you could add a tag to the summoned monster and have a check if any monsters with that tag were alive then don't summon anymore.

 

oh, that could work, then it would be something like this

 

local function Update(inst)

    if TUNING.MONSTER_ALIVE == 1 then

        local monster = TheSim:FindFirstEntityWithTag("monster")

        if not monster then

            monster = Spawnmonster(inst)

 

is that corect?

but how do i "tag" the monster? which would be the code?

sorry i still dont understand the coding language enough :(

Link to comment
Share on other sites

oh, that could work, then it would be something like this

 

local function Update(inst)

    if TUNING.MONSTER_ALIVE == 1 then

        local monster = TheSim:FindFirstEntityWithTag("monster")

        if not monster then

            monster = Spawnmonster(inst)

 

is that corect?

but how do i "tag" the monster? which would be the code?

sorry i still dont understand the coding language enough :(

All you need to do is

inst:AddTag("TAGNAME")

to the spawned monster. TAGNAME can be anything you want - but try to make sure it's unique, so you don't clash with existing tags.

Link to comment
Share on other sites

All you need to do is

inst:AddTag("TAGNAME")

to the spawned monster. TAGNAME can be anything you want - but try to make sure it's unique, so you don't clash with existing tags.

ty for the info, now i get it a little more, but i cant get it to work :( i tried it with my mod and

i tried it with the original maxwell, i opened waxwelljournall.lua and added

 

local function Update(inst)

    if TUNING.SHADOWWAXWELL_ALIVE == 1 then

        local shadowwaxwell = TheSim:FindFirstEntityWithTag("waxwax")

        if not shadowwaxwell then

            shadowwaxwell = Spawnshadowwaxwell(inst)

            inst.shadowwaxwell = shadowwaxwell

            AddLeader(shadowwaxwell)

        end

    end

end

local function StartUpdating(inst)

    if not inst.loop then

        inst.loop = {}

    end

    inst.loop.amount = 0

    inst.loop.period = 0.1

    if not inst.loop.task then

        inst.loop.task = inst:DoPeriodicTask(inst.loop.period, function() Update(inst) end)

    end

end

 

i even tried

 

local function onread(inst, reader)

    if TUNING.SHADOWWAXWELL_ALIVE == 1 then

        local shadowwaxwell = TheSim:FindFirstEntityWithTag("waxwax")

        if not shadowwaxwell then

            shadowwaxwell = Spawnshadowwaxwell(inst)

            inst.shadowwaxwell = shadowwaxwell

            AddLeader(shadowwaxwell)

        end

    end

end

 

and in the shaddowwaxwell.lua i added under local function

 

local function fn()

    local inst = CreateEntity()

    local trans = inst.entity:AddTransform()

    local anim = inst.entity:AddAnimState()

    local sound = inst.entity:AddSoundEmitter()

    inst.Transform:SetFourFaced(inst)

    MakeGhostPhysics(inst, 1, .5)

    anim:SetBank("wilson")

    anim:SetBuild("waxwell_shadow_mod")

    anim:PlayAnimation("idle")

    anim:Hide("ARM_carry")

    anim:Hide("hat")

    anim:Hide("hat_hair")

    

    inst:AddTag("scarytoprey")

    inst:AddTag("NOCLICK")

    inst:AddTag("waxwax") <---this is the tag name i added

 

i must be missing something, that is everything i changed, maybe in the modmain.lua i have to add something?

sorry if im hard to work with :(

Link to comment
Share on other sites

All you need to do is

inst:AddTag("TAGNAME")

to the spawned monster. TAGNAME can be anything you want - but try to make sure it's unique, so you don't clash with existing tags.

couldnt do it, but i changed it so when i use the book it spawns 1 monster and consumes the book as a reagent, and when the monster dies it drops the book so it can be used again

 

i wanted to ask you can you help me with the second thing, i need to make the character lose half his health or sanity when i use the book, it doesnt need to be half exactly, it can be 50, 60, any number

 

now the book uses up healt and sanity, i can remove the use of health and sanity both but i just want to change it

what code do i write in the book.lua to make it consume, lets say 100 sanity?

is that posible? i have seen

 

local function onread(inst, reader)

    GetPlayer().components.sanity:DoDelta(-TUNING.SANITY_HUGE)

 

that uses 50 sanity i think, how do i set it to 100?

Link to comment
Share on other sites

couldnt do it, but i changed it so when i use the book it spawns 1 monster and consumes the book as a reagent, and when the monster dies it drops the book so it can be used again

 

i wanted to ask you can you help me with the second thing, i need to make the character lose half his health or sanity when i use the book, it doesnt need to be half exactly, it can be 50, 60, any number

 

now the book uses up healt and sanity, i can remove the use of health and sanity both but i just want to change it

what code do i write in the book.lua to make it consume, lets say 100 sanity?

is that posible? i have seen

 

local function onread(inst, reader)

    GetPlayer().components.sanity:DoDelta(-TUNING.SANITY_HUGE)

 

that uses 50 sanity i think, how do i set it to 100?

I'm really not the most coding-knowledgeable here. And I've been out of commission for so long I'm getting a bit rusty on what code I had familiarised myself with... sorry I can't be more help...

That said, you don't need to point it to a TUNING.WHATEVER value. Like, you can just use (-100) - or, alternatively, you can make it do math. Things like -TUNING.SANITY_HUGE*2 and -TUNING.SANITY_HUGE/2 will work.

Link to comment
Share on other sites

I'm really not the most coding-knowledgeable here. And I've been out of commission for so long I'm getting a bit rusty on what code I had familiarised myself with... sorry I can't be more help...

That said, you don't need to point it to a TUNING.WHATEVER value. Like, you can just use (-100) - or, alternatively, you can make it do math. Things like -TUNING.SANITY_HUGE*2 and -TUNING.SANITY_HUGE/2 will work.

 

-TUNING.SANITY_HUGE*2 worked perfectly! thank you!

requesting lock

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...