edwardtmclean03 Posted March 7, 2014 Share Posted March 7, 2014 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 More sharing options...
edwardtmclean03 Posted March 7, 2014 Author Share Posted March 7, 2014 Something along the lines likeif target is close = hitif target is far = throwbut I don't know how to differ from the actions with Don't Starve pre-determined actions Link to comment Share on other sites More sharing options...
edwardtmclean03 Posted March 8, 2014 Author Share Posted March 8, 2014 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? Link to comment Share on other sites More sharing options...
squeek Posted March 8, 2014 Share Posted March 8, 2014 -- 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 = GetWeaponModeEdit 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 More sharing options...
edwardtmclean03 Posted March 8, 2014 Author Share Posted March 8, 2014 you are amazing. Link to comment Share on other sites More sharing options...
edwardtmclean03 Posted March 8, 2014 Author Share Posted March 8, 2014 it all works except for now when spear is thrown it returns to hand while I want it to land on ground Link to comment Share on other sites More sharing options...
squeek Posted March 8, 2014 Share Posted March 8, 2014 it all works except for now when spear is thrown it returns to hand while I want it to land on ground What does your projectile code look like? Link to comment Share on other sites More sharing options...
edwardtmclean03 Posted March 9, 2014 Author Share Posted March 9, 2014 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 More sharing options...
squeek Posted March 10, 2014 Share Posted March 10, 2014 Modify or remove this line: inst.components.projectile:SetOnMissFn(ReturnToOwner)and modify the OnHit function to not call ReturnToOwner (probably just want to call OnDropped instead) Link to comment Share on other sites More sharing options...
Recommended Posts
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.