Jump to content

[HELP]


Recommended Posts

23 minutes ago, Firespider said:

Hi! 

Which function can I use to damage the player?
 
 
 

Hi @Firespider welcome to MTA forum, i will help you with your question, i will send you a code, you can test it,There is no function to do damage in mta but we can do it yourself...

but maybe more needs to be added to the code so I madde a code for testing.

function takeDamage(player, attacker, damage_causing, bodypart, loss)
   setElementHealth(player, getElementHealth(player) - loss) --reduce player's health
   triggerEvent("onClientPlayerDamage", player, attacker, damage_causing, bodypart, loss) --notify onClientPlayerDamage event
end

addCommandHandler("dmg", 
  function()
     takeDamage(localPlayer, false, 19, 3, 50) --simulates the player taking a rocket damage to the torso
  end
)

 

If the player's imprisonment is less than the damage dealt, it may be necessary to trigger the onClientPlayerWasted event, to see the correct results,and also this is client side i didn't test it on server side.

I saw a small problem in the code and fixed it

Edited by Shady1
Link to comment
How can I insert this so that it takes damage when the hunger is low.
 
 
 
setPlayerHudComponentVisible("all", false)

local sx,sy = guiGetScreenSize();--1920,1080
local relx,rely = sx/1920,sy/1080;

local isHudVisible = true

 local stamina = 100
 
 local hunger = 100
 
 local hp = getElementHealth(localPlayer)
 
function Panel()




local armor = getPedArmor(localPlayer)

  if(isHudVisible) then
    dxDrawRectangle(sx*.8, sy*.010, sx*.13, sy*.150, tocolor(20, 30, 40, 200)) 
    dxDrawRectangle(sx*.8, sy*.009, sx*.130, sy*.02, tocolor(100, 110, 120, 125))-- HP ALAP
     dxDrawRectangle(sx*.8, sy*.009, sx*(.130*(hp/100)), sy*.02, tocolor(138, 10, 31, 255))
	dxDrawRectangle(sx*.8, sy*.05, sx*.130, sy*.02, tocolor(100, 110, 120, 125)) -- ARMOR ALAP
	  dxDrawRectangle(sx*.8, sy*.05, sx*(.130*(armor/100)), sy*.02, tocolor(77, 145, 144, 255))
	dxDrawRectangle(sx*.8, sy*.09, sx*.130, sy*.02, tocolor(100, 110, 120, 125)) -- ARMOR ALAP 
      dxDrawRectangle(sx*.8, sy*.09, sx*(.130*(stamina/100)), sy*.02, tocolor(77, 145, 144, 255))
    dxDrawRectangle(sx*.8, sy*.13, sx*.130, sy*.02, tocolor(100, 110, 120, 125)) -- ARMOR ALAP
      dxDrawRectangle(sx*.8, sy*.13, sx*(.130*(hunger/100)), sy*.02, tocolor(186, 148, 34, 255))	
  end
 end 
 addEventHandler("onClientRender", root, Panel)
 
 
 
 
 addEventHandler("onClientPreRender",root,
 function()
    if (stamina > 0) then  
      if (getPedMoveState(localPlayer) == "sprint") then  
          stamina = stamina-01
	else
	if (stamina < 100)  then
	    
	     stamina = stamina+01
        end
	end 
	
	if (stamina <= 15) then
      toggleAllControls(false)
	  		setTimer(setPedAnimation,300,1,localPlayer,"fat","idle_tired")
	else	    
	    toggleAllControls (true)
   		setPedAnimation(localPlayer)
	
end	  
end	 
 end
)

addCommandHandler("togg",
function()
      toggleAllControls(true)
	  
	  
end
)

setTimer ( function ()
    if (hunger > 0) then 
		hunger = hunger-1
        outputChatBox(hunger)
    if (hunger == 5) then
      outputChatBox("Egyél mert ehénfogsz halni.")
      hp = hp-01	  
	end
	end
end, 1, 0 )

 

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