Jump to content

Any command to DISABLE Player movement when we USE something?


Russell
 Share

Recommended Posts

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...

Link to comment
Share on other sites

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..

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

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.

Link to comment
Share on other sites

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

 

  • Like 1
  • Thanks 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...