Jump to content

Recommended Posts

Basically, I want a character's attack to be a melee, but instead it seems this won't work:

 

 

local function EquipWeapon(inst)
    if inst.components.inventory and not inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
        local weapon = CreateEntity()
        --[[Non-networked entity]]
        weapon.entity:AddTransform()
        weapon:AddComponent("weapon")
        weapon.components.weapon:SetDamage(inst.components.combat.defaultdamage)
        weapon.components.weapon:SetRange(inst.components.combat.attackrange, inst.components.combat.attackrange+4)
        weapon.components.weapon:SetProjectile("bishop_charge")
        weapon:AddComponent("inventoryitem")
        weapon.persists = false
        weapon.components.inventoryitem:SetOnDroppedFn(inst.Remove)
        weapon:AddComponent("equippable")
        
        inst.components.inventory:Equip(weapon)
    end
end

 

When the player recieves it, the game crashes.  Any way I can fix it, or do I have to make my own weapon?

@Mario384,

this all looks a bit confusing to me.

if u attack something without any weapon equipped, your character automatically attacks melee(use Crtl to force attack), so i dont know why u would try to add anything to your character anyway?

also, i assume this code is support to be in the prefab of an item, or is it?

if its supposed to be an item, and melee, why dont just base it on the spear?

to me this code looks like to copypasted stuff together without knowing what it does....

@Mario384,

This all looks a bit confusing to me.

if you attack something without any weapon equipped, your character automatically attacks melee(use Crtl to force attack), so I dont know why you would try to add anything to your character anyway?

also, I assume this code is support to be in the prefab of an item, or is it?

if its supposed to be an item, and melee, why dont just base it on the spear?

 

( Insult here, if it's confusing to you, don't tell people they have no idea what they're doing.)

 

This is the weapon the Bishop uses.  It allows him to fire a special bolt which occurs in his attacks.  This is in his prefab, and it is equipped when he spawns.  I know precisely that the player can use crtl and left click, and this is not a melee weapon.

Edited by Mario384

( Insult here, if it's confusing to you, don't tell people they have no idea what they're doing.)

well, i help a lot of pple, who actually just copypaste stuff together without knowing what they are actually doin (and who mostly also admit it) and u talking about your character just attacking with melee, while your code creates projectiles and looks like a function from a weaponprefab didnt make much sense to me, thats why i assumed it.

also, i didnt say anything like "dont just copypaste stuff together", i specifically worded it, that iam confused and it looks to me, like u copypasted it together.

and yes, it was new to me that creating a weaponentity on the fly like that is a thing.

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