Jump to content

Can someone give me this script?


GamerDeMTA

Recommended Posts

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 by Guest
Link to comment

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 
) 

Link to comment

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 
) 

Link to comment
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.

Link to comment
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.

Link to comment
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 
) 

Link to comment

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 by Guest
Link to comment

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 
   ) 
    

Link to comment
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 .

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...