motax Posted July 30, 2013 Share Posted July 30, 2013 I just made a script where you can lock or unlock your own car by click on the vehicle and choose to lock or unlock it. The script is working fine, except that if a player clicks on the vehicle more times it will run the script as many times he clicked on the car. Server: function car_click ( button, buttons, player ) car = getElementType(source) if(car == "vehicle") then if(buttons == "up") then triggerClientEvent ( "onCar", getRootElement(), source,player) end end end addEventHandler ( "onElementClicked",getRootElement() ,car_click ) Client: addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () car_info = guiCreateWindow ( 200, 200, 200, 200,"Car Menu", false ) lock = guiCreateButton ( 5, 30, 170, 30, "Unlock Car", false, car_info ) lock1 = guiCreateButton ( 5, 61, 170, 30, "Lock Car", false, car_info ) guiSetVisible(car_info, false) end ) function car_window ( car,player ) local playerID = getElementData(player, "ID") local carID = getElementData(car, "ID") local own = getElementData(car, "owner") local kx,ky,kz = getElementPosition(car) local px,py,pz = getElementPosition(player) local dst = getDistanceBetweenPoints2D ( px, py, kx, ky ) if(dst < 5) then if (player ~= localPlayer) then return end guiSetVisible(car_info, true) if(own == playerID)then function open(button, state) setVehicleLocked ( car, false ) outputChatBox("Vehicle succesfully unlocked!",player) guiSetVisible(car_info, false) end function close(button, state) setVehicleLocked ( car, true ) outputChatBox("Vehicle succesfully locked!!",player) guiSetVisible(car_info, false) end addEventHandler ( "onClientGUIClick", lock, open, true ) addEventHandler ( "onClientGUIClick", lock1, close, true ) else outputChatBox("This isn't your car!",player) end end end addEvent( "onCar", true ) addEventHandler( "onCar", getRootElement(), car_window ) I can't figure it out, how to solve this. Link to comment
Moderators IIYAMA Posted July 30, 2013 Moderators Share Posted July 30, 2013 https://wiki.multitheftauto.com/wiki/GetTickCount local tickCount = 0 if getTickCount() - tickCount >= 1000 then tickCount = getTickCount() end Recommended to use this on client side cause of the trigger, it will save you some bandwidth. Link to comment
motax Posted July 30, 2013 Author Share Posted July 30, 2013 Ok, thanks for the advice Any idea about how to stop doing that multiple locking/unlocking? Link to comment
Moderators IIYAMA Posted July 30, 2013 Moderators Share Posted July 30, 2013 Ok, thanks for the advice Any idea about how to stop doing that multiple locking/unlocking? I just did, you scripted that, then it won't be hard to add these few lines. else it isn't your script. ("motax: I just made a script") Good luck Link to comment
motax Posted July 30, 2013 Author Share Posted July 30, 2013 I think you misunderstood me, because I can't see how this could help. Link to comment
Moderators IIYAMA Posted July 30, 2013 Moderators Share Posted July 30, 2013 WIKI getTickCount Client and Server function This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task. Clear? Link to comment
motax Posted July 30, 2013 Author Share Posted July 30, 2013 WIKIgetTickCount Client and Server function This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task. Clear? Nevermind, I'm an idiot... now i get it.. and thank you! Link to comment
Moderators IIYAMA Posted July 30, 2013 Moderators Share Posted July 30, 2013 A sample how you can do it: local tickCount = 0 addCommandHandler("hey", function() if getTickCount() - tickCount >= 1000 then outputChatBox("hey") tickCount = getTickCount() end end) After you write the command /hey, it will show "hey" in the chat box, if you write it again within the 1000 millisecond(1sec), it won't be visible in the chat box. After this amount of time has past, you can show it again. Link to comment
motax Posted July 30, 2013 Author Share Posted July 30, 2013 Work like a charm. Thanks again for the help! Link to comment
Moderators IIYAMA Posted July 30, 2013 Moderators Share Posted July 30, 2013 np. else it isn't your script. ("motax: I just made a script") I wrote this because many forum users are abusing my attention or steal scripts, sorry for that but that was just for assurance. Link to comment
motax Posted July 30, 2013 Author Share Posted July 30, 2013 No problem, I saw that the forum is full with people who asking help for stolen scripts all the time. I prefer to enjoy my own work. 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