Scripting Moderators ds1-e Posted January 26, 2019 Scripting Moderators Share Posted January 26, 2019 Hello. I wanna do something as default GTA SA have. It's about explosion damage, which it's not same all the time, it depends on distance of where explosion was created and how close player was. Following code: function damage(attacker, weapon, bodypart, loss) cancelEvent() outputChatBox(weapon.." "..loss) end addEventHandler("onClientPlayerDamage", getLocalPlayer(), damage) Give me that results: 19 82.5 19 65.310546875 19 58.554851531982 First explosion was under me, and others were a little further from me. So i have a question, how i can create something similar to it, and i don't want to use the default GTA SA damage for my gamemode (for known reasons). I think i can use getDistanceBetweenPoints, but what next? Link to comment
Moderators IIYAMA Posted January 26, 2019 Moderators Share Posted January 26, 2019 (edited) @majqq The first step would be cancelling this event: https://wiki.multitheftauto.com/wiki/OnClientExplosion x: the X Coordinate of where the explosion was created y: the Y Coordinate of where the explosion was created z: the z Coordinate of where the explosion was created theType: the type of explosion created, Values are: 0: Grenade 1: Molotov 2: Rocket 3: Rocket Weak 4: Car 5: Car Quick 6: Boat 7: Heli 8: Mine 9: Object 10: Tank Grenade 11: Small 12: Tiny The second step, recreating the explosion and disable the damage: https://wiki.multitheftauto.com/wiki/CreateExplosion Optional Arguments makeSound: a boolean specifying whether the explosion should be heard or not. camShake: a float specifying the camera shake's intensity. damaging: a boolean specifying whether the explosion should cause damage or not. And the last step is indeed:https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D For your first iteration you can work with rings. So if distance is closer than: damage = 0 if distance is closer than 30 units damage = damage + 10 if distance is closer than 15 units damage = damage + 30 if distance is closer than 5 units damage = damage + 50 iprint(damage) Later you can do some more advanced math stuff which gives you something similar to GTA. Edited January 26, 2019 by IIYAMA 1 Link to comment
Scripting Moderators ds1-e Posted January 26, 2019 Author Scripting Moderators Share Posted January 26, 2019 44 minutes ago, IIYAMA said: @majqq The first step would be cancelling this event: https://wiki.multitheftauto.com/wiki/OnClientExplosion x: the X Coordinate of where the explosion was created y: the Y Coordinate of where the explosion was created z: the z Coordinate of where the explosion was created theType: the type of explosion created, Values are: 0: Grenade 1: Molotov 2: Rocket 3: Rocket Weak 4: Car 5: Car Quick 6: Boat 7: Heli 8: Mine 9: Object 10: Tank Grenade 11: Small 12: Tiny The second step, recreating the explosion and disable the damage: https://wiki.multitheftauto.com/wiki/CreateExplosion Optional Arguments makeSound: a boolean specifying whether the explosion should be heard or not. camShake: a float specifying the camera shake's intensity. damaging: a boolean specifying whether the explosion should cause damage or not. And the last step is indeed:https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D For your first iteration you can work with rings. So if distance is closer than: damage = 0 if distance is closer than 30 units damage = damage + 10 if distance is closer than 15 units damage = damage + 30 if distance is closer than 5 units damage = damage + 50 iprint(damage) Later you can do some more advanced math stuff which gives you something similar to GTA. That's probably everything what i need to know. About second step if i wanna replace it for RPG i should use createExplosion within onPlayerWeaponFire?: endX, endY, endZ: float world coordinates representing an end point. Because as i see onClientPlayerWeaponFire: Note: This does not trigger for projectiles, melee weapons, or camera. I am right? Link to comment
Moderators IIYAMA Posted January 26, 2019 Moderators Share Posted January 26, 2019 (edited) 16 minutes ago, majqq said: That's probably everything what i need to know. About second step if i wanna replace it for RPG i should use createExplosion within onPlayerWeaponFire?: endX, endY, endZ: float world coordinates representing an end point. Because as i see onClientPlayerWeaponFire: Note: This does not trigger for projectiles, melee weapons, or camera. I am right? explosions can't be detected with onClientPlayerWeaponFire My first first step gives you everything you need know for the second step. addEventHandler("onClientExplosion", root, function (x,y,z,theType) createExplosion (x, y, z, theType, true, -1.0, false ) local creator = source -- the one that created the explosion, this doesn't have to be a player. local playerX, playerY, playerZ = getElementPosition(localPlayer) local distance = getDistanceBetweenPoints3D(x, y, z, playerX, playerY, playerZ) end) Edited January 26, 2019 by IIYAMA 1 Link to comment
Scripting Moderators ds1-e Posted January 26, 2019 Author Scripting Moderators Share Posted January 26, 2019 17 minutes ago, IIYAMA said: explosions can't be detected with onClientPlayerWeaponFire My first first step gives you everything you need know for the second step. addEventHandler("onClientExplosion", root, function (x,y,z,theType) createExplosion (x, y, z, theType, true, -1.0, false ) local creator = source -- the one that created the explosion, this doesn't have to be a player. local playerX, playerY, playerZ = getElementPosition(localPlayer) local distance = getDistanceBetweenPoints3D(x, y, z, playerX, playerY, playerZ) end) Oh well, that's my bad, thank you for explaining everything. 1 Link to comment
Moderators IIYAMA Posted January 26, 2019 Moderators Share Posted January 26, 2019 Just now, majqq said: Oh well, that's my bad, thank you for explaining everything. Notes: The car explosion might not look the same, even though it is the same type. (to be honest it looks nicer) You might want to only apply it to the types you want to replace. Damage is disabled for all elements, which includes peds, objects and vehicles. You might need to write the same damage method for those. 1 Link to comment
Scripting Moderators ds1-e Posted May 12, 2019 Author Scripting Moderators Share Posted May 12, 2019 On 26/01/2019 at 23:44, IIYAMA said: Notes: The car explosion might not look the same, even though it is the same type. (to be honest it looks nicer) You might want to only apply it to the types you want to replace. Damage is disabled for all elements, which includes peds, objects and vehicles. You might need to write the same damage method for those. Hey, I wanna say that it works flawless. I know how to get it for player, but what about vehicle? Link to comment
Moderators IIYAMA Posted May 12, 2019 Moderators Share Posted May 12, 2019 7 hours ago, majqq said: Hey, I wanna say that it works flawless. I know how to get it for player, but what about vehicle? For the vehicle the same steps. But in case of doing it clientside. https://wiki.multitheftauto.com/wiki/IsElementSyncer It is important that you as player only edit the vehicles that are synchronized by yourself. In case of doing it serverside, you need to send the explosion to serverside. And do the steps there. Note: explosions without owner should be ignored or not cancelled. 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