iNsanex Posted April 13, 2012 Share Posted April 13, 2012 I'm having an error with the script below, It's not doing -Anything-. It seems to make it so the driver takes no damage at all, command on or not. Nothing comes out in debug, it doesn't output the /me. Any ideas? Thanks in advance. addEventHandler ("onPlayerDamage", getRootElement(), function ( attacker, weapon, bodypart, loss ) if ( getElementData ( source, "seatbelt" ) ) then setElementHealth ( source, ( getElementHealth ( source ) + loss ) ) end end ) function toggleSeatbelt ( thePlayer ) if ( getElementData ( thePlayer, "seatbelt" ) ) then exports.global:sendLocalMeAction(thePlayer, " takes off his seatbelt.") setElementData ( thePlayer, "seatbelt", false ) else exports.global:sendLocalMeAction(thePlayer, " puts on his seatbelt.") setElementData ( thePlayer, "seatbelt", true ) end end addCommandHandler("seatbelton", toggleSeatbelt, false, false) addCommandHandler("seatbeltoff", toggleSeatbelt, false, false) Link to comment
Castillo Posted April 13, 2012 Share Posted April 13, 2012 Topic moved to Scripting section. --------------------------------------- What I understand is that your script is working together with a script that set's player health when crash, right? and for that you're using setElementHealth, but this function won't trigger onPlayerDamage event, so it'll never work this way. You have to check if the player has the seatbelt before setting his health instead. I've made your code a little easier: addEventHandler ( "onPlayerDamage", getRootElement ( ), function ( attacker, weapon, bodypart, loss ) if ( getElementData ( source, "seatbelt" ) ) then setElementHealth ( source, ( getElementHealth ( source ) + loss ) ) end end ) function toggleSeatbelt ( thePlayer ) local state = getElementData ( thePlayer, "seatbelt" ) local newState = ( not state ) outputChatBox ( newState and " puts on his seatbelt." or " takes off his seatbelt." ) setElementData ( thePlayer, "seatbelt", newState ) end addCommandHandler ( "seatbelt", toggleSeatbelt ) Instead of two commands you can do: "/seatbelt" and it'll put it on if it's off, else take it off. 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