Ujeelka Posted September 2, 2009 Share Posted September 2, 2009 Here is "car_locks" script. Car Locks version 1.1 by vick. Commands: affect last vehicle driven/lock - lock vehicle /unlock - unlock vehicle /lights - toggle lights /engine - toggle engine Binds: always on"l" - lock/unlock toggle ...here is only one bind... i want to make this: Keys: 1 for engine , 2 for lights , 3 for lock... -- =================-- Car Locks ( server )-- by vick.-- ================= -- player element data -- -- cl_ownedvehicle-- vehicle element data -- -- cl_vehicleowner -- cl_vehiclelocked -- cl_enginestate -- resource starts - endsfunction initCarLocks () -- Initilize Player Element Data local players = getElementsByType ( "player" ) for k,p in ipairs(players) do removeElementData ( p, "cl_ownedvehicle" ) bindKey ( p, "l", "down", doToggleLocked ) end -- Initilize Vehicle Element Data local vehicles = getElementsByType ( "vehicle" ) for k,v in ipairs(vehicles) do removeElementData ( v, "cl_vehicleowner" ) removeElementData ( v, "cl_vehiclelocked" ) removeElementData ( v, "cl_enginestate" ) setVehicleLocked ( v, false ) setVehicleOverrideLights ( v, 0 ) endendaddEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), initCarLocks )addEventHandler ( "onResourceStop", getResourceRootElement ( getThisResource () ), initCarLocks ) -- player joinsfunction cl_PlayerJoin ( )bindKey ( source, "l", "down", doToggleLocked ) endaddEventHandler ( "onPlayerJoin", getRootElement(), cl_PlayerJoin ) -- player quitsfunction cl_PlayerQuit ( ) -- check for owned car local ownedVehicle = getElementData ( source, "cl_ownedvehicle" ) if (ownedVehicle ~= false) then cl_RemoveVehicleOwner ( ownedVehicle ) endendaddEventHandler ( "onPlayerQuit", getRootElement(), cl_PlayerQuit ) -- player diesfunction cl_PlayerWasted ( ) -- check for owned car local ownedVehicle = getElementData ( source, "cl_ownedvehicle" ) if (ownedVehicle ~= false) then cl_RemoveVehicleOwner ( ownedVehicle ) endendaddEventHandler ( "onPlayerWasted", getRootElement(), cl_PlayerWasted ) -- player tries to enter vehiclefunction cl_VehicleStartEnter ( enteringPlayer, seat, jacked ) local theVehicle = source local theOwner -- locked and not owner entering if ( getElementData ( theVehicle, "cl_vehiclelocked" ) == true ) then theOwner = getElementData ( theVehicle, "cl_vehicleowner" ) if theOwner ~= false and theOwner ~= enteringPlayer then -- make sure they dont enter --cancelEvent(); end endendaddEventHandler ( "onVehicleStartEnter", getRootElement(), cl_VehicleStartEnter ) -- player enters a vehiclefunction cl_PlayerDriveVehicle ( player, seat, jacked ) -- Driver Enter if ( seat == 0 ) then oldVehicle = getElementData ( player, "cl_ownedvehicle" ) -- not entering player's own owned vehicle if ( (cl_VehicleLocked(source) == true) and (cl_VehicleOwner(source) ~= player) ) then removePlayerFromVehicle( player ) Err_Msg("this vehicle is locked.", player) return false end -- set element data for vehicle and owner cl_SetVehicleOwner ( source, player ) end return trueendaddEventHandler ( "onVehicleEnter", getRootElement(), cl_PlayerDriveVehicle ) -- vehicle respawnsfunction cl_VehicleRespawn ( exploded ) cl_RemoveVehicleOwner ( source )endaddEventHandler ( "OnVehicleRespawn", getRootElement(), cl_VehicleRespawn ) -- vehicle explosionfunction cl_VehicleExplode ( ) local theOwner = getElementData ( source, "cl_vehicleowner" ) if ( theOwner ~= false ) then cl_RemoveVehicleOwner ( source ) endendaddEventHandler ( "onVehicleExplode", getRootElement(), cl_VehicleExplode ) -- set vehicle ownerfunction cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if ( oldVehicle ~= false ) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car end setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end function cl_RemoveVehicleOwner ( theVehicle ) local theOwner = getElementData ( theVehicle, "cl_vehicleowner" ) if ( theOwner ~= false ) then removeElementData ( theOwner, "cl_ownedvehicle" ) removeElementData ( theVehicle, "cl_vehicleowner" ) removeElementData ( theVehicle, "cl_vehiclelocked" ) removeElementData ( owned, "cl_enginestate" ) end setVehicleLocked ( theVehicle, false ) end -- flash the lights twicefunction cl_FlashLights ( thePlayer ) setTimer ( doToggleLights, 300, 4, thePlayer, true )end -- flash oncefunction cl_FlashOnce ( thePlayer ) setTimer ( doToggleLights, 300, 2, thePlayer, true )end -- get vehicle owner ( according to vehicle's element data )function cl_VehicleOwner ( theVehicle ) return getElementData( theVehicle, "cl_vehicleowner" ) end-- is vehicle locked ( according to vehicle's element data )function cl_VehicleLocked ( theVehicle ) return getElementData( theVehicle, "cl_vehiclelocked" )end-- messaging functions-- send red error messagefunction Err_Msg ( strout, thePlayer ) outputChatBox ( strout, thePlayer, 200, 0, 10 )end -- send message to all occupants of vehiclefunction Car_Msg ( strout, theVehicle ) numseats = getVehicleMaxPassengers ( theVehicle ) for s = 0, numseats do local targetPlayer = getVehicleOccupant ( theVehicle, s ) if targetPlayer ~= false then outputChatBox ( strout, targetPlayer, 30, 144, 255 ) end endend-- send aquamarine message to playerfunction Info_Msg ( strout, thePlayer ) outputChatBox ( strout, thePlayer, 102, 205, 170 )end -- commands function doToggleLocked ( source ) local theVehicle , strout if ( getElementType(source) == "vehicle" ) then theVehicle = source end if ( getElementType(source) == "player" ) then theVehicle = getElementData ( source, "cl_ownedvehicle" ) end if ( theVehicle ) then local vehiclename = getVehicleName ( theVehicle ) -- already locked if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then doUnlockVehicle ( source ) else doLockVehicle ( source ) end else Err_Msg("You must have a vehicle to lock or unlock it.", source) endend function doLockVehicle ( source ) local theVehicle , strout if ( getElementType(source) == "vehicle" ) then theVehicle = source end if ( getElementType(source) == "player" ) then theVehicle = getElementData ( source, "cl_ownedvehicle" ) end if ( theVehicle ) then local vehiclename = getVehicleName ( theVehicle ) -- already locked if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then strout = "Your " .. vehiclename .. " is already locked." Err_Msg(strout, source) else setElementData ( theVehicle, "cl_vehiclelocked", true) setVehicleLocked ( theVehicle, true ) Car_Msg( "current vehicle " .. vehiclename .. " locked.", theVehicle) Info_Msg ( "locked vehicle " .. vehiclename .. ".", source ) if ( getVehicleController ( theVehicle ) == false ) then cl_FlashLights ( source ) end end else Err_Msg("You must have a vehicle to lock it.", source) endend function doUnlockVehicle ( source ) local theVehicle, strout if ( getElementType(source) == "vehicle" ) then theVehicle = source end if ( getElementType(source) == "player" ) then theVehicle = getElementData ( source, "cl_ownedvehicle" ) end if ( theVehicle ) then local vehiclename = getVehicleName ( theVehicle ) if ( getElementData ( theVehicle, "cl_vehiclelocked") == false ) then strout = "Your " .. vehiclename .. " is already unlocked." Err_Msg(strout, source) else setElementData ( theVehicle, "cl_vehiclelocked", false) setVehicleLocked ( theVehicle, false ) Car_Msg( "current vehicle " .. vehiclename .. " unlocked.", theVehicle ) Info_Msg ( "unlocked vehicle " .. vehiclename .. ".", source ) if ( getVehicleController ( theVehicle ) == false ) then Link to comment
Ujeelka Posted September 2, 2009 Author Share Posted September 2, 2009 Man... i understand this bindkey . Need help . for example: (syntax) bindKey ( player thePlayer, string key, string keyState, function handlerFunction, [ var arguments, ... ] ) i dont know what is this shit ! Link to comment
eAi Posted September 2, 2009 Share Posted September 2, 2009 Have you read the wiki? It has detailed explanations of each parameter and two examples... Link to comment
50p Posted September 2, 2009 Share Posted September 2, 2009 Have you read the wiki? It has detailed explanations of each parameter and two examples... Having description of all parameters is not always enough... especially for someone who has no scripting knowledge whatsoever. He needs to learn Lua first.. then he can start scripting. Link to comment
xbenny2506x Posted September 3, 2009 Share Posted September 3, 2009 50p has right! You find here a lot help but you must learn how work a script. I am not the best in making scripts, but the people here help me a lot and i have learn a lot in the last month since i have start the work on my Stunt server. So i can say you read what the people say here and work with that! I have not so much time for help you to add in all "function" the "bindKey" but its easy! You have for "lock" a bindKey in the script: function initCarLocks () -- Initilize Player Element Data local players = getElementsByType ( "player" ) for k,p in ipairs(players) do removeElementData ( p, "cl_ownedvehicle" ) bindKey ( p, "l", "down", doToggleLocked ) -- change with bindKey ( p, "3", "down", doToggleLocked ) end and here too -- player joins function cl_PlayerJoin ( ) bindKey ( source, "l", "down", doToggleLocked ) end addEventHandler ( "onPlayerJoin", getRootElement(), cl_PlayerJoin ) -- change with bindKey ( p, "3", "down", doToggleLocked ) and for the rest you have here the answer addCommandHandler ( "engine", doToggleEngine ) addCommandHandler ( "lights", doToggleLights, false) addCommandHandler ( "lock", doLockVehicle ) addCommandHandler ( "unlock", doUnlockVehicle ) Search the "function" (doToggleEngine...) and add "bindKey" More can i help you not... i have many things to do with my scripts and server. Link to comment
Ujeelka Posted September 3, 2009 Author Share Posted September 3, 2009 let's see...(adding bind key to engine) function doToggleEngine ( source ) local theVehicle if ( getElementType(source) == "vehicle" ) then theVehicle = source [color=#0000FF]bindKey[/color] ( p, "1", "down", doToggleEngine ) end its good ? 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