Jump to content

My own scipt start to flood


motax

Recommended Posts

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
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
  • Moderators

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
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?

Nevermind, I'm an idiot...

now i get it..:D

and thank you! :)

Link to comment
  • Moderators

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
  • Moderators

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...