Jump to content

Let Peds die faster!


Einheit-101

Recommended Posts

Posted

Hello Community,

I have written a little script that lets Peds die earlier, because

setElementHealth does not work for peds :shock:

The problem is, that the Peds die correctly :redhotevil:

But the Player that killed the Ped should get his 30 Dollar and he gets the money only if the script

knows, that the Player has killed this ped. My code down there kills the ped, but the Player gets no money.

I hope you understand what i mean^^

  
function zombiedamaged ( attacker, weapon, bodypart ) 
local health = getElementHealth ( source ) 
    if (health < 60) then 
    thePed = source 
    angreifer = attacker 
    triggerServerEvent("onDamage", getRootElement(), thePed, angreifer ) 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), zombiedamaged ) 
  

  
function damageHandler(thePed, angreifer) 
killPed(thePed) 
givePlayerMoney ( angreifer, 30 ) 
end 
addEvent("onDamage", true) 
addEventHandler("onDamage", getRootElement(), damageHandler) 
  

As alternative i would prefer setPedStat ( thePed, 24, 90)

(means: Ped name, MAX_HEALTH, value)

but setPedStat with max_health seems not to work^^

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted (edited)

try this

function zombiedamaged ( attacker, weapon, bodypart ) 
local health = getElementHealth ( source ) 
    if (health < 60) then 
    thePed = source 
    triggerServerEvent ("onDamage", getRootElement(), attacker, thePed, weapon) 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), zombiedamaged ) 

function damageHandler(killer, thePed, theWeapon) 
killPed(thePed, killer, theWeapon ) 
givePlayerMoney ( killer, 30 ) 
end 
addEvent("onDamage", true) 
addEventHandler("onDamage", getRootElement(), damageHandler) 

---------------

setPedStat ( source, 24, 1000 )  

work with me i tested it

Edited by Guest
CiTLh.png
Posted (edited)

LoL thanks TAPL, i found a similar way 1 minute ago!

Client:

  
function zombiedamaged ( attacker, weapon, bodypart ) 
    local health = getElementHealth ( source ) 
  
    if (health < 60) then 
    thePed = source 
    angreifer = attacker 
    triggerServerEvent("onDamage", angreifer, thePed ) 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), zombiedamaged ) 
  

Server:

  
function damageHandler(thePed) 
killPed(thePed) 
givePlayerMoney ( source, 30 ) 
end 
addEvent("onDamage", true) 
addEventHandler("onDamage", getRootElement(), damageHandler) 
  

Edited by Guest

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

So you tested "setPedStat ( source, 24, 1000 )" and it worked?

lol!

Btw. How much HP does an PED have? 1000? and whats the minimum Value for "setPedStat"?

they should have about 50% less than normal...

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

The maximun health a player/ped can have is 200%.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

***PUSH***

I got a Problem. At the beginning it worked well, but then i got more and more problems with that method.

Now is my question: how is it possible to get

setPedStat ( source, 24, 1000 )

to work? I tested some values like:

setPedStat ( source, 24, 2000 )

setPedStat ( source, 24, 500 )

setPedStat ( source, 24, 100 )

setPedStat ( source, 24, 50 )

But Nothings happening! Waste of Time! All Zombies have still very high health! It doesnt Work!

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

Just do setElementHealth in the zombies to a lower value, i.e 50%.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Well, then you are wrong, because I just set a ped health to 20%.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I used it via runcode, as it was just a simple test:

ped = createPed(299,x,y,z) 
setElementHealth(ped,20) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • 2 weeks later...
Posted

setElementHealth(ped,20)

CAN NOT WORK.

setElementHealth only works for vehicles and Players, not Peds and i tested it, the zombies still have 100%

i dont know what youre doing:

viewtopic.php?f=102&t=26375 (not my topic)

https://wiki.multitheftauto.com/wiki/SetElementHealth

This function sets the health for the specified element. This can be a player or a vehicle.

setPedStat(zomb,24, 400) does not work.

setPedStat(zomb,24, 40) does also not work.

in 1 week i will post the zombie spawn code because i dont have my own pc atm.

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

*Wiki should update

---------------------------

if you don't use setTimer all Zombies will not changed his health

use this will work 100%

setTimer(setElementHealth,500,1,zomb,20) 

This is from "zombie_server.lua" (line: 384)

addEvent( "onZombieSpawn", true ) 
function RanSpawn_Z ( gx, gy, gz, rot) 
    local safezone = 0 
    local allradars = getElementsByType("radararea") 
    for theKey,theradar in ipairs(allradars) do 
        if getElementData(theradar, "zombieProof") == true then 
            if isInsideRadarArea ( theradar, gx, gy ) then 
                safezone = 1 
            end 
        end 
    end 
    if safezone == 0 then 
        if table.getn ( everyZombie ) < newZombieLimit then 
            if not rot then 
                rot = math.random (1,359) 
            end 
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
            local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) 
            if zomb ~= false then 
                setElementData ( zomb, "zombie", true  ) 
                table.insert( everyZombie, zomb )    
                setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) 
                setTimer ( function (zomb) if ( isElement ( zomb ) ) then setPedAnimation ( zomb, "ped", chaseanim, -1, true, true, true ) end end, 1000, 1, zomb ) 
                setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) 
                triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) 
                setTimer(setElementHealth,500,1,zomb,20) 
            end 
        end 
    end 
end 
addEventHandler( "onZombieSpawn", getRootElement(), RanSpawn_Z ) 

also if you are using Export functions

This is from "zombie_server.lua" (line: 626)

function createZombie ( x, y, z, rot, skin, interior, dimension ) 
    if (table.getn( everyZombie ) < newZombieLimit ) then 
    --this part handles the args 
        if not x then return false end 
        if not y then return false end 
        if not z then return false end 
        if not rot then 
            rot = math.random (1,359) 
        end 
        if not skin then 
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
            skin = ZombiePedSkins[randomZskin] 
        end 
        if not interior then interior = 0 end 
        if not dimension then dimension = 0 end 
    --this part spawns the ped 
        local zomb = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z))--spawns the ped 
    --if successful, this part applies the zombie settings/args 
        if (zomb ~= false) then 
            setTimer ( setElementInterior, 100, 1, zomb, tonumber(interior)) --sets interior 
            setTimer ( setElementDimension, 100, 1, zomb, tonumber(dimension)) --sets dimension 
            setElementData ( zomb, "zombie", true  ) 
            setElementData ( zomb, "forcedtoexist", true  ) 
            setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "forcedtoexist", true ) end end, 1000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then table.insert( everyZombie, zomb ) end end, 1000, 1, zomb ) 
            triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) 
            setTimer(setElementHealth,500,1,zomb,20) 
            return zomb --returns the zombie element 
        else 
            return false --returns false if there was a problem 
        end 
    else 
        return false --returns false if there was a problem 
    end 
end 

CiTLh.png
Posted
setElementHealth(ped,20)

CAN NOT WORK.

setElementHealth only works for vehicles and Players, not Peds and i tested it, the zombies still have 100%

i dont know what youre doing:

viewtopic.php?f=102&t=26375 (not my topic)

https://wiki.multitheftauto.com/wiki/SetElementHealth

This function sets the health for the specified element. This can be a player or a vehicle.

setPedStat(zomb,24, 400) does not work.

setPedStat(zomb,24, 40) does also not work.

in 1 week i will post the zombie spawn code because i dont have my own pc atm.

Client side?

Server side?

*Wiki should update

---------------------------

if you don't use setTimer all Zombies will not changed his health

use this will work 100%

[...]

The problem is that peds including the health are synced by the client, that means either you do setElementData(ped,health) and try to freeze the health on each player's side, or you need to set the health of the ped when it spawns for every player.

In other words:

If you hit a ped, you should trigger a server event, which sets the ped health, which syncs the health for each player.

NPCs are difficult to sync.

Officially MTA's worst fanboy

default.pngdefault.png

default.pngdefault.pngdefault.png

Posted

I want to do it onSpawn, so i will test it with the following code onZombieSpawn SERVER SIDE:

setTimer(setElementHealth,500,1,zomb,20)

i will tell you in 2 weeks if it works or not (work -.-)

n-560x95_FFFFFF_FFFFFF_000000_000000.png

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