Turbe$Z Posted December 3, 2016 Share Posted December 3, 2016 (edited) -- client -- function boom ( ) local pX, pY, pZ = getElementPosition ( getLocalPlayer() ) createExplosion ( pX+3, pY+3, pZ, 2 ) createExplosion ( pX-3, pY-3, pZ, 2 ) createExplosion ( pX+5, pY-2, pZ, 2 ) createExplosion ( pX-4, pY+4, pZ, 2 ) end addEvent( "rob", true ) addEventHandler( "rob", root, boom ) -- server -- function robbant(p,s) if hasObjectPermissionTo(p,"command.rob") then triggerClientEvent(getRootElement(),"rob",getRootElement()) end end addCommandHandler("rob",robbant) When i type 'rob', explode everyone.. Why? How to fix this? Edited December 3, 2016 by Turbo777 Link to comment
LoPollo Posted December 3, 2016 Share Posted December 3, 2016 (edited) I can't see any error... but why are you making a clientside script if you can do all serverside? triggerClientEvent note: Note: To save client CPU, you should avoid setting sourceElement to the root element where possible. Using resourceRoot is usually sufficient if the event is handled by the same resource on the client. EDIT: ohhh i now see the problem: you are triggering to the root, so EVERY player will get the clientside script. Edited December 3, 2016 by LoPollo Link to comment
Turbe$Z Posted December 3, 2016 Author Share Posted December 3, 2016 because me a noob scripter, and i dont know how to create in serverside Link to comment
LoPollo Posted December 3, 2016 Share Posted December 3, 2016 (edited) Line 3 serverside: triggerClientEvent(getRootElement(),"rob",getRootElement()) replace with triggerClientEvent(p,"rob",getRootElement()) If you want to solve the problem said in the note of triggerClientEvent, replace with triggerClientEvent(p,"rob",p) (if you don't need the extra arguments of clientside createExplosion then it's still better to move all on serverside, i will post the code as soon as i return) Edited December 3, 2016 by LoPollo Link to comment
pa3ck Posted December 3, 2016 Share Posted December 3, 2016 (edited) Well hasObjectPermissionTo is a server-side only function, so you either make changes to it so you don't have to use that function or just do the explosion server side: function robbant(p,s) if hasObjectPermissionTo(p,"command.rob") then local pX, pY, pZ = getElementPosition ( p ) createExplosion ( pX+3, pY+3, pZ, 2 ) createExplosion ( pX-3, pY-3, pZ, 2 ) createExplosion ( pX+5, pY-2, pZ, 2 ) createExplosion ( pX-4, pY+4, pZ, 2 ) end end addCommandHandler("rob",robbant) Edited December 3, 2016 by pa3ck 1 Link to comment
LoPollo Posted December 3, 2016 Share Posted December 3, 2016 (edited) Ok here's the serverside with all in it. I never used the restricted argument in addCMDHandler, but it should work... still it's better to test. If testing of the first function result in a "fail", then use the second variant. function nameThatFunction( playerSource, cmd, ... ) local pX, pY, pZ = getElementPosition ( playerSource ) createExplosion ( pX+3, pY+3, pZ, 2 ) createExplosion ( pX-3, pY-3, pZ, 2 ) createExplosion ( pX+5, pY-2, pZ, 2 ) createExplosion ( pX-4, pY+4, pZ, 2 ) end addCommandHandler( "rob", nameThatFunction, true) --that true means the resource is restricted, so only if a player is in a group with the access to command.rob that command will be executed --since i NEVER used the restricted argument, here's the variant with the check inside the function function nameThatFunction( playerSource, cmd, ... ) if hasObjectPermissionTo(playerSource,"command.rob") then local pX, pY, pZ = getElementPosition ( playerSource ) createExplosion ( pX+3, pY+3, pZ, 2 ) createExplosion ( pX-3, pY-3, pZ, 2 ) createExplosion ( pX+5, pY-2, pZ, 2 ) createExplosion ( pX-4, pY+4, pZ, 2 ) end end addCommandHandler( "rob", nameThatFunction) EDIT: lol i noticed that the second variant is already posted, sorry for the duplicate. Edited December 3, 2016 by LoPollo 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