GamerDeMTA Posted March 17, 2013 Posted March 17, 2013 I need this: When a player has 10 of health or less, It shows him in the screen a image called for example "image.png", in all the screen
GamerDeMTA Posted March 17, 2013 Author Posted March 17, 2013 Can you give me an example? because you said a GUI but I want an image
Jaysds1 Posted March 17, 2013 Posted March 17, 2013 (edited) Use these: guiCreateStaticImage --use this to create the image getElementHealth --use this to get the players health guiSetVisible --use this to set the image visible or not Example: local image = guiCreateStaticImage(0,0,300,100,"image.png",false) --create image before the script continues guiSetVisible(image,false) --hide the image before anyone sees it addEventHandler("onClientPlayerDamage",root,function() --triggers when the localPlayer gets damaged if getElementHealth(source)<=10 then --check if his health is 10 or less guiSetVisible(image,true) --set the hurt image visible elseif guiGetVisible(image) then --if the localPlayer health isn't 10 or less then check if the hurt image is still visible guiSetVisible(image,false) --set the hurt image not visible end end) Sorry for that little error, I've been scripting in JS lately. Edited March 18, 2013 by Guest
Castillo Posted March 17, 2013 Posted March 17, 2013 else if guiGetVisible(image) then That should be: elseif guiGetVisible(image) then
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Thanks and can you say me how to do this? I want to put when a player joins/respawns in freeroam he has skin, but I put the skin ID 1, but now I want to put the skin ID 1 and 2. See line 19 local spawnpoint addEventHandler("onResourceStart", resourceRoot, function() spawnpoint = getRandomSpawnPoint() resetMapInfo() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) if not isElement(player) then return end if get("spawnreset") == "onSpawn" then spawnpoint = getRandomSpawnPoint() end exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) repeat until setElementModel(player,1) fadeCamera(player, true) setCameraTarget(player, player) showChat(player, true) end function getRandomSpawnPoint () local spawnpoints = getElementsByType("spawnpoint") return spawnpoints[math.random(1,#spawnpoints)] end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerQuit",root, function () if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then spawnpoint = getRandomSpawnPoint() end end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 1800, 1, source) end )
Jaysds1 Posted March 18, 2013 Posted March 18, 2013 if you want to let them either have 1 or 2 just use math.random here: local spawnpoint addEventHandler("onResourceStart", resourceRoot, function() spawnpoint = getRandomSpawnPoint() resetMapInfo() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) if not isElement(player) then return end if get("spawnreset") == "onSpawn" then spawnpoint = getRandomSpawnPoint() end exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) repeat until setElementModel(player,math.random(0,2)) fadeCamera(player, true) setCameraTarget(player, player) showChat(player, true) end function getRandomSpawnPoint () local spawnpoints = getElementsByType("spawnpoint") return spawnpoints[math.random(1,#spawnpoints)] end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerQuit",root, function () if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then spawnpoint = getRandomSpawnPoint() end end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 1800, 1, source) end )
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 (edited) . Edited March 18, 2013 by Guest
Castillo Posted March 18, 2013 Posted March 18, 2013 local image = guiCreateStaticImage(0,0,300,100,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( "onClientPlayerDamage", localPlayer, function ( ) local health = getElementHealth ( source ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) end end ) Try that and see what it outputs to chat.
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Still doesn't works I don't know why, I put my health as 10 and the image isn't showed and the outputchatbox too
Castillo Posted March 18, 2013 Posted March 18, 2013 You set your health how? because it won't trigger that even for when you set your health by setElementHealth.
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 with the Panel or doing /sethealth I set my health
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Now it works but the IMG is in a corner Can you say me how to put the Image around all the screen?
Castillo Posted March 18, 2013 Posted March 18, 2013 local sx, sy = guiGetScreenSize ( ) local image = guiCreateStaticImage(0,0,sx,sy,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( "onClientPlayerDamage", localPlayer, function ( ) local health = getElementHealth ( source ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) end end ) Try that.
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Gracias Castillo, but it has a bug. Can you say me how to fix this? When I get killed the IMG stays and when I recuperate health too.
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 But I have a script that recuperates health in my server, and when the player recuperates the health he still has the Image, without die, so what about that?
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Can give me a full code with when you die and recuperate health the image sets false / isn't in screen?
PaiN^ Posted March 18, 2013 Posted March 18, 2013 local sx, sy = guiGetScreenSize ( ) local image = guiCreateStaticImage(0,0,sx,sy,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( "onClientPlayerDamage", localPlayer, function ( ) setTimer ( function ( ) local health = getElementHealth ( source ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) else guiSetVisible ( image, false ) end end, 5000, 0 ) end )
GamerDeMTA Posted March 18, 2013 Author Posted March 18, 2013 Why SetTimer? Does that script to hide the IMG when the player dies and recuperate health?
PaiN^ Posted March 18, 2013 Posted March 18, 2013 I used a timer that keeps repeating to check the players health, If it was more than 10 then the image is hidden, Put if his health was 10 or less the picture will appear ... If it didn't work tell me ..
iPrestege Posted March 18, 2013 Posted March 18, 2013 (edited) Try this : local sx, sy = guiGetScreenSize ( ) local image = guiCreateStaticImage(0,0,sx,sy,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( "onClientPlayerDamage", localPlayer, function ( ) local health = getElementHealth ( localPlayer ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) end end ) addEventHandler ( "onClientPlayerWasted", localPlayer, function () guiSetVisible ( image, false ) end,false) Edited March 18, 2013 by Guest
X-SHADOW Posted March 18, 2013 Posted March 18, 2013 Fhode you didn't check the player Health if it changes . This Will Fix the Problem . local sx, sy = guiGetScreenSize ( ) local image = guiCreateStaticImage(0,0,sx,sy,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( 'onClientPlayerDamage', localPlayer, function ( ) setTimer( function( ) local health = getElementHealth ( source ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) end end, 1000, 0 ) end ) addEventHandler( 'onClientPlayerWasted', localPlayer, function ( ) guiSetVisible( image, false ) end )
iPrestege Posted March 18, 2013 Posted March 18, 2013 Fhode you didn't check the player Health if it changes .This Will Fix the Problem . local sx, sy = guiGetScreenSize ( ) local image = guiCreateStaticImage(0,0,sx,sy,"image.png",false) guiSetVisible ( image, false ) addEventHandler ( 'onClientPlayerDamage', localPlayer, function ( ) setTimer( function( ) local health = getElementHealth ( source ) outputChatBox ( "Your health is: ".. math.floor ( health ) .."%" ) if ( health <= 10 ) then guiSetVisible ( image, true ) end end, 1000, 0 ) end ) addEventHandler( 'onClientPlayerWasted', localPlayer, function ( ) guiSetVisible( image, false ) end ) lol i think he just want to remove the image when the player die as what he say in page 1 . You're code wrong .
X-SHADOW Posted March 18, 2013 Posted March 18, 2013 no it's not wrong why it well be worng ? and also he say when player he got damge and die the image wont hide because the health he should use setTimer .
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