Jump to content

Set damage made by boss bot


Kahlua

Recommended Posts

Hello everybody, I'm new in LUA scripting, I followed tutorials, it helped me very well, thanks for that, but I have a problem

I've made a boss bot (Alex Mercer) for my server, and I want it to use no weapons, and to instant kill players in sight when this boss hits them, here's the script

outputChatBox ("Alex Mercer is attacking Los Santos ! Stop him before he transforms the whole city into a giant hive !",getRootElement(), 255, 0, 0, true ) 
function boss ( ) 
      Alex = exports [ "slothBot" ]:spawnBot ( 1479.33984375, -1675.4399414063, 14.0406875, 90, 308, 0, 0, Alex, 0,         "hunting", true ) 
      exports.extra_health:setElementExtraHealth ( Alex, 75000 ) 
      myBlip = (createBlipAttachedTo ( Alex, 41 )) 
      setBotWeapon (Alex, 0) 
      setElementData ( Alex, "alex", true  ) 
 end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), boss ) 
  
function alexattack ( attacker, weapon, bodypart ) 
    if (attacker) then 
        if getElementType ( attacker ) == "ped" then 
            if (getElementData (attacker, "alex") == true) then 
                local playerHealth = getElementHealth ( getLocalPlayer() ) 
                if playerHealth > 15 then 
                    setElementHealth ( source, playerHealth - 500 ) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), alexattack ) 
  
function money (theKiller) 
if (source == Alex) then 
givePlayerMoney(theKiller,math.random(5000000,10000000)) 
outputChatBox ( getPlayerName ( theKiller ) .. " stopped Alex Mercer ! But the virus will never die ...",getRootElement(), 10, 255 , 10, true ) 
end 
end 
addEvent("onBotWasted", true) 
addEventHandler("onBotWasted", getRootElement(), money) 
  

The boss is working, he have 75.000 HP, he go attack players who shot him, and we he got killed, the player who killed him get rewarded, the problem is that the boss isn't killing the players he attacks with 1 hit (it does only normal punch damage)

If somebody can help me to fix this, i've tried everything I could do, I'm kinda desperate to see that my script isn't working properly.

Best regards

Kahlua

Link to comment

Try changing this

  
                if playerHealth > 15 then 
                    setElementHealth ( source, playerHealth - 500 ) 
                end 

into this

  
killPed(source) 
  

PD: You must also move this event server-side. There's no problem in doing that.

Link to comment

I modified like you said, but it's not working, even server-sided :(

outputChatBox ("Alex Mercer is attacking Los Santos ! Stop him before he transforms the whole city into a giant hive !",getRootElement(), 255, 0, 0, true ) 
function boss ( ) 
      Alex = exports [ "slothBot" ]:spawnBot ( 1479.33984375, -1675.4399414063, 14.0406875, 90, 308, 0, 0, Alex, 0,         "hunting", true ) 
      exports.extra_health:setElementExtraHealth ( Alex, 75000 ) 
      myBlip = (createBlipAttachedTo ( Alex, 41 )) 
      setBotWeapon (Alex, 0) 
      setElementData ( Alex, "alex", true  ) 
 end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), boss ) 
  
function alexattack ( attacker, weapon, bodypart ) 
    if (attacker) then 
        if getElementType ( attacker ) == "ped" then 
            if (getElementData (attacker, "alex") == true) then 
                local playerHealth = getElementHealth ( getLocalPlayer() ) 
                 killPed(source) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), alexattack ) 
  
function money (theKiller) 
if (source == Alex) then 
givePlayerMoney(theKiller,math.random(5000000,10000000)) 
outputChatBox ( getPlayerName ( theKiller ) .. " stopped Alex Mercer ! But the virus will never die ...",getRootElement(), 10, 255 , 10, true ) 
end 
end 
addEvent("onBotWasted", true) 
addEventHandler("onBotWasted", getRootElement(), money) 
  

I also tried to put this instead of what you say, nothing changes :x

  
killPed( sourcePlayer, attacker, 0) 
  

Link to comment

try

outputChatBox ("Alex Mercer is attacking Los Santos ! Stop him before he transforms the whole city into a giant hive !",getRootElement(), 255, 0, 0, true ) 
function boss ( ) 
      Alex = exports [ "slothBot" ]:spawnBot ( 1479.33984375, -1675.4399414063, 14.0406875, 90, 308, 0, 0, Alex, 0,         "hunting", true ) 
      exports.extra_health:setElementExtraHealth ( Alex, 75000 ) 
      myBlip = (createBlipAttachedTo ( Alex, 41 )) 
      setBotWeapon (Alex, 0) 
      setElementData ( Alex, "alex", true  ) 
 end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), boss ) 
  
function alexattack ( attacker, weapon, bodypart ) 
    if (attacker) then 
        if getElementType ( attacker ) == "ped" then 
            if (getElementData (attacker, "alex") == true) then 
                 killPed(source,attacker) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerDamage",root, alexattack ) 
  
function money (theKiller) 
if (source == Alex) then 
givePlayerMoney(theKiller,math.random(5000000,10000000)) 
outputChatBox ( getPlayerName ( theKiller ) .. " stopped Alex Mercer ! But the virus will never die ...",getRootElement(), 10, 255 , 10, true ) 
end 
end 
addEvent("onBotWasted", true) 
addEventHandler("onBotWasted", getRootElement(), money) 
  

Link to comment

ok try again

server

  
outputChatBox ("Alex Mercer is attacking Los Santos ! Stop him before he transforms the whole city into a giant hive !",getRootElement(), 255, 0, 0, true ) 
function boss ( ) 
      Alex = exports [ "slothBot" ]:spawnBot ( 1479.33984375, -1675.4399414063, 14.0406875, 90, 308, 0, 0, Alex, 0,         "hunting", true ) 
      exports.extra_health:setElementExtraHealth ( Alex, 75000 ) 
      myBlip = (createBlipAttachedTo ( Alex, 41 )) 
      setElementData ( Alex, "alex", true  ) 
      setBotWeapon (Alex, 0) 
 end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), boss ) 
  
function money (theKiller) 
if (source == Alex) then 
givePlayerMoney(theKiller,math.random(5000000,10000000)) 
outputChatBox ( getPlayerName ( theKiller ) .. " stopped Alex Mercer ! But the virus will never die ...",getRootElement(), 10, 255 , 10, true ) 
end 
end 
addEvent("onBotWasted", true) 
addEventHandler("onBotWasted", getRootElement(), money) 
  
addEvent("KillByAlex",true) 
addEventHandler("KillByAlex",root, 
function(atacker) 
killPed(source,atacker) 
end) 
  

Client

  
 function alexattack ( attacker, weapon, bodypart ) 
    if (attacker) then 
            if (getElementData (attacker, "alex") == true) then 
                triggerServerEvent("KillByAlex",source,attacker)  
            end 
        end 
    end 
addEventHandler ( "onClientPlayerDamage",root, alexattack ) 
  

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