Jump to content

Recommended Posts

On 4/28/2021 at 6:31 PM, Ultroman said:

Then you need to move the entire doAreaDamage function over into modmain.lua, outside of any other function or closure. Then exchange the code as you proposed. However, since you get the player as a parameter in your function, you should change "ThePlayer" to "player" in the line where you declare and set your x, y and z.

I finished the part where you can do AOE damage with keybind.
The finalized version is here:

Spoiler

local function doAreaDamage (inst, x, y, z, damageRange, damageToLivingEntities, doDamageToNonCombatants, workableDamage, isExplosion, ignite, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)

    local ents = TheSim : FindEntities (x, y, z, 12, nil, {"INLIMBO"}, nil)

    for i, v in ipairs(ents) do
        if v ~= inst and v:IsValid() and not v:IsInLimbo() then

            if v:IsValid() and not v:IsInLimbo() then

                if v ~= inst and v:IsValid() and not v:IsInLimbo() then
                    if workableDamage > 0 and 
                        v.components.workable ~= nil and v.components.workable:CanBeWorked() then
                        v.components.workable:WorkedBy(inst, workableDamage, nil)
                    end

                    if ignite and
                        v.components.fueled == nil and
                        v.components.burnable ~= nil and
                        not v.components.burnable:IsBurning() and
                        not v:HasTag("burnt") then
                        v.components.burnable:Ignite()
                    end

                    if v.components.health ~= nil and not v.components.health:IsDead() then
                        if v.components.combat ~= nil then
                        v.components.combat:GetAttacked(inst, damageToLivingEntities, nil)
                        elseif doDamageToNonCombatants then
                        v.components.health:DoDelta(inst, damageToLivingEntities, nil)
                        end
                    end
                end
            end
        end
    end
end

local function AkaExplosion(player)
    local x,y,z = player.Transform:GetWorldPosition()
       doAreaDamage(player, x, y, z, 12, 50, true, 0, true, false, nil, {"INLIMBO"}, nil)
end
AddModRPCHandler(modname, "Aka", AkaExplosion)

GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_G, function()
    if GLOBAL.ThePlayer and GLOBAL.ThePlayer.prefab == "gojo" and GLOBAL.TheFrontEnd:GetActiveScreen() == GLOBAL.ThePlayer.HUD then
        if GLOBAL.TheWorld.ismastersim then
            AkaExplosion(GLOBAL.ThePlayer)
        else
            SendModRPCToServer(GetModRPC(modname, "Aka"))
        end
    end
end)

 

The reason why I use 

doAreaDamage (inst, x, y, z, damageRange, damageToLivingEntities, doDamageToNonCombatants, workableDamage, isExplosion, ignite, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)

instead of 

doAreaDamage (x, y, z, damageRange, damageToLivingEntities, doDamageToNonCombatants, workableDamage, isExplosion, ignite, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)

is because "inst" helps the game recognize that the character is the subject who used AOE damage, thus the character won't hurt himself/herself.
And of course, "inst" will be changed to "player" in another chunk.

The above chunks are for modmain, for character prefabs and keyhandler, it will be the same as previous posts.

That can work like that. Nice. I'd probably rename the parameter from "inst" to "source" or "caster", though, to make its name say what it is.

You've done triple-checks here. You don't need that.

if v ~= inst and v:IsValid() and not v:IsInLimbo() then
	if v:IsValid() and not v:IsInLimbo() then
		if v ~= inst and v:IsValid() and not v:IsInLimbo() then

You only need the first if-statement, because all the if-statements that are under it in the hierarchy are only checked if they pass the first if-statement.

-- If myNumber is 1, then only the first if-statement is checked, and since it is false, it goes into the else-statement at the bottom.
-- None of the other if-statements within the first if-statement need to check the same things, because they have already been checked.
if myNumber ~= 1 then
	print("Number is not 1")
	if myNumber ~= 2 then
		print("Number is neither 1 or 2")
	else
		print("Number is 2")
	end
else
	print("Number is 1")
end

 

On 5/2/2021 at 7:47 PM, Ultroman said:

That can work like that. Nice. I'd probably rename the parameter from "inst" to "source" or "caster", though, to make its name say what it is.

You've done triple-checks here. You don't need that.


if v ~= inst and v:IsValid() and not v:IsInLimbo() then
	if v:IsValid() and not v:IsInLimbo() then
		if v ~= inst and v:IsValid() and not v:IsInLimbo() then

You only need the first if-statement, because all the if-statements that are under it in the hierarchy are only checked if they pass the first if-statement.


-- If myNumber is 1, then only the first if-statement is checked, and since it is false, it goes into the else-statement at the bottom.
-- None of the other if-statements within the first if-statement need to check the same things, because they have already been checked.
if myNumber ~= 1 then
	print("Number is not 1")
	if myNumber ~= 2 then
		print("Number is neither 1 or 2")
	else
		print("Number is 2")
	end
else
	print("Number is 1")
end

 

thanks for pointing out that ! 
This didn't go into my notification so I didn't see this reply, thanks!

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