Jump to content

Client script not working


Recommended Posts

Posted

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

  

Ingame Nick: CrowClaws

Posted (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 by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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.

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

Ingame Nick: CrowClaws

Posted

For sure not what Jaysd1 was talking about ;).

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.

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