Jump to content

How to make ranged weapon use durability instead of just disappearing?


pikafan8

Recommended Posts

I tried to make a crossbow, which is weaker than the blowdart, but has a large number of finite uses. However, after firing the crossbow, it still disappears? Could I have some help with this?


 
local assets={    Asset("ANIM", "anim/crossbow.zip"),    Asset("ANIM", "anim/swap_crossbow_normal.zip"),	    Asset("ATLAS", "images/inventoryimages/crossbow.xml"),    Asset("IMAGE", "images/inventoryimages/crossbow.tex"),		}local prefabs = {    "impact",}local function onfinished(inst)    inst:Remove()endlocal function onequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_object", "swap_crossbow_normal", "swap_crossbow_normal")    owner.AnimState:Show("ARM_carry")     owner.AnimState:Hide("ARM_normal") endlocal function onunequip(inst, owner)     owner.AnimState:ClearOverrideSymbol("swap_object")    owner.AnimState:Hide("ARM_carry")     owner.AnimState:Show("ARM_normal") endlocal function onhit(inst, attacker, target)    local impactfx = SpawnPrefab("impact")    if impactfx and attacker then        local follower = impactfx.entity:AddFollower()	follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0 )        impactfx:FacePoint(attacker.Transform:GetWorldPosition())    endendlocal function onthrown(inst, data)    inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )endlocal function common()    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        anim:SetBank("crossbow")    anim:SetBuild("crossbow")        inst:AddTag("blowdart")	inst:AddTag("sharp")        inst:AddComponent("weapon")    inst.components.weapon:SetDamage(0)    inst.components.weapon:SetRange(8, 10)        inst:AddComponent("projectile")    inst.components.projectile:SetSpeed(90)    inst.components.projectile:SetOnHitFn(onhit)    inst:ListenForEvent("onthrown", onthrown)    -------        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "crossbow"    inst.components.inventoryitem.atlasname = "images/inventoryimages/crossbow.xml"		        inst:AddComponent("finiteuses")    inst.components.finiteuses:SetMaxUses(TUNING.WATHGRITHR_SPEAR_USES)    inst.components.finiteuses:SetUses(TUNING.WATHGRITHR_SPEAR_USES)        inst.components.finiteuses:SetOnFinished( onfinished )        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip(onequip)    inst.components.equippable:SetOnUnequip(onunequip)        return instendlocal function normalequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_object", "swap_crossbow_normal", "swap_crossbow_normal")    owner.AnimState:Show("ARM_carry")     owner.AnimState:Hide("ARM_normal") endlocal function normalthrown(inst)    inst.AnimState:PlayAnimation("dart_normal")endlocal function normal()    local inst = common()    inst.AnimState:PlayAnimation("idle_normal")    inst.components.equippable:SetOnEquip(normalequip)    inst.components.weapon:SetDamage(75)    inst.components.projectile:SetOnThrownFn(normalthrown)        return instendreturn Prefab( "common/inventory/crossbow_normal", normal, assets, prefabs)

Link to comment
Share on other sites

Wouldn't adding "projectile" component to the crossbow make it fire itself when you use it? Boomerangs and blowdarts are fine this way, but I think your crossbow is more similar to staffs or weather pain rather than them. So basically, the weapon and the projectile should be separated and you would need to make a new prefab file that defines the projectile.

 

Perhaps something like this...

On crossbow.lua (or whatever your prefab is named)

local prefabs = {    "impact",    "crossbow_normal_bolt",}
local function common()    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)         anim:SetBank("crossbow")    anim:SetBuild("crossbow")         inst:AddTag("blowdart")    inst:AddTag("sharp")         inst:AddComponent("weapon")    inst.components.weapon:SetDamage(0)    inst.components.weapon:SetRange(8, 10)    ------- ...
local function normal()    local inst = common()    inst.AnimState:PlayAnimation("idle_normal")    inst.components.equippable:SetOnEquip(normalequip)    inst.components.weapon:SetProjectile("crossbow_normal_bolt")        return instend

 

On crossbow_projectile.lua

local assets={	Asset("ANIM", "anim/crossbow_projectile.zip"),}local function OnHit(inst, owner, target)    inst:Remove()endlocal function common()	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)    RemovePhysicsColliders(inst)        anim:SetBank("projectile")        inst:AddTag("projectile")        inst:AddComponent("projectile")    inst.components.projectile:SetSpeed(50)    inst.components.projectile:SetOnHitFn(OnHit)    inst.components.projectile:SetOnMissFn(OnHit)    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(0)    inst.components.weapon:SetRange(8, 10)    return instend 
 local function normal()      local inst = common()      inst.AnimState:PlayAnimation("normal_bolt", true)     inst.components.weapon:SetDamage(TUNING.NORMAL_BOLT_DAMAGE)      return inst end return Prefab( "common/inventory/crossbow_normal_bolt", normal, assets)

 

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