Fidooop Posted June 12, 2015 Share Posted June 12, 2015 (edited) YAY YAY YAY YAY YAY YAY YAY YAY YAY SMILEY MOD IS 90% FINISHED!.... But it has... follower problems....................... Well I also have to do 1 little thing for Fantabulous for his upgrade system but other than that everything is finished!What follower problems though? Well there's a lot!!!You see I created these adorable little pets by the name of "stikmen" and boy are they cute as all hell!http://steamcommunity.com/sharedfiles/filedetails/?id=458882464http://steamcommunity.com/sharedfiles/filedetails/?id=457709114They all have cute little quotes and random names! and there are even 3 different types of stikmen toobut I have a wee... bunch of little problems with them that I can't for the life of me figure out... D:They are already mostly programmed but I'm missing some important knowledge it seems... 1: I'd like it if they treated all players alike! Not just their leader... You see, they are supposed to run from everything a certain distance so they don't get in the way or anything and they do it wonderfully! except for when it comes to a nonleading player... then they seem to just... completely ignore them or something... I'm sure it's a brain problem and I could probably get it working with a bit of tinkering! (but incase I don't I'm leaving the problem here incase somebody knows what's up) 2: I've been trying to dig around the combat component but I can't seem to find a way to make it so that nobody can attack them unless they force attack... because right now it seems that nonleading players can accidentally whap them in the face by holding spacebar or the F key! And that's not good because these little stikmen have very little health and in most cases will be 1 hit killed and then that attacking player will be swarmed and lose his own stikmen because they'll decide to stop following him to go and attack his ass for hurting their kind! 3: The big one... the awful one... the big daddy that's been kicking me in the face since I started porting the mod... I want the stikmen to act exactly as Abigail does for Wendy.... for all players... because these stikmen are supposed to be pets for all players! Smiley, Angry, and Fantabulous are supposed to be able to share their stikmen with other people so Wilson can have his own stikmen and so can Wolfgang and even WX-78! With this power the stick people are a great help to the entire team no matter what! (unless they are fantabulous/angry and have bad internet connection or are REALLY awful at the game... or both...) I just want it so that they leave with their leader and come back with their leader and when the server owner quits the stikmen don't decide to abandon him! With the same values as when they left of course... (all the stikmen are given a set name and the default stikmen are given a set color that makes their body and talker text that color!) I figured since I've been at this all damn day and still have not been able to figure it out I'd just plop it on the forums and continue working on it regardless (I kinda need the mod finished by Friday night to super super super early Saturday morning USA time) Thank you to those of you who are willing to teach a young pupil such as I! I really hope that one day I will be as good at DST coding as I am at DS coding c: Edited June 14, 2015 by Fidooop Link to comment Share on other sites More sharing options...
Seiai Posted June 12, 2015 Share Posted June 12, 2015 (edited) @Fidooop,1) they run from you because of a parameter in the follow behaviour in the brain. u cant make that work for other players, but u can use the runaway behaviour, just look into other brains for how they use it.2) i'll take a blind guess and say that the "companion"-tag might help with that?3) yeah, that's a bit tricky, u might try to have your mod make a custom savefunction and custom loadfunction that applies to all playerprefabs(with some afterprefabinit-function or something), and saves/loades your creatures and then call the regular save/loadfunctions, that the character had.Alternatively u could try to always just leave the creatures in the game, but hide them from the scene(theres an actual hidefromscene function) and remember their master(i think u would have to use some user_id or something for that, i dont think just saving the prefab is enough), so they can pop back in, when he rejoins the game. Edited June 12, 2015 by Seiai Link to comment Share on other sites More sharing options...
Fidooop Posted June 12, 2015 Author Share Posted June 12, 2015 @Fidooop,1) they run from you because of a parameter in the follow behaviour in the brain. u cant make that work for other players, but u can use the runaway behaviour, just look into other brains for how they use it.2) i'll take a blind guess and say that the "companion"-tag might help with that?3) yeah, that's a bit tricky, u might try to have your mod make a custom savefunction and custom loadfunction that applies to all playerprefabs(with some afterprefabinit-function or something), and saves/loades your creatures and then call the regular save/loadfunctions, that the character had.Alternatively u could try to always just leave the creatures in the game, but hide them from the scene(theres an actual hidefromscene function) and remember their master(i think u would have to use some user_id or something for that, i dont think just saving the prefab is enough), so they can pop back in, when he rejoins the game.lol that's what I figured for 1 and 2 and it works perfectly now except for issue number 3 which is being a pain in my butt like no other D: Link to comment Share on other sites More sharing options...
Fidooop Posted June 13, 2015 Author Share Posted June 13, 2015 (edited) WOOHOO! it's SO close to working! After a long day trying to figure out how I was going to do it (and studying a bunch on DST's code) I finally managed to whip up a component that saved all the stikmen properly! C: local StikmenLeader = Class(function(self, inst) self.inst = instself.stikmen = {}end) function StikmenLeader:OnSave()local datatable = {}local i = 1if #self.stikmen > 0 thenfor k,v in pairs(self.stikmen) dodatatable = v:GetSaveRecord()i = i + 1endendreturn { stikmen = datatable}end function StikmenLeader:OnLoad(data)if data.stikmen ~= nil and #data.stikmen > 0 thenfor k,v in pairs(data.stikmen) dolocal stikmen = SpawnSaveRecord(v)if stikmen.components.follower.leader ~= self.inst then stikmen.components.follower:SetLeader(self.inst) endtable.insert(self.stikmen, stikmen)endendend function StikmenLeader:DespawnStikmen() if #self.stikmen > 0 thenfor k,v in pairs(self.stikmen) dov:Remove()end endend StikmenLeader.OnRemoveEntity = StikmenLeader.DespawnStikmen return StikmenLeader I still have one major problem though.... it's not tracking when I despawn... D:is there an event I can listen for or something? anything that I can use to remove all stikmen following the despawning leader from the world? because otherwise every time people leave and come back they will duplicate their stikmen! I don't want that... :L Edited June 13, 2015 by Fidooop Link to comment Share on other sites More sharing options...
CremeLover Posted June 13, 2015 Share Posted June 13, 2015 (edited) @FidooopI haven't actually gone trough your code, but I think this might be what you're looking for inst:ListenForEvent("ms_playerdespawn", function) Edited June 13, 2015 by CremeLover Link to comment Share on other sites More sharing options...
Seiai Posted June 13, 2015 Share Posted June 13, 2015 (edited) @Fidooop, u can also add an OnDespawn function exactly the same way that u can add an OnSave function.also, u can set inst.persists=false in your creatures, so they dont get saved in the gameworld. Edited June 13, 2015 by Seiai Link to comment Share on other sites More sharing options...
Fidooop Posted June 14, 2015 Author Share Posted June 14, 2015 the problem has been solved! I had to postinit a component with onsave/onload functions and then hijack any ondespawns (if there were any) with a new ondespawn that ran the old despawn after it did it's work to all players! if GLOBAL.TheNet:GetIsServer() theninst:AddComponent("stikmenleader")endinst.olddespawn = nilif inst.OnDespawn ~= nil and inst.olddespawn == nil then inst.olddespawn = inst.OnDespawn endinst.OnDespawn = function(inst)if inst.olddespawn ~= nil then inst:olddespawn(inst) endif #inst.components.stikmenleader.stikmen > 0 then for k,v in pairs(inst.components.stikmenleader.stikmen) do v:Remove() end endend and this is the component: local StikmenLeader = Class(function(self, inst) self.inst = instself.stikmen = {}end) function StikmenLeader:OnSave()local datatable = {}local i = 1if #self.stikmen > 0 thenfor k,v in pairs(self.stikmen) dodatatable = v:GetSaveRecord()i = i + 1endendreturn { stikmen = datatable}end function StikmenLeader:OnLoad(data)if data.stikmen ~= nil and #data.stikmen > 0 thenfor k,v in pairs(data.stikmen) dolocal stikmen = SpawnSaveRecord(v)if stikmen.components.follower.leader ~= self.inst then stikmen.components.follower:SetLeader(self.inst) endtable.insert(self.stikmen, stikmen)endendend return StikmenLeader 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