Jump to content

If Statements and multiple actions


Recommended Posts

I'm trying to create a mod that allows the spear to be throwable. I've managed to do that but now I want to add the ability to decide wether it should throw the Spear or walk up and hit it. I believe this is done threw if statements but Im not sure how id go about doing it. Any insight would be appreciated

Link to comment
Share on other sites

-- in your prefab file somewherelocal function GetWeaponMode(weapon)	local inst = weapon.components.inventoryitem.owner	local max_melee_attack_range = 1	if inst:IsNear(inst.components.combat.target, max_melee_attack_range) then		return weapon.components.weapon.modes["MELEE"]	else		return weapon.components.weapon.modes["RANGE"]	endend-- in your prefab's fn function:        weapon:AddComponent("weapon")        weapon.components.weapon.modes =        {                RANGE = {damage = 1, ranged = true, attackrange = 5, hitrange = 7},                MELEE = {damage = 1, ranged = false, attackrange = 0, hitrange = 1}    	}        weapon.components.weapon.variedmodefn = GetWeaponMode
Edit the weapon.components.weapon.modes table with the values you want and set max_melee_attack_range in GetWeaponMode to what you want.

EDIT: Updated to use the IsNear function because it's more clear/applicable for the situation.

Link to comment
Share on other sites

inst:AddComponent("projectile")

inst.components.projectile:SetSpeed(15)

inst.components.projectile:SetCanCatch(true)

inst.components.projectile:SetHoming(false)

inst.components.projectile:SetOnThrownFn(OnThrown)

inst.components.projectile:SetOnHitFn(OnHit)

inst.components.projectile:SetOnMissFn(ReturnToOwner)

inst.components.projectile:SetOnCaughtFn(OnCaught)

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