Jump to content

Ridiculous Follower Problems (pls help asap!)


Recommended Posts

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=458882464

http://steamcommunity.com/sharedfiles/filedetails/?id=457709114

They all have cute little quotes and random names! and there are even 3 different types of stikmen too

but 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 by Fidooop
Link to comment
Share on other sites

@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 by Seiai
Link to comment
Share on other sites

@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

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 = inst
self.stikmen = {}
end)
 
function StikmenLeader:OnSave()
local datatable = {}
local i = 1
if #self.stikmen > 0 then
for k,v in pairs(self.stikmen) do
datatable = v:GetSaveRecord()
i = i + 1
end
end
return { stikmen = datatable}
end
 
function StikmenLeader:OnLoad(data)
if data.stikmen ~= nil and #data.stikmen > 0 then
for k,v in pairs(data.stikmen) do
local stikmen = SpawnSaveRecord(v)
if stikmen.components.follower.leader ~= self.inst then stikmen.components.follower:SetLeader(self.inst) end
table.insert(self.stikmen, stikmen)
end
end
end
 
function StikmenLeader:DespawnStikmen()
    if #self.stikmen > 0 then
for k,v in pairs(self.stikmen) do
v:Remove()
end
    end
end
 
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 by Fidooop
Link to comment
Share on other sites

@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 by Seiai
Link to comment
Share on other sites

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! :D

 

if GLOBAL.TheNet:GetIsServer() then

inst:AddComponent("stikmenleader")
end
inst.olddespawn = nil
if inst.OnDespawn ~= nil and inst.olddespawn == nil then inst.olddespawn = inst.OnDespawn end
inst.OnDespawn = function(inst)
if inst.olddespawn ~= nil then inst:olddespawn(inst) end
if #inst.components.stikmenleader.stikmen > 0 then for k,v in pairs(inst.components.stikmenleader.stikmen) do v:Remove() end end
end
 
and this is the component:
 
local StikmenLeader = Class(function(self, inst)
    self.inst = inst
self.stikmen = {}
end)
 
function StikmenLeader:OnSave()
local datatable = {}
local i = 1
if #self.stikmen > 0 then
for k,v in pairs(self.stikmen) do
datatable = v:GetSaveRecord()
i = i + 1
end
end
return { stikmen = datatable}
end
 
function StikmenLeader:OnLoad(data)
if data.stikmen ~= nil and #data.stikmen > 0 then
for k,v in pairs(data.stikmen) do
local stikmen = SpawnSaveRecord(v)
if stikmen.components.follower.leader ~= self.inst then stikmen.components.follower:SetLeader(self.inst) end
table.insert(self.stikmen, stikmen)
end
end
end
 
return StikmenLeader

 

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...