Jump to content

Recommended Posts

Guys, could someone help me?

 

I'm creating this PvP weapon where it deals no damage, however puts targets to sleep and damages while the foe is sleeping, like 1 damage per tick

The weapon is intended to have infinite uses, and i don't know how to create the "infiniteUses" so i'm modifying Walking Cane's Prefab.

 

Here's the code I could use to get the funtion onattack and sleep, buuut i'm the on put to sleep when I hit a foe/player


local function onattack(inst, target, attacker)
    if target ~= nil and target:IsValid() and attacker ~= nil and attacker:IsValid() then
        if target.components.sleeper ~= nil then
                target.components.sleepingbag:onsleeper(5, )                                
            elseif target.components.grogginess ~= nil then
                    target.components.grogginess:AddGrogginess(5, 5)
                else
                    target:PushEvent("knockedout")
            end
    end
end

 

(...)

inst:AddComponent("sleepingbag")
    inst.components.sleepingbag.health_tick = TUNING.SLEEP_HEALTH_PER_TICK

(...)

it's no presenting any bug or crash with this

 

but i want the target/foe to sleep for the amout of time and while its sleeping that health decreases until is awaken or hit

 

thx so much

 

ps: i dont know much of coding

 

Link to comment
https://forums.kleientertainment.com/forums/topic/139209-creating-a-weapon/
Share on other sites

Okay, here is what you should do.
(This might not work, I'm also new, but try it)
 

Go all the way down to the components part of your script, then delete the whole "finiteuses" component, if you have one. Then it should be infinite.

Also, change the "TUNING.SLEEP_HEALTH_PER_TICK" to a negative number of your choice.

As for the timer, I don't know how to set the amount of time with the code you have provided.

Edited by BombardmentPigs

i figured out that the game already have the sleep darts, so i modified them to be used in the cane. 

so the weapon first part is working fine, like i hit and set the target to sleep

but i'm not getting the damage from it cause there are 2 types of sleeping

 

which is from "sleepingbag" and "sleeper" but i will be trying here

thx for the help, as always welcomed

 

--the underlined code only let me to lose health while i use something to sleep (sleepingbag), but I want that the moment the target go to sleep it starts losing its health, (for player only)

 

(...not changed walking cane prefab code...)

local function onattack(inst, attacker, target)

    while target.components.sleeper == true and target:HasTag("player") do
        target.components.sleeper.health_tick = TUNING.SLEEP_HEALTH_PER_TICK -- added 'health_tick' to sleeper.lua and to modmain
    end

    if target.components.sleeper ~= nil then
        target.components.sleeper:AddSleepiness(10,TUNING.PANFLUTE_SLEEPTIME, inst)
    elseif target.components.grogginess ~= nil then
        target.components.grogginess:AddGrogginess(10, TUNING.PANFLUTE_SLEEPTIME)
    end
    if target.components.combat ~= nil and not target:HasTag("player") then
        target.components.combat:SuggestTarget(attacker)
    end
    
    target:PushEvent("knockedout", { attacker = attacker, damage = 0, weapon = inst }) 
    
        --target:PushEvent("startstarving") <--seems not to work
        
end

 

(...same)

local function fn()

(...)
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.CANE_DAMAGE)
    inst.components.weapon:SetOnAttack(onattack)

    return inst

end

edit: mainmod.lua has TUNING.SLEEP_HEALTH_PER_TICK = -10, for test so I lose health if sleeping

so far. i've got the target to sleep, but not dealing tickdamage while is sleeping.

Edited by Badarokey

Hm. Now that might be out of my knowledge for now. So I might not be able to help.

However, I have an idea: (In pseudo-code)

When Player goes to sleep:
repeat every 0.2 seconds:
reduce health

Unfortunately I don't know how to type that in .lua :???:
Hope this helps a bit!

Edited by BombardmentPigs

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