HeK Posted April 13, 2013 Share Posted April 13, 2013 Hello there forum, I have been working on a small script, but i have some issues, those issues are, that when i shoot the ped it displays the text in the corner of the screen but the text doesn't stay there for even a second, everytime i shoot it displays and it's gone in a millisecond. Another thing, is that i have used "loss" i have been following some Wiki stuff to learn more about loss, but it seems not to show the real damage i have taken from the ped, it normaly shows 8, 7, etc. Shouldn't it show for example, with a 1 shot kill. "100"? I'd just like to know what i should use and the proper stuff to make this work. I'm a beginner, so i'm sorry if anything of this stuff is really stupid to learn, and thanks for your attention. Here's the code: local screenWidth, screenHeight = guiGetScreenSize ( ) kill = {} addEventHandler("onClientPedDamage",root, function ( attaker, weapon, loss) local lostHealth = loss if ( attaker and attaker == localPlayer ) then if ( kill[localPlayer] ) then killTimer(kill[localPlayer]) end dxDrawText ( lostHealth, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) dxDrawText ( lostHealth, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) kill[localPlayer] = setTimer(dxDrawText,5000,1,red) end end ) Link to comment
PaiN^ Posted April 13, 2013 Share Posted April 13, 2013 dx functions requires onClientRender event so they work .. Link to comment
HeK Posted April 13, 2013 Author Share Posted April 13, 2013 Then how am i supposed to make the text display when the player is getting shot? I tried with onClientRender and nothing happens. Link to comment
Max+ Posted April 13, 2013 Share Posted April 13, 2013 It's makeno sense the Event is onClientPedDamage and You defined attacker like this if ( attaker and attaker == localPlayer ) then it's worng because it's for players use should use if ( attaker and (getElementType(attacker) == 'Ped' ) then ... and use should use this also , losshealth = getElementHealth() Link to comment
PaiN^ Posted April 13, 2013 Share Posted April 13, 2013 Not Tested ! function draw ( ) dxDrawText ( tostring(loss), 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) end addEventHandler ( 'onClientPlayerDamage', root, function ( attacker, weapon, _, loss ) if attacker and attacker ~= source then addEventHandler ( 'onClientRender', root, draw ); messageTimer = setTimer ( removeEventHandler, 5000, 1, 'onClientRender', draw ); end end ) Link to comment
Max+ Posted April 13, 2013 Share Posted April 13, 2013 function draw ( ) dxDrawText ( tostring(loss), 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) end addEventHandler ( 'onClientRender', root, draw ) addEventHandler ( 'onClientPedDamage', root, function ( attacker, weapon, _, loss ) if attacker and getElementType(attacker) == 'ped' then draw ( ) messageTimer = setTimer ( removeEventHandler, 5000, 1, 'onClientRender', draw ); end end ) Link to comment
codeluaeveryday Posted April 14, 2013 Share Posted April 14, 2013 Both your codes will not work, loss is not defined in the client render. function drawDamage ( ) dxDrawText ( damageLoss, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) end addEventHandler ( 'onClientPedDamage', root, function ( attacker, weapon, _, loss ) if attacker and getElementType(attacker) == 'ped' then damageLoss = tostring(loss) addEventHandler ( 'onClientRender', root, drawDamage ) messageTimer = setTimer ( removeEventHandler, 5000, 1, 'onClientRender', drawDamage ) end end ) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now