Jump to content

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

Are there any ideas out there? I was looking at the monkey prefab and it seems to use the function im looking for. I need to rewrite the hasammo function to determine if target is in range or out of range. How could I do that?

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

Edited by squeek

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)

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