Not_Wilson Posted May 19, 2016 Share Posted May 19, 2016 Basically I'm wrapping my Shank mod up, and I want to offset his potential OP-ness by making him lose sanity when he attacks players. My reasoning is that Shank obvious isn't one to just randomly kill people, and I don't want people picking this character to wipe out camps. So I've used this code below to get sanity from killing monsters: local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("prey") or victim:HasTag("veggie") or victim:HasTag("structure") or victim:HasTag("wall") or victim:HasTag("companion")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function onattack(inst, data) local victim = data.target if not inst.components.health:IsDead() and IsValidVictim(victim) then inst.components.sanity:DoDelta(.5) end end He gets .5 sanity per hit. However, if I use the same function: local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("player")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function onattack(inst, data) local victim = data.target if not inst.components.health:IsDead() and IsValidVictim(victim) then inst.components.sanity:DoDelta(-50) end end He will lose sanity upon killing anything. I assume for the first function I should add some kind of "else" statement? I don't know. Link to comment Share on other sites More sharing options...
Aquaterion Posted May 19, 2016 Share Posted May 19, 2016 (edited) 3 minutes ago, DextersComicLaboratory said: Basically I'm wrapping my Shank mod up, and I want to offset his potential OP-ness by making him lose sanity when he attacks players. My reasoning is that Shank obvious isn't one to just randomly kill people, and I don't want people picking this character to wipe out camps. So I've used this code below to get sanity from killing monsters: local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("prey") or victim:HasTag("veggie") or victim:HasTag("structure") or victim:HasTag("wall") or victim:HasTag("companion")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function onattack(inst, data) local victim = data.target if not inst.components.health:IsDead() and IsValidVictim(victim) then inst.components.sanity:DoDelta(.5) end end He gets .5 sanity per hit. However, if I use the same function: local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("player")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function onattack(inst, data) local victim = data.target if not inst.components.health:IsDead() and IsValidVictim(victim) then inst.components.sanity:DoDelta(-50) end end He will lose sanity upon killing anything. I assume for the first function I should add some kind of "else" statement? I don't know. you looking for "NOT (victom:HasTag("player"))". basically remove that not and it should work fine Edited May 19, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
Not_Wilson Posted May 19, 2016 Author Share Posted May 19, 2016 OH DERP. Link to comment Share on other sites More sharing options...
Not_Wilson Posted May 19, 2016 Author Share Posted May 19, 2016 38 minutes ago, Aquaterion said: you looking for "NOT (victom:HasTag("player"))". basically remove that not and it should work fine Actually, now it only makes him lose sanity from killing people. He won't gain sanity from killing other things, even after doing this tweak. Should I try to add an else statement into this function? Link to comment Share on other sites More sharing options...
Aquaterion Posted May 19, 2016 Share Posted May 19, 2016 (edited) 27 minutes ago, DextersComicLaboratory said: Actually, now it only makes him lose sanity from killing people. He won't gain sanity from killing other things, even after doing this tweak. Should I try to add an else statement into this function? well both ur validation functions have the same name, so that might be an issue i would rename it to something like IsValidPlayer and do if not inst.components.health:IsDead() then if IsValidPlayer(victim) then -- check for player first inst.components.sanity:DoDelta(-50) elseif IsValidVictim(victim) then -- since here we dont check if the target isnt a player inst.components.sanity:DoDelta(.5) end end Edited May 19, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
. . . Posted May 20, 2016 Share Posted May 20, 2016 (edited) This code for gaining sanity on attacking monster inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "spider" then inst.components.sanity:DoDelta(TUNING.SANITY_TINY) end end) of course you'd have to probably copy the code for each monster he gain sanity on attacking, the above code makes it you get 5 sanity from every hit on spider you do. Hope this helps in some way ! And here would be the proper way to lose sanity on attacking a player, all thanks to Aquaterion inst:ListenForEvent("onattackother", function(inst, data) if data.target:HasTag("player") then inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL) end end) Edited May 20, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Aquaterion Posted May 20, 2016 Share Posted May 20, 2016 5 minutes ago, SuperDavid said: This code makes it that you lose 10 sanity on attack a player. inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "player" then inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL) end end) are you sure that works? prefab is the name of the object, for players, it would be characters, like "wilson", "willow", etc.. you'd have to do data.target:HasTag("player") Link to comment Share on other sites More sharing options...
Aquaterion Posted May 20, 2016 Share Posted May 20, 2016 2 minutes ago, SuperDavid said: I have it on my character and it doesn't cause any crashes, I think it works but I can't confirm because I don't remember. It probably works. well yeah it won't crash you because the code is fine, your comparing a target's prefab name to a string, which is fine, but no prefab is called "player" as far as im aware. Link to comment Share on other sites More sharing options...
. . . Posted May 20, 2016 Share Posted May 20, 2016 (edited) Yeah, you where right the code to attack other players doesn't work. Edited May 20, 2016 by SuperDavid Link to comment 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