Jump to content

How to damage yourself? (using the Player script)


Kenneth Nyström
 Share

Recommended Posts

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

.......

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

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