Jump to content

Super Punch


favarotop

Recommended Posts

Hello, I'm trying to make a script for the punch to be strong, which would take a large amount of life but not kill, the idea is to make the player have a power of a few seconds that if it hits another opponent it can cause a lot of damage to life. Does anyone know any way? I tried using the weapon's damage boost function, but it seems to work only with weapons that fire projectile

Link to comment

Hi,

local damage = 30
addEventHandler("onPlayerDamage", root, function(attacker, weapon)
  if isElement(attacker) and getElementType(attacker)=="player" then

    local health = getElementHealth(source) -- get health
    if weapon == 0 then -- is the weapon a fist?
      local expectedHealth = health-damage 
      if expectedHealth <= 0 then -- setting health to 0 causes sync issues and does not register the attacker as the killer. So we prevent this.
        killPed(player, attacker, weapon) -- kill and register the attacker as the killer
      else
        setElementHealth(player, expectedHealth) -- just damage the player
      end
    end
  end
end)

This should work, and explained it a little bit :). Might have some errors, been using OOP since forever.

Edited by DRW
Link to comment
On 16/08/2021 at 08:46, DRW said:

Oi,

  
    

     
       
          
       
      
    
  

Isso deve funcionar e explicou-o um pouco :). Pode haver alguns erros, uso OOP desde sempre.

How can I make this command work? I want what type I type / superpunch and that this command activates. Then deactivate, can you help me?

Link to comment

Hi,

That's a little bit more complicated to do it right here, but the things you should use are:

addCommandHandler() -- to register the command.
setElementData(player, "gamemode.superpunch", true) -- to activate/deactivate the user that's using a superpunch
getElementData(player, "gamemode.superpunch") -- to check if the superpunch is enabled for the player

Check the wiki for these functions.

Alternatively (and a better practice in terms of server performance, element data syncs between the clients which is not necessary for what you want to do) you could create a table and assign players to it and check against it but I believe you should learn about tables first!

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