Crazybait24 Posted January 5, 2015 Share Posted January 5, 2015 I was wondering if it were at all possible to make neutralcreatures follow/attack me when a key is pressed or held down...Such as making me like some sort of bait or trap Link to comment Share on other sites More sharing options...
rezecib Posted January 6, 2015 Share Posted January 6, 2015 @Crazybait24, That sounds quite difficult. You'd need a key handler attached to custom RPCs (which we can't do nicely yet), as well as server-side modifications to the brains of the creatures... All very messy stuff. Link to comment Share on other sites More sharing options...
Crazybait24 Posted January 6, 2015 Author Share Posted January 6, 2015 I'm not nearly that good at lua. xD I guess I'll have to do something else... Link to comment Share on other sites More sharing options...
Kzisor Posted January 6, 2015 Share Posted January 6, 2015 (edited) @rezecib, I actually figured out a really simple way to 'hack' it together by using Actions. @Crazybait24, the following code will get you started on your way to making this a reality, however, you will need to put in a lot of time and effort to actually finish it. This code will specifically contains key press/down handling, communication from client to server and a demonstration of how it works by altering your health upon key press. modmain.lualocal function OnKeyPressed(inst, data) --if data.player == GLOBAL.ThePlayer then if data.key == GLOBAL.KEY_T then print("T key has been pressed.") if GLOBAL.TheWorld.ismastersim then -- Since we are the server, do the action on the server.act.target.components.health:SetCurrentHealth(1)act.target.components.health:DoDelta(0) else GLOBAL.SendRPCToServer(GLOBAL.RPC.DoWidgetButtonAction, GLOBAL.ACTIONS.BECOMEBAIT.code, inst, GLOBAL.ACTIONS.BECOMEBAIT.mod_name) end end --endend Wilson = function(self) self:AddComponent("keyhandler") self:ListenForEvent("keypressed", OnKeyPressed) return selfend AddPrefabPostInit("wilson", Wilson) local BECOMEBAIT = GLOBAL.Action()BECOMEBAIT.str = "BecomeBait"BECOMEBAIT.id = "BECOMEBAIT"BECOMEBAIT.fn = function(act) act.target.components.health:SetCurrentHealth(1) act.target.components.health:DoDelta(0) return trueend AddAction(SETHEALTH) scripts/components/keyhandler.lualocal KeyHandler = Class(function(self, inst) self.inst = inst self.handler = TheInput:AddKeyHandler(function(key, down) self:OnRawKey(key, down) end )end) function KeyHandler:OnRawKey(key, down) if (key and not down) and not IsPaused() then ThePlayer:PushEvent("keypressed", {player = ThePlayer, key = key}) elseif key and down and not IsPaused() then ThePlayer:PushEvent("keydown", {player = ThePlayer, key = key}) endend return KeyHandler Alter the BECOMEBAIT.fn to suit your needs. This will get you started with the set-up, next you will need to figure out how to make creatures follow you. Edited January 6, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Crazybait24 Posted January 6, 2015 Author Share Posted January 6, 2015 Thanks for the help but I think I'll try to do this later when I become more familiar with lua Link to comment Share on other sites More sharing options...
Crazybait24 Posted January 6, 2015 Author Share Posted January 6, 2015 Actually thinking about it... With this code you sent me why would I need to have them just follow me? My character is on the workshop but I'm editing in some things and making it more then just a character but what I am getting at is if I use said code I will be able to do what I was wanting... I just wanted to make my character get attacked/followed by creatures which is what you did in the code(hopefully not 100%, haven't tested it). With them now being able to attack me with key_t my character no londer has to hit said beast to make it mad. So in any case I'll just try that later after finishing a character for a friend.. Thanks @Kzisor and @rezecib I might just be able to make this work in a way that I need it to. Link to comment Share on other sites More sharing options...
Kzisor Posted January 6, 2015 Share Posted January 6, 2015 @Crazybait24, the code that I posted, doesn't make creatures attack you. It displays how to use key handlers and RPC in a simple fashion through adding a new Action. if you are wanting to get creatures to follow and/or attack you, you will need different code and or actions on the server. However, what I posted fives you a great start. Link to comment Share on other sites More sharing options...
Aquaterion Posted January 7, 2015 Share Posted January 7, 2015 Sounds like it would be a cool Tank trait. Making everything Aggro on you. If I knew how I would make it like a threat system, that when u press the button, if the monster is ALREADY AGGRO on someone/something else, it changes the aggro to you. Link to comment Share on other sites More sharing options...
Crazybait24 Posted January 7, 2015 Author Share Posted January 7, 2015 Aquaterion basically discribed what I'm after 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