Jump to content

Recommended Posts

Posted

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

.......

 

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

Posted
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, 

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

  • Like 1
Posted
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...

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.

×
×
  • Create New...