GrubaS Posted February 25, 2015 Share Posted February 25, 2015 I want make a script, when someone use command kill then after 5 sec he'll die whats wrong? addCommandHandler("kill", function (player) setTimer(5000, 0, player) setElementHealth(player, 0) end) Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 You should check the wiki pages for examples; this is not how setTimer works. The 0 in setTimer will make it execute every 5 seconds, you only need it once. addCommandHandler("kill", function(player) setTimer(setElementHealth, 5000, 1, player, 0) end) Link to comment
GrubaS Posted February 25, 2015 Author Share Posted February 25, 2015 and now it's killing me every 5 secound, its working without command Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 Are you using my code? It should kill you only once when you execute the command. Link to comment
WhoAmI Posted February 25, 2015 Share Posted February 25, 2015 It's impossible, check if other script doesn't disturb this code. Link to comment
GrubaS Posted February 25, 2015 Author Share Posted February 25, 2015 Yea, u're right WhoAmI, thanks for helps guys it's working Link to comment
GrubaS Posted February 25, 2015 Author Share Posted February 25, 2015 Hello again, i wanted make kill on Bind (enter). I don't know what write in client ;( server.lua addEvent('KillPlayer', true) addEventHandler('KillPlayer', resourceRoot, function(player, resourceRoot) if not source == resourceRoot then return end setTimer(setElementHealth, 5000, 1, player, 0) end) client.lua function kill() triggerServerEvent('KillPlayer', resourceRoot) end addCommandHandler('kill',kill) addCommandHandler('Commit suicide',kill) bindKey ( next(getBoundKeys"enter_exit"), "down", "Commit suicide" ) Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 You don't need to trigger a server event; setElementHealth is both server and client side. And you don't need that second command. Also, why are you using next and getBoundKeys? You only need to specify the key that should be bound which is 'enter'. Client side: function kill() setTimer(setElementHealth, 5000, 1, localPlayer, 0) end addCommandHandler('kill',kill) bindKey ( "enter", "down", "kill" ) Link to comment
WhoAmI Posted February 25, 2015 Share Posted February 25, 2015 (edited) function kill ( player ) setTimer ( setElementHealth, 5000, 1, player, 0 ) end addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "enter", "down", kill ) end ) It's serverside code. Edited February 25, 2015 by Guest Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 When a player joins after the resource starts, it won't work for him. A client side approach would be better and more efficient, especially with the use of timers. Link to comment
WhoAmI Posted February 25, 2015 Share Posted February 25, 2015 Well, my bad should be onPlayerJoin event instead. But he said that he don't want to write in client so... Edited it already. Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 He said that he doesn't know what to "write" in the client-side script. Like I said, client side will definitely be more efficient since it has timers. Link to comment
GrubaS Posted February 25, 2015 Author Share Posted February 25, 2015 Guys, thanks for help Link to comment
xeon17 Posted February 25, 2015 Share Posted February 25, 2015 There is no need for using setElementHealth , use killPed Link to comment
JR10 Posted February 25, 2015 Share Posted February 25, 2015 They're the same thing, except that he will have to move it to server-side because killPed is server-side only. 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