Miliviu Posted February 13, 2020 Share Posted February 13, 2020 (edited) addEventHandler ( "onPlayerDamage", getRootElement (), function ( attacker, weapon ) if ( weapon == 41 ) then if ( getElementType ( source ) == "player" ) then fadeCamera(source, false) setTimer(function() fadeCamera(source, true) end, time, 1) outputChatBox ( "Has cegado a " source, attacker, 0, 255, 120 ) outputChatBox ( "Has sido cegado con un gas pimienta.", source, 0, 255, 120 ) end end end ) Hi! I made a pepper spray that blinds when you get hitted by it, but when i used it i have this errors spray/spray.Lua:7 bad argument @ fadeCamera expected element at argument 1, got nil spray/spray.Lua:9 attempt to concatenate global source a userdata value Edited February 13, 2020 by Miliviu Link to comment
ReZurrecti0n Posted February 14, 2020 Share Posted February 14, 2020 (edited) It doesn't "know" what source is, you have to pass the argument to the function within your timer setTimer(function(source) -- Added source here fadeCamera(source, true) -- So now it will get "source" from the function's argument (source) end, time, 1, source) -- And here too, this tells the function what "source" will be This should resolve that issue... outputChatBox ( "Has cegado a " source, attacker, 0, 255, 120 ) -- There is no comma between the text string and source outputChatBox ( "Has cegado a ", source, attacker, 0, 255, 120 ) -- Im still not sure if this would work exactly, but could just do another line outputChatBox ( "Has cegado a ", source, 0, 255, 120 ) -- Send to the source outputChatBox ( "Has cegado a ", attacker, 0, 255, 120 ) -- Send to the attacker Edited February 14, 2020 by ReZurrecti0n 1 Link to comment
Miliviu Posted February 14, 2020 Author Share Posted February 14, 2020 Thanks! it worked! But now the message spams every second a player gets hitted by the spray, It's possible to limit the number of messages? Thanks in advantage addEventHandler ( "onPlayerDamage", getRootElement (), function ( attacker, weapon ) if ( weapon == 41 ) then if ( getElementType ( source ) == "player" ) then fadeCamera(source, false) setTimer(function(source) fadeCamera(source, true) end, 5000, 1, source) outputChatBox ( "Has cegado a alguien con un gas pimienta " , attacker, 0, 255, 120 ) outputChatBox ( "Has sido cegado con un gas pimienta por ." , source, 0, 255, 120 ) end end end ) Link to comment
!#NssoR_) Posted February 14, 2020 Share Posted February 14, 2020 Seconds = 3 -- prevent spamming for 3 sec. Spamming = {} addEventHandler ( "onPlayerDamage", getRootElement (), function ( attacker, weapon ) if ( weapon == 41 ) then if ( getElementType ( source ) == "player" ) then fadeCamera(source, false) setTimer(function(source) fadeCamera(source, true) end, 5000, 1, source) if not Spamming[attacker] then Spamming[attacker] = setTimer(function (attac) Spamming[attac] = nil end , Seconds * 1000,1,attacker) outputChatBox ( "Has cegado a alguien con un gas pimienta " , attacker, 0, 255, 120 ) outputChatBox ( "Has sido cegado con un gas pimienta por ." , source, 0, 255, 120 ) end end end end ) 1 Link to comment
Miliviu Posted February 14, 2020 Author Share Posted February 14, 2020 Thanks, it's perfect, have a good day 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