Sharingan Posted July 25, 2011 Share Posted July 25, 2011 Hello every one, I checked semi-weapons resource and I edited it. The code doesn't work, I don't know why. The damage is different when you shoot in differents bodyparts. Here is the code: local allowedWeapons = {} local damageModified = {} local customDamageHead = {} local customDamageChest = {} local customDamageLeg = {} addEventHandler("onClientResourceStart", getRootElement(), function (startedResource) if (startedResource == getThisResource()) then local xml = xmlLoadFile("config/custom.damage.xml") for i, node in ipairs(xmlNodeGetChildren(xml)) do if (xmlNodeGetName(node) == "weapon") then table.insert(damageModified, tonumber(xmlNodeGetAttribute(node, "id")), true) table.insert(customDamageHead, tonumber(xmlNodeGetAttribute(node, "id")), tonumber(xmlNodeGetAttribute(node, "head"))) table.insert(customDamageChest, tonumber(xmlNodeGetAttribute(node, "id")), tonumber(xmlNodeGetAttribute(node, "chest"))) table.insert(customDamageLeg, tonumber(xmlNodeGetAttribute(node, "id")), tonumber(xmlNodeGetAttribute(node, "leg"))) end end end end ) addEventHandler("onClientPlayerDamage", getRootElement(), function (attacker, weapon, bodypart, loss) cancelEvent() if isElement(attacker) and getElementType(attacker) == "player" then if damageModified[weapon] == true then if bodypart == 9 then if getElementHealth(source) <= customDamageHead[weapon]) then killPed(source, attacker, weapon, bodypart) else setElementHealth(source, getElementHealth(source)-customDamageHead[weapon]) end elseif bodypart == 3 or bodypart == 4 then if getElementHealth(source) <= customDamageChest[weapon]) then killPed(source, attacker, weapon, bodypart) else setElementHealth(source, getElementHealth(source)-customDamageChest[weapon]) end else if getElementHealth(source) <= customDamageLeg[weapon]) then killPed(source, attacker, weapon, bodypart) else setElementHealth(source, getElementHealth(source)-customDamageLeg[weapon]) end end end elseif isElement(attacker) and getElementType(attacker) == "vehicle" then local damage = loss*5 if(getElementHealth(source) <= damage) then killPed(source, attacker, weapon, bodypart) else setElementHealth(source, getElementHealth(source)-damage) end else local damage = loss*3 if(getElementHealth(source) <= damage) then killPed(source, attacker, weapon, bodypart) else setElementHealth(source, getElementHealth(source)-damage) end end end ) and config/custom.damage.xml: "0" head="15" chest="10" leg="80"> "1" head="20" chest="15" leg="10"> "2" head="25" chest="20" leg="17"> "3" head="22" chest="17" leg="15"> "4" head="30" chest="25" leg="15"> "5" head="30" chest="30" leg="30"> "6" head="25" chest="25" leg="25"> "7" head="20" chest="20" leg="20"> "8" head="35" chest="35" leg="35"> "9" head="8" chest="5" leg="4"> "10" head="10" chest="10" leg="10"> "11" head="10" chest="10" leg="10"> "12" head="10" chest="10" leg="10"> "13" head="10" chest="10" leg="10"> "14" head="10" chest="10" leg="10"> "15" head="20" chest="20" leg="20"> "22" head="40" chest="20" leg="15"> "23" head="45" chest="25" leg="20"> "24" head="100" chest="40" leg="30"> "28" head="60" chest="22" leg="12"> "29" head="70" chest="30" leg="18"> "30" head="90" chest="37" leg="20"> "31" head="80" chest="33" leg="18"> "32" head="57" chest="20" leg="10"> "33" head="100" chest="40" leg="30"> "34" head="100" chest="100" leg="80"> "38" head="60" chest="20" leg="15"> "46" head="15" chest="10" leg="80"> Link to comment
Jaysds1 Posted July 25, 2011 Share Posted July 25, 2011 (edited) EDIT: NVM... you have to remove the space between "function" and "(startedresource)", even for the second addEventHandler "function" and "(attacker, etc.)". function(startedResource) -- and function(attacker, weapon, bodypart, loss) If the eventHandler is attached to the function never leave a space between the function and the brackets. Edited July 25, 2011 by Guest Link to comment
Castillo Posted July 25, 2011 Share Posted July 25, 2011 Jaysd1, what are you talking about? that XML file is right, he can put anything as name in there, like root, damage and so on. Link to comment
Sharingan Posted July 25, 2011 Author Share Posted July 25, 2011 Thanks but the problem was in custom.damage.xml. Link to comment
Jaysds1 Posted July 26, 2011 Share Posted July 26, 2011 what was the problem in custom.damage.xml? Link to comment
Sharingan Posted July 26, 2011 Author Share Posted July 26, 2011 "0" head="15" chest="10" leg="80"> The correct form is: "0" head="15" chest="10" leg="80"/> That wasn't the only problem, there were some syntax errors like: if getElementHealth(source) <= customDamageHead[weapon]) then --I put a parenthesis before "then" --correct way: if getElementHealth(source) <= customDamageChest[weapon] then Link to comment
Castillo Posted July 26, 2011 Share Posted July 26, 2011 For sure not what Jaysd1 was talking about . Link to comment
Jaysds1 Posted July 26, 2011 Share Posted July 26, 2011 Well, he might have did what I told him... 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