Kenneth Nyström Posted January 10, 2019 Share Posted January 10, 2019 Hello: need assistance to figure out a small script (to use within the "basic" player script) to give my own player damage when pressing a certain key: OR Just using a keyhit (Key.U) to trigger a respawn (within the "player script) ( to have the player be able to get out of situations they are stuck in or have fallen thru the map) .......................... I thought the below would be enough...but I cant get it to work: (my Health amount is 100: and I tried using the script.hurt) ................. if window:KeyHit(Key.U) then script:hurt (100) end end ........... I also tried using self.health = self.health - self.health (in several configs and a bunch of other ways i have forgotten about now after 3 hours of trying to figure this one out.) .......... As said I want to be able to press a key to lower my health so I can use/trigger the ingame respawn function if the player either gets stuck or falls thru the map (after that) (and damaging my player health logicly should been the easiest way to do it; as that would trigger the respawn function: but nah, it wasnt that easy at all.) ....... Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 10, 2019 Share Posted January 10, 2019 Without seeing the actual script you have right now, we can only guess as to why it doesn't work. The script:hurt() function looks a little of. I think you want to use: if window:KeyHit(Key.U) then self:hurt (100) end See this tutorial on functions https://www.youtube.com/watch?v=x9Wi8Rh7M58 Quote Link to comment Share on other sites More sharing options...
Kenneth Nyström Posted January 10, 2019 Author Share Posted January 10, 2019 5 hours ago, AggrorJorn said: Without seeing the actual script you have right now, we can only guess as to why it doesn't work. The script:hurt() function looks a little of. I think you want to use: if window:KeyHit(Key.U) then self:hurt (100) end See this tutorial on functions https://www.youtube.com/watch?v=x9Wi8Rh7M58 Yes that is exactly what I thought it would be, but somehow it doesnt work. (head began spinning after hours of it not working althou it looked like it should be working) will go bk and look at it again now after an nights sleep, but yeah it looks like I originally thought... hmm. and I pretty much used the basic "player" template that leadwerks comes with with no major changes. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 10, 2019 Share Posted January 10, 2019 Maybe the lowercase "h" to a capital? if window:KeyHit(Key.U) then self:Hurt(100) <----- end Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2019 Share Posted January 10, 2019 Attach the entire script. It'll be easier to see what's wrong. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 10, 2019 Share Posted January 10, 2019 You just have to put this under the UpdateWorld() function: if window:KeyHit(Key.U) then self:Hurt(100) end 2 Quote Link to comment Share on other sites More sharing options...
Kenneth Nyström Posted January 11, 2019 Author Share Posted January 11, 2019 2 hours ago, havenphillip said: You just have to put this under the UpdateWorld() function: if window:KeyHit(Key.U) then self:Hurt(100) end Yeah this solved it; (thought I had put it under that in atleast 4 variants) Thank you (and the other commenters) for the assistance, Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 11, 2019 Share Posted January 11, 2019 Please, for future posts, attach your entire script in the question (and in code format). The community wants to help you and the more information you provide, the faster you are going to get a solution. 1 Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted January 12, 2019 Share Posted January 12, 2019 Script.hurt1 = (randomglobal) if window:KeyHit(Key.U) then player.health = player.health - self.hurt1 end if you do it this way. You can then add extra if conditions elsewhere that change the randomglobal. Changing the amount of damage you deal to yourself. 1 Quote Link to comment Share on other sites More sharing options...
Kenneth Nyström Posted January 13, 2019 Author Share Posted January 13, 2019 On 1/11/2019 at 9:36 AM, AggrorJorn said: Please, for future posts, attach your entire script in the question (and in code format). The community wants to help you and the more information you provide, the faster you are going to get a solution. Its the basic "player" script that comes with Leadwerks...so really no need to attach the script... 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.