Einheit-101 Posted October 2, 2011 Share Posted October 2, 2011 Hello Community, I have written a little script that lets Peds die earlier, because setElementHealth does not work for peds The problem is, that the Peds die correctly 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^^ Link to comment
TAPL Posted October 2, 2011 Share Posted October 2, 2011 (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 October 2, 2011 by Guest Link to comment
Einheit-101 Posted October 2, 2011 Author Share Posted October 2, 2011 (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 October 4, 2011 by Guest Link to comment
Einheit-101 Posted October 4, 2011 Author Share Posted October 4, 2011 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... Link to comment
Castillo Posted October 4, 2011 Share Posted October 4, 2011 The maximun health a player/ped can have is 200%. Link to comment
TAPL Posted October 4, 2011 Share Posted October 4, 2011 or you can use this for extra Health https://community.multitheftauto.com/index.php?p= ... ls&id=1604 viewtopic.php?f=108&t=31550&p=336070#p336070 Link to comment
Einheit-101 Posted October 8, 2011 Author Share Posted October 8, 2011 ***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! Link to comment
Castillo Posted October 8, 2011 Share Posted October 8, 2011 Just do setElementHealth in the zombies to a lower value, i.e 50%. Link to comment
Einheit-101 Posted October 8, 2011 Author Share Posted October 8, 2011 Solidsnake, this doesnt work, because setElementHealth does not work for PEDs (only Players and Vehicles) Link to comment
Castillo Posted October 9, 2011 Share Posted October 9, 2011 Well, then you are wrong, because I just set a ped health to 20%. Link to comment
Einheit-101 Posted October 9, 2011 Author Share Posted October 9, 2011 I just set a ped health to 20%. Could you please show me your line? Link to comment
Phat Looser Posted October 9, 2011 Share Posted October 9, 2011 Erm, setElementHealth(ped,20) when it spawns? Can't be THAT hard. After all I'm using it in my syncro. Or just use killPed(ped) in onClientPedDamage https://wiki.multitheftauto.com/wiki/OnClientPedDamage Link to comment
Castillo Posted October 9, 2011 Share Posted October 9, 2011 I used it via runcode, as it was just a simple test: ped = createPed(299,x,y,z) setElementHealth(ped,20) Link to comment
Einheit-101 Posted October 18, 2011 Author Share Posted October 18, 2011 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. Link to comment
TAPL Posted October 19, 2011 Share Posted October 19, 2011 *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 Link to comment
Phat Looser Posted October 19, 2011 Share Posted October 19, 2011 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. Link to comment
Einheit-101 Posted October 19, 2011 Author Share Posted October 19, 2011 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 -.-) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now