Goregonzola Posted May 20, 2021 Share Posted May 20, 2021 (edited) Hey-hey! I'm looking for a bit of guidance about a perk-idea I have in mind. The main goal would be that my survivor could only be able to attack entities with the "hostile" tag. The prohibition code will probably be one of these, but I'm not sure how the frame of the perk should look like: Quote inst.components.combat.canattack = false inst.components.combat:SetTarget(nil) Is this a simple local function I should create or something more complicated? I can't really think of an example for this, as far as I know only non-playable creatures can sort targets. Thanks in advance! Cheers! Edited May 21, 2021 by C_Thun Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/ Share on other sites More sharing options...
Wonderlarr Posted May 20, 2021 Share Posted May 20, 2021 You should be able to do this via a stegraph, where you just cancel the attack if not target:HasTag("hostile")... Or something like that. Sorry I can't help more, I'm at work lol. Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462028 Share on other sites More sharing options...
Goregonzola Posted May 20, 2021 Author Share Posted May 20, 2021 (edited) I've tinkered it a bit, but I feel like I'm still very far from the solution. This is the best I came up with so far, but better programmers will just probably just whisper a "Huh, pathetic..." line in anime style: Quote local function moral(inst, data) if inst.prefab == "samjack" and data.target.components.combat then if (not data.target:HasTag("hostile")) then inst.components.combat.canattack = false inst.components.combat:SetTarget(nil) end end end This doesn't do anything at the moment : ( Edited May 20, 2021 by C_Thun Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462082 Share on other sites More sharing options...
Wonderlarr Posted May 20, 2021 Share Posted May 20, 2021 (edited) Okay, I tried adapting some code from my own mod, you'll need to change hatkid to your character's prefab, and add some extra stuff yourself. It will also only work if you have movement prediction disabled on your client. I'll help you later with how to get it working with it, just figured you can test this from now. Put this in your modmain AddStategraphPostInit("wilson", function(sg) local _attack = sg.states["attack"] local _onenter = _attack.onenter _attack.onenter = function(inst,...) _onenter(inst,...) if inst.prefab == "hatkid" and inst.components.combat.target:HasTag("hostile") then -- code if hostile else --code if not hostile end return end end) do not do this Edited May 21, 2021 by TheSkylarr Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462106 Share on other sites More sharing options...
Wonderlarr Posted May 21, 2021 Share Posted May 21, 2021 Okay, ignore my previous post, that doesn't work. I've got a a second one for you that doesn't require you to have special code in your characters prefab file, it just works with whatever if statement you want. AddStategraphPostInit("wilson", function(sg) local _attack = sg.states["attack"] -- This specifies which state we're adding to local _onenter = _attack.onenter _attack.onenter = function(inst,...) _onenter(inst,...) if inst.prefab == "hatkid" and not inst.components.combat.target:HasTag("monster") then -- this runs if the thing your character is attacking doesn't have the tag "monster" inst:ClearBufferedAction() -- Cancel the attack before it hits. inst.sg:GoToState("idle", true) -- Go to idle state, technically redundant but it keeps things neat. inst.components.talker:Say(GetString(player, "ACTIONFAIL_GENERIC")) -- This will use the characters speech file for this line. end return end end) In this example, once you change the prefab name (I used Hat Kid to test it), the specified character will not be able to attack anything that doesn't have the monster tag. 1 Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462204 Share on other sites More sharing options...
Goregonzola Posted May 21, 2021 Author Share Posted May 21, 2021 (edited) @TheSkylarr It works like charm, many thanks <3 I had to replace this line Quote inst.components.talker:Say(GetString(player, "ACTIONFAIL_GENERIC")) with Quote inst.components.talker:Say("I cannot do that.") but otherwise it works as intended. Edited May 21, 2021 by C_Thun 1 Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462258 Share on other sites More sharing options...
Wonderlarr Posted May 21, 2021 Share Posted May 21, 2021 11 minutes ago, C_Thun said: @TheSkylarr It works like charm, many thanks <3 I had to replace this line with but otherwise is works as intended. Understandable change there, glad I could help. Personally I like having all my speech lines in the speech files, but if works, it works. Good luck with your project. 1 Link to comment https://forums.kleientertainment.com/forums/topic/130133-solved-restrict-survivors-ability-to-attack/#findComment-1462260 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now