• NextBot GetPlayerColor()
    6 replies, posted
Is there anyway to add a shared GetPlayerColor() function to NextBots, so i can color them over mat.Proxy("PlayerColor") ? Basically i want a NextBot to have the same Color for his clothing on all clients. I'm stuck at this problem for a few hours now. Since NWVars seem not to work with NextBots. Thanks in advance -Lolle
(ATTENTION! This is a old way to change the color of NextBot's clothings and things.) [I]This will not be possible without heavy modifications of the nextbot.[/I] (Don't believe this.) And the major problem is: Are you using a player model on the nextbot (Not NPC model)? If yes, you would have to edit to somethings like this: [CODE]function DoNextBotColor(ent,colors_vector) mat.Proxy("PlayerColor") -- Basically, your code to change color on the clientside end net.Receive("nextbotcolor",function() DoNextBotColor(net.ReadEntity(),net.ReadVector()) end) function ENT:GetNextBotColor() return self.NextBotColor end function ENT:SetNextBotColor(colors_vector) self.NextBotColor=colors_vector net.Start("nextbotcolor") net.WriteEntity(self) net.WriteVector(colors_vector) net.Broadcast() end[/CODE] If no, well, you will have to change the color using textures functions. (Since the recents updates from Garry's mod, you are now able to change materials of models, I will let someone else explain this. I don't know very much about materials changes functions...)
Pretty sure you can use this as a clientside hook: [url]http://wiki.garrysmod.com/page/GM/OnEntityCreated[/url] to give your nextbot a lua function called GetPlayerColor. That's all you have to do. The problem why you can't do it from NEXTBOT:* hooks is because they are serverside only.
[QUOTE=Robotboy655;48810570]Pretty sure you can use this as a clientside hook: [url]http://wiki.garrysmod.com/page/GM/OnEntityCreated[/url] to give your nextbot a lua function called GetPlayerColor. That's all you have to do. The problem why you can't do it from NEXTBOT:* hooks is because they are serverside only.[/QUOTE] That's exactly what i tried. But I want to use random colors or a random color from a preset table. And i want the color from each nextbot to match on all clients. I tried to call GM:OnEntityCreated server side and send all the clients the same color for the nextbot created, but like you said nextbots a different on client and server so that didn't work. EDIT: And thank you Gedo for your approach I will give it a shot once I am home.
I think I'm gonna post here again just for future reference. So here is my workaround to give nextbots that use playermodels a GetPlayerColor() function that is synced on all clients! Basically I use the ENTITY:SetColor() function to network the color between client and server. That way i can set the ent color once in my NEXTBOT:Initialize() and convert it to a playercolor vector client side once its created. Nextbot Code: [LUA] function ENT:Initialize() self:SetColor(Color(123,254,50)) end [/LUA] Clientside hooks: [LUA]function addPlayerColorOnCreate( ent ) if ent:GetClass() == "npc_walker" then --"npc_walker" is my nextbot class name ent.WalkerColor = Vector(ent:GetColor().r / 255, ent:GetColor().g / 255, ent:GetColor().b / 255) --Convert color table to a Vector function ent:GetPlayerColor() return self.WalkerColor end --return the color vector ent:SetColor(Color(255, 255, 255, 255)) --set the color back to the default/no color. end end hook.Add("OnEntityCreated", "customnextbotcolors", addplayerColorOnCreate) function resetNextbotColor( ent, shouldtransmit ) if shouldtransmit and ent:GetClass() == "npc_walker" then ent:SetColor(Color(255,255,255,255)) --we need to reset the color everytime the entity gets transmitted to the client if you don't want them to have coloured heads end end hook.Add("NotifyShouldTransmit", "resetcustomcolors", resetNextbotColor)[/LUA]
Do not EVER use GM:* hooks outside of gamemodes, use the hook.Add function. [editline]3rd October 2015[/editline] Also I'd suggest you use NWVector for this, not SetColor ( for models that do not support coloring, etc )
Yeah sorry thats my fail I use the bots in a gamemode i will change it asap. And as far as I can tell SetNWVector isn't working.
Sorry, you need to Log In to post a reply to this thread.