Hiding Posted January 14 Share Posted January 14 (edited) I'm encountering an issue with my script where it prints 'playerName died' twice when a vehicle explodes. Interestingly, it works fine when I press enter or jump into the water; it only prints once. Any suggestions on how to handle explosions in this script? Also, any tips on optimizing the script for better efficiency would be appreciated. function onPlayerWasted(totalAmmo, killer) local playerName = getPlayerName(source) if isElement(killer) and getElementType(killer) == "player" then local killerName = getPlayerName(killer) local victimName = getPlayerName(source) if killer == source then -- suicide outputChatBox(playerName .. " died") else outputChatBox(killerName .. " killer " .. victimName) end else outputChatBox(playerName .. " died") end end addEventHandler("onPlayerWasted", root, onPlayerWasted) Edited January 14 by Hiding Link to comment
Spakye Posted January 15 Share Posted January 15 Hello, could it be that the car explosion count as a player killing himself (suicide)? so then it print the suicide message and then the other one? maybe change the suicide message so they are not identical. 1 Link to comment
mazarati21 Posted January 15 Share Posted January 15 Hi, try this local lastDeathTime = {} function onPlayerWasted(totalAmmo, killer) local playerName = getPlayerName(source) local currentTime = getTickCount() -- Check if the player has already been processed recently if lastDeathTime[playerName] and currentTime - lastDeathTime[playerName] < 1000 then return end lastDeathTime[playerName] = currentTime if isElement(killer) and getElementType(killer) == "player" then local killerName = getPlayerName(killer) local victimName = getPlayerName(source) if killer == source then -- suicide outputChatBox(playerName .. " died") else outputChatBox(killerName .. " killed " .. victimName) end else outputChatBox(playerName .. " died") end end addEventHandler("onPlayerWasted", root, onPlayerWasted) 1 Link to comment
Hiding Posted January 15 Author Share Posted January 15 1 hour ago, mazarati21 said: Hi, try this local lastDeathTime = {} function onPlayerWasted(totalAmmo, killer) local playerName = getPlayerName(source) local currentTime = getTickCount() -- Check if the player has already been processed recently if lastDeathTime[playerName] and currentTime - lastDeathTime[playerName] < 1000 then return end lastDeathTime[playerName] = currentTime if isElement(killer) and getElementType(killer) == "player" then local killerName = getPlayerName(killer) local victimName = getPlayerName(source) if killer == source then -- suicide outputChatBox(playerName .. " died") else outputChatBox(killerName .. " killed " .. victimName) end else outputChatBox(playerName .. " died") end end addEventHandler("onPlayerWasted", root, onPlayerWasted) Thank you so much, it works now 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