Galactix Posted June 11, 2018 Share Posted June 11, 2018 Hello, I am Scripting a zombie rpg server and as I disabled headshot kills on zombies, I would like to make a damage multiplier system depending on the body part hit when you shoot a zombie. I have been trying to use this script (not mine): local weaponTable = { -- populate this list by adding weapons: -- [weap_id] = { torso, ass, left_arm, right_arm, left_leg, right_leg, head } [24] = { 75, 50, 30, 30, 25, 25, 150 }, } addEventHandler("onPlayerDamage", getRootElement(), function (attacker, weapon, bodypart, loss) if getElementType(attacker) == "player" and getPlayerWeapon(attacker) and weaponTable[ getPlayerWeapon(attacker) ] then setElementHealth(source, getElementHealth(source) - weaponTable[ getPlayerWeapon(attacker) ] [ bodyPart - 2] + loss) end end ) but it didn't work on both players and zombie peds. If someone has a solution for this to work the way I want it would be great (ideally both player and zombie ped multiplier but ped multiplier is more important) Link to comment
Saml1er Posted June 11, 2018 Share Posted June 11, 2018 (edited) I created something similar for a friend, a simple resource that loads settings from xml file, like how much damage each body part will take for every weapon. You can see how I did it: https://drive.google.com/file/d/10KC22xDZ9TkKYJQKoGiyVJ3oYzrLHkCz/view?usp=sharing before you start using it, just add this to main_server.lua at bottom of the file: addEventHandler ("onPlayerJoin", root, function () arrCPlayers [ source ] = CPlayer ( arrCBodyPartsCache ) end ) addEventHandler ("onPlayerQuit", root, function () arrCPlayers [ source ] = nil end ) I'm not a fan of loading data from xml files, I think they should be avoided if possible, because they can freeze your server for a few milliseconds if you have too much info in there, it's better to use a lua table for configuration data, like you did in your original post. Edited June 11, 2018 by Saml1er Link to comment
Galactix Posted June 11, 2018 Author Share Posted June 11, 2018 (edited) I tried running your script but it doesn't seem to affect the damage I deal to the zombies with the deagle, even after modifying the multiplier in the damage_config.xml file. Is the script intended to modify damage dealt to player elements or peds aswell? Edited June 11, 2018 by Galactix Link to comment
Saml1er Posted June 11, 2018 Share Posted June 11, 2018 (edited) I haven't added that part, it doesn't modify player health after receiving damage. It just keeps track of how much damage was caused to each body part, like I said, it's just an example of how to handle damage. You'll need to create an event which detects zombies damage, there's no server side event, this means you'll need a client (player) to trigger a server side event that you'll create. You can gracefully use onClientPedDamage event on client side to trigger your server side event for detecting damage: client side: addEventHandler ( "onClientPedDamage", root, function ( attacker, weapon, bodypart ) -- here we check if the attacker is localPlayer, so we don't trigger -- the server side event for all players on server if getElementType ( source ) == "ped" and attacker == localPlayer then if (getElementData (source, "zombie") == true) then triggerServerEvent ("onZombieDamage", resourceRoot, source, attacker, weapon, bodypart ) end end end ) server side: local weaponTable = { -- populate this list by adding weapons: -- [weap_id] = { torso, ass, left_arm, right_arm, left_leg, right_leg, head } [24] = { 5, 8, 5, 8, 9, 4, 5 }, } addEvent( "onZombieDamage", true ) function Zheadhit ( ped,attacker, weapon, bodypart) if (getElementData (ped, "zombie") == true) then -- here you need to decide how much damage to give, I'm not quite sure if this line of code works -- but that's something you need to check local bodyPartsDamageTable = weaponTable[ getPedWeapon (attacker) ] if getElementType(attacker) == "player" and bodyPartsDamageTable then local damageMultiplier = bodyPartsDamageTable [ bodyPart - 2] setElementHealth ( ped, getElementHealth(ped) - (damageMultiplier * loss) ) end end end addEventHandler( "onZombieDamage", getRootElement(), Zheadhit ) EDIT: create two files, one for server, and other for client, then put this code in there, you have to make sure that they are within the same resource. Edited June 11, 2018 by Saml1er made some adjustments and change triggerServerEvent's source to resourceRoot 1 Link to comment
Galactix Posted June 11, 2018 Author Share Posted June 11, 2018 (edited) Thank you very much for your help, that's what I was looking for! Edited June 11, 2018 by Galactix Link to comment
Galactix Posted June 11, 2018 Author Share Posted June 11, 2018 (edited) Actually, I'm getting this error now [21:23:31] ERROR: [OutbreakRPG]\zdamage\damage_server.lua:15: attempt to perform arithmetic on global 'bodyPart' (a nil value) How to fix it? EDIT: Changed "bodyPart" to "bodypart" and it's now solved and working completely, thanks a lot again! Edited June 11, 2018 by Galactix 1 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