Russell Posted January 24, 2020 Share Posted January 24, 2020 I've got an object on my game with a little tutorial showed when we interact with it. But as player, we can move around when the tutorial is active. Is there any way to disable Player movement and Enable when i wan? Thanks a lot!! Quote Link to comment Share on other sites More sharing options...
Russell Posted January 24, 2020 Author Share Posted January 24, 2020 I'm thinking about create a Global variable like "ReadingSomething" and a function on FPSPlayer.lua for change movementspeed when we are reading or not. But i don't know how develop this with code, i'm looking over the net for examples, and not able to find anything. Anyway i'm looking the code of the rest *.LUA on Leadwerks to learn the syntax to do this... Quote Link to comment Share on other sites More sharing options...
Josh Posted January 24, 2020 Share Posted January 24, 2020 7 minutes ago, Russell said: I'm thinking about create a Global variable like "ReadingSomething" and a function on FPSPlayer.lua for change movementspeed when we are reading or not. But i don't know how develop this with code, i'm looking over the net for examples, and not able to find anything. Anyway i'm looking the code of the rest *.LUA on Leadwerks to learn the syntax to do this... You would probably just want to add a variable to the player script like this: self.disableMovement = true And then add an if statement around the code that handles player input.. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Russell Posted January 24, 2020 Author Share Posted January 24, 2020 15 minutes ago, Josh said: You would probably just want to add a variable to the player script like this: self.disableMovement = true And then add an if statement around the code that handles player input.. Thank a lot Josh for your answer. I understand what are you saying, but i don't know how write code in LUA... I have a model (a switch) with 3 functions Script (ImageSwitch.lua). When we hit it, an image show centered on screen as i wanted. But I can walk and move away from the area with the image showed on screen. This is my code for show the image: --------ImageSwitch.lua---------- Script.HudTexture=""--string "Name Texture" local ShowedImage="No" function Script:Start() texture = Texture:Load("Materials/MyMaterials/"..self.HudTexture..".tex") textureEmpty = Texture:Load("Materials/MyMaterials/EmptyTexture.tex") end function Script:Use() if ShowedImage=="Yes" then ShowedImage="No" else ShowedImage="Yes" end end function Script:PostRender(context) if ShowedImage=="Yes" then context:SetBlendMode(Blend.Alpha) context:DrawImage(texture,context:GetWidth()/2-texture:GetWidth()/2,context:GetHeight()/2-texture:GetHeight()/2,texture:GetWidth(),texture:GetHeight()) end if ShowedImage=="No" then context:SetBlendMode(Blend.Alpha) context:DrawImage(textureEmpty,context:GetWidth()/2-textureEmpty:GetWidth()/2,context:GetHeight()/2-textureEmpty:GetHeight()/2,textureEmpty:GetWidth(),textureEmpty:GetHeight()) end end ------------------------ If I want our player to not be able to walk from place until the switch is turned off again, I have thought about putting a global variable to control it. But I don't know how to write the code to be able to change the "moveSpeed" of the FPSPlayer.lua when "ShowedImage" is YES in my ImageSwitch.lua Thanks a lot for your answer. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 24, 2020 Share Posted January 24, 2020 If you open up the FPSPlayer script you can see that the player itself will be passed into the Use() function: --Use the object, whatever it may be usableentity.script:Use(self) So you could add a value directly onto the player in your switch function: function Script:Use(player) player.disablemove = true if ShowedImage=="Yes" then ShowedImage="No" else ShowedImage="Yes" end end And then disable the player input in the FPSPlayer script if this value is set to true: if self.disablemove ~= true then if window:KeyDown(Key.W) then self.input[1]=self.input[1]+1 end if window:KeyDown(Key.S) then self.input[1]=self.input[1]-1 end if window:KeyDown(Key.D) then self.input[0]=self.input[0]+1 end if window:KeyDown(Key.A) then self.input[0]=self.input[0]-1 end end 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Russell Posted January 24, 2020 Author Share Posted January 24, 2020 Thank you very much Josh!!! Your code has been very useful to get exactly what I intended to do. Many thanks. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.