Jump to content

[Help] Change bind key to command handler


BieHDC

Recommended Posts

Hello,

i have downloaded a script and want to costumize it for my server.

It has a key bind but i want a command handler.

The Client side is crypted, but maybe we dont need it.

Here is the bind code:

  
function onLoad () 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        if isPlayerAdmin ( player ) then 
            bindKey ( player, "F2", "down", isPlayerAdmins ) 
        end 
    end 
end 
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), onLoad)   
  
  
function onJoin () 
    if isPlayerAdmin (source) then 
        bindKey ( source, "F2", "down", isPlayerAdmins ) 
    end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), onJoin ) 
  
function onJoin () 
    unbindKey ( source, "F2", "down", isPlayerAdmins ) 
end 
addEventHandler ( "onPlayerLogout", getRootElement(), onJoin ) 
  

Link to comment
  
local eof = nil
function outputPanelLog(outputs,comment)
    local panellog = nil
    if fileOpen ( "panellog.txt" ) then
        panellog = fileOpen ( "panellog.txt" )
        eof = fileGetSize ( panellog )
        fileSetPos ( panellog, eof )
    else
        panellog = fileCreate ( "panellog.txt" )
    end
    local time = getRealTime()
    local curTime = "[".. time.year+1900 .."-".. time.month+1 .."-"..time.monthday.." "..time.hour..":"..time.minute.."]"
    local str = outputs
    -- if string.len( comment ) > 0 then
        -- str = str .. "\\ " .. comment
    -- end
    str = str .. "\r\n"
    eof = fileWrite ( panellog, curTime .. " * FTAPANEL: "  .. outputs .. "." .. "\n" )
    fileSetPos ( panellog, eof )
    fileClose ( panellog )
    outputDebugString ( "Log Written" )
    for index, player in ipairs ( getElementsByType ( "player" ) ) do
        if isPlayerAdmin ( player ) then
            outputConsole ( " * FTAPANEL: " .. outputs .. ".", player )
        end
    end
end
 
function getdxtxt ( motdt, _source)
    local logK =  _source .. " set the dxMOTD to \"" .. motdt .. "\""
    outputPanelLog(logK)
    for _, player in ipairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( player, "rendertxt", player, motdt )
        triggerClientEvent ( player, "setBox", player, motdt )
    end
    motdhandle  = fileCreate("motdk.txt")
    if motdhandle then
        fileWrite(motdhandle , motdt)
        fileFlush (motdhandle)
        fileClose(motdhandle)
    end
end
addEvent ( "getdx", true )
addEventHandler ( "getdx", root, getdxtxt )
 
function readfile()
        local openmotd = fileOpen("motdk.txt")
        local motdt = fileRead (openmotd, 100)
        triggerClientEvent ( source, "rendertxt", source, motdt )
        triggerClientEvent ( source, "setBox", source, motdt )
        fileClose(openmotd)
end
addEvent("joinmotd",true)
addEventHandler("joinmotd", root, readfile)
 
 
 
function isPlayerAdmins(source)
    if isPlayerAdmin (source) then
         triggerClientEvent("ClientGui",getRootElement(),source)
    end
end
 
function onLoad ()
    for index, player in ipairs ( getElementsByType ( "player" ) ) do
        if isPlayerAdmin ( player ) then
            bindKey ( player, "F2", "down", isPlayerAdmins )
        end
    end
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), onLoad)  
 
 
function onJoin ()
    if isPlayerAdmin (source) then
        bindKey ( source, "F2", "down", isPlayerAdmins )
    end
end
addEventHandler ( "onPlayerLogin", getRootElement(), onJoin )
 
function onJoin ()
    unbindKey ( source, "F2", "down", isPlayerAdmins )
end
addEventHandler ( "onPlayerLogout", getRootElement(), onJoin )
 
function isPlayerAdmin(source)
    local accountname = getAccountName(getPlayerAccount(source))
    if isObjectInACLGroup("user." ..accountname, aclGetGroup("Admin")) then
        return true
    elseif isObjectInACLGroup("user." ..accountname, aclGetGroup("SuperModerator"))  then
        return true
    end
end
 
function isPlayerInTeam( thePlayer, teamName )
    local pTeam = getPlayerTeam( thePlayer )
    local fTeam = getTeamName( teamName )
    if ( pTeam ) and ( fTeam ) then
        if ( pTeam == fTeam ) then
            return true
        end
    end
end
 
 
function adminChat ( thePlayer, commandName, ... )
    local text = table.concat ( { ... }, " " )
    local playerName = getPlayerName ( thePlayer )
    for _, player in ipairs ( getElementsByType ( "player" ) ) do
        if isPlayerAdmin ( player ) then
            outputChatBox ( "#FF0000[#CCCCCCAdmin#FF0000] #FF0000".. playerName .."#CCCCCC: #FF0000".. text, player, 255, 255, 255, true )
        end
    end
end
addCommandHandler ( "ac", adminChat, true )
 
----[Admin Display Server]----
function outputMessage(text)
    outputChatBox ("#FFD700Admin#FFFF00: "..text, getRootElement(), 255, 255, 255, true ) --output that text
end
addEvent("ServerOutput",true)
addEventHandler("ServerOutput", root,outputMessage)
 
----[Hide Name Server]----
function hideNameTag ( source )
    if isPlayerNametagShowing ( source ) == true then
        setPlayerNametagShowing ( source, false )
    end
end
addEvent("hideName",true)
addEventHandler("hideName", root,hideNameTag)
 
function showNameTag ( source )
    setPlayerNametagShowing ( source, true )
end
addEvent("showName",true)
addEventHandler("showName", root, showNameTag)
 
----[HideRadar Blip]----
 
function hideRadarBlip ( source )
    for index, element in ipairs ( getAttachedElements ( source ) ) do
        if ( getElementType ( element ) == "blip" ) then
        destroyElement ( element )
        end        
    end
end
addEvent("hideBlip",true)
addEventHandler("hideBlip", resourceRoot,hideRadarBlip)
 
function createRadarBlip ( source )
    r = math.random(1,255)
    g = math.random(1,255)
    b = math.random(1,255)
    pBlip = createBlipAttachedTo ( source, 0, 2, r, g, b )
end
addEvent("createBlips",true)
addEventHandler("createBlips", resourceRoot, createRadarBlip)
 
function destroyBlipsAttachedTo()
    local attached = getAttachedElements ( source )
    if ( attached ) then
        for k,element in ipairs(attached) do
            if isElement ( element ) then
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsAttachedTo )
 
---- [invisibility - Player(ped)] -----
function invisible ( source )
    if not ( getElementAlpha(source) == 0 ) then
        setElementAlpha ( source, 0 )
    end
end
addEvent("noalpha",true)
addEventHandler("noalpha", resourceRoot, invisible)
function notinvisible ( source )
    if ( getElementAlpha(source) == 0 ) then
        setElementAlpha ( source, 255 )
    end
end
addEvent("noalpha1",true)
addEventHandler("noalpha1", resourceRoot, notinvisible)
 
------------------
---- Car Mods ----
------------------
 
---- [ God Mode ] ----
function nocardamage ( source )
    if ( isPedInVehicle ( source ) ) then
        if ( isVehicleDamageProof ( getPedOccupiedVehicle ( source ) )  == false )    then
            setVehicleDamageProof ( getPedOccupiedVehicle ( source ), true )
        end
    else
        outputChatBox ( "You must be inside a vehicle to set this.", source )
    end
end
addEvent("cardamage", true )
addEventHandler("cardamage", resourceRoot, nocardamage )
 
function disabledamage ( source )
    if ( isPedInVehicle ( source ) ) then
        setVehicleDamageProof ( getPedOccupiedVehicle ( source ), false )
    end
end
addEvent("nodamage", true)
addEventHandler("nodamage", resourceRoot, disabledamage )
 
---- [Car Invisibility] ----
function carinvis(source)
    if not ( getElementAlpha ( getPedOccupiedVehicle ( source ) ) == 0 ) then
        setElementAlpha ( getPedOccupiedVehicle ( source ), 0 )
    end
end
addEvent("nocaralpha",true)
addEventHandler("nocaralpha", resourceRoot,carinvis)
function tcarinvis(source)
    setElementAlpha ( getPedOccupiedVehicle ( source ), -1 )
end
addEvent("nocaralpha1",true)
addEventHandler("nocaralpha1", resourceRoot,tcarinvis)
 
--- [Kill] ---
function noElementHealth ( playerName, _source )
    -- local comment = table.concat( arg, " " )
    local logK =  _source .. " killed " .. playerName
    outputPanelLog(logK)
    local _source = getPlayerFromName ( _source )
    if isPlayerAdmin ( _source ) then
        local killed = setElementHealth ( getPlayerFromName ( playerName ), 0 )
    end
end
addEvent("nohp", true)
addEventHandler("nohp",resourceRoot, noElementHealth )
 
---- [ Set Nametag Text ] ----
function setnametxt ( playerName, newNametagText )
    setPlayerNametagText ( getPlayerFromName ( tostring(playerName) ), newNametagText )
end
addEvent ("nametxt",true)
addEventHandler("nametxt", resourceRoot, setnametxt )
 
---- [ Lock / UnLock ] ----
function slock ( targetLock )
   
Link to comment
  
local eof = nil
function outputPanelLog(outputs,comment)
    local panellog = nil
    if fileOpen ( "panellog.txt" ) then
        panellog = fileOpen ( "panellog.txt" )
        eof = fileGetSize ( panellog )
        fileSetPos ( panellog, eof )
    else
        panellog = fileCreate ( "panellog.txt" )
    end
    local time = getRealTime()
    local curTime = "[".. time.year+1900 .."-".. time.month+1 .."-"..time.monthday.." "..time.hour..":"..time.minute.."]"
    local str = outputs
    -- if string.len( comment ) > 0 then
        -- str = str .. "\\ " .. comment
    -- end
    str = str .. "\r\n"
    eof = fileWrite ( panellog, curTime .. " * FTAPANEL: "  .. outputs .. "." .. "\n" )
    fileSetPos ( panellog, eof )
    fileClose ( panellog )
    outputDebugString ( "Log Written" )
    for index, player in ipairs ( getElementsByType ( "player" ) ) do
        if isPlayerAdmin ( player ) then
            outputConsole ( " * FTAPANEL: " .. outputs .. ".", player )
        end
    end
end
 
function getdxtxt ( motdt, _source)
    local logK =  _source .. " set the dxMOTD to \"" .. motdt .. "\""
    outputPanelLog(logK)
    for _, player in ipairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( player, "rendertxt", player, motdt )
        triggerClientEvent ( player, "setBox", player, motdt )
    end
    motdhandle  = fileCreate("motdk.txt")
    if motdhandle then
        fileWrite(motdhandle , motdt)
        fileFlush (motdhandle)
        fileClose(motdhandle)
    end
end
addEvent ( "getdx", true )
addEventHandler ( "getdx", root, getdxtxt )
 
function readfile()
        local openmotd = fileOpen("motdk.txt")
        local motdt = fileRead (openmotd, 100)
        triggerClientEvent ( source, "rendertxt", source, motdt )
        triggerClientEvent ( source, "setBox", source, motdt )
        fileClose(openmotd)
end
addEvent("joinmotd",true)
addEventHandler("joinmotd", root, readfile)
 
 
 
function isPlayerAdmins(source)
    if isPlayerAdmin (source) then
         triggerClientEvent("ClientGui",getRootElement(),source)
    end
end
addCommandHandler ( "COMMAND NAME HERE", isPlayerAdmins )
 
function isPlayerAdmin(source)
    local accountname = getAccountName(getPlayerAccount(source))
    if isObjectInACLGroup("user." ..accountname, aclGetGroup("Admin")) then
        return true
    elseif isObjectInACLGroup("user." ..accountname, aclGetGroup("SuperModerator"))  then
        return true
    end
end
 
function isPlayerInTeam( thePlayer, teamName )
    local pTeam = getPlayerTeam( thePlayer )
    local fTeam = getTeamName( teamName )
    if ( pTeam ) and ( fTeam ) then
        if ( pTeam == fTeam ) then
            return true
        end
    end
end
 
 
function adminChat ( thePlayer, commandName, ... )
    local text = table.concat ( { ... }, " " )
    local playerName = getPlayerName ( thePlayer )
    for _, player in ipairs ( getElementsByType ( "player" ) ) do
        if isPlayerAdmin ( player ) then
            outputChatBox ( "#FF0000[#CCCCCCAdmin#FF0000] #FF0000".. playerName .."#CCCCCC: #FF0000".. text, player, 255, 255, 255, true )
        end
    end
end
addCommandHandler ( "ac", adminChat, true )
 
----[Admin Display Server]----
function outputMessage(text)
    outputChatBox ("#FFD700Admin#FFFF00: "..text, getRootElement(), 255, 255, 255, true ) --output that text
end
addEvent("ServerOutput",true)
addEventHandler("ServerOutput", root,outputMessage)
 
----[Hide Name Server]----
function hideNameTag ( source )
    if isPlayerNametagShowing ( source ) == true then
        setPlayerNametagShowing ( source, false )
    end
end
addEvent("hideName",true)
addEventHandler("hideName", root,hideNameTag)
 
function showNameTag ( source )
    setPlayerNametagShowing ( source, true )
end
addEvent("showName",true)
addEventHandler("showName", root, showNameTag)
 
----[HideRadar Blip]----
 
function hideRadarBlip ( source )
    for index, element in ipairs ( getAttachedElements ( source ) ) do
        if ( getElementType ( element ) == "blip" ) then
        destroyElement ( element )
        end        
    end
end
addEvent("hideBlip",true)
addEventHandler("hideBlip", resourceRoot,hideRadarBlip)
 
function createRadarBlip ( source )
    r = math.random(1,255)
    g = math.random(1,255)
    b = math.random(1,255)
    pBlip = createBlipAttachedTo ( source, 0, 2, r, g, b )
end
addEvent("createBlips",true)
addEventHandler("createBlips", resourceRoot, createRadarBlip)
 
function destroyBlipsAttachedTo()
    local attached = getAttachedElements ( source )
    if ( attached ) then
        for k,element in ipairs(attached) do
            if isElement ( element ) then
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsAttachedTo )
 
---- [invisibility - Player(ped)] -----
function invisible ( source )
    if not ( getElementAlpha(source) == 0 ) then
        setElementAlpha ( source, 0 )
    end
end
addEvent("noalpha",true)
addEventHandler("noalpha", resourceRoot, invisible)
function notinvisible ( source )
    if ( getElementAlpha(source) == 0 ) then
        setElementAlpha ( source, 255 )
    end
end
addEvent("noalpha1",true)
addEventHandler("noalpha1", resourceRoot, notinvisible)
 
------------------
---- Car Mods ----
------------------
 
---- [ God Mode ] ----
function nocardamage ( source )
    if ( isPedInVehicle ( source ) ) then
        if ( isVehicleDamageProof ( getPedOccupiedVehicle ( source ) )  == false )    then
            setVehicleDamageProof ( getPedOccupiedVehicle ( source ), true )
        end
    else
        outputChatBox ( "You must be inside a vehicle to set this.", source )
    end
end
addEvent("cardamage", true )
addEventHandler("cardamage", resourceRoot, nocardamage )
 
function disabledamage ( source )
    if ( isPedInVehicle ( source ) ) then
        setVehicleDamageProof ( getPedOccupiedVehicle ( source ), false )
    end
end
addEvent("nodamage", true)
addEventHandler("nodamage", resourceRoot, disabledamage )
 
---- [Car Invisibility] ----
function carinvis(source)
    if not ( getElementAlpha ( getPedOccupiedVehicle ( source ) ) == 0 ) then
        setElementAlpha ( getPedOccupiedVehicle ( source ), 0 )
    end
end
addEvent("nocaralpha",true)
addEventHandler("nocaralpha", resourceRoot,carinvis)
function tcarinvis(source)
    setElementAlpha ( getPedOccupiedVehicle ( source ), -1 )
end
addEvent("nocaralpha1",true)
addEventHandler("nocaralpha1", resourceRoot,tcarinvis)
 
--- [Kill] ---
function noElementHealth ( playerName, _source )
    -- local comment = table.concat( arg, " " )
    local logK =  _source .. " killed " .. playerName
    outputPanelLog(logK)
    local _source = getPlayerFromName ( _source )
    if isPlayerAdmin ( _source ) then
        local killed = setElementHealth ( getPlayerFromName ( playerName ), 0 )
    end
end
addEvent("nohp", true)
addEventHandler("nohp",resourceRoot, noElementHealth )
 
---- [ Set Nametag Text ] ----
function setnametxt ( playerName, newNametagText )
    setPlayerNametagText ( getPlayerFromName ( tostring(playerName) ), newNametagText )
end
addEvent ("nametxt",true)
addEventHandler("nametxt", resourceRoot, setnametxt )
 
---- [ Lock / UnLock ] ----
function slock ( targetLock )
    local targetvehicle = getPedOccupiedVehicle ( getPlayerFromName ( targetLock ) )
    if ( targetvehicle ) then
        setVehicleLocked ( targetvehicle, true )
    end
end
addEvent ("sslock",true)
addEventHandler("sslock", resourceRoot, slock )
 
function sunlock ( targetunlock )
    local targetsvehicle = getPedOccupiedVehicle ( getPlayerFromName ( targetunlock ) )
    if ( targetsvehicle ) then
        setVehicleLocked ( targetsvehicle, false )
    end
end
addEvent ("ssunlock",true)
addEventHandler("ssunlock", resourceRoot, sunlock )
 
---- [ Head/less ] ----
addEvent ("toghead",true)
function headless( playerName )
    if not (
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...