Jump to content

SQLWRONG


z24d

Recommended Posts

السلآم عليكم وش المشكلة بالكود#؟

exports.scoreboard:addScoreboardColumn('PlayTime') 
 addEvent("addTime",true) 
addEvent("removeTime",true) 
addEvent("ToServer",true) 
local t = { } 
local w = {} 
addEventHandler("ToServer",root, 
function (word,get,time) 
 if word and tonumber(get) and tonumber(time) then 
table.insert(w,{word,get}) 
setTimer(function () 
 for _,v in ipairs(w) do 
  if v[1] == word and v[2] == get then 
   table.remove(w,i) 
   end 
 end 
end,time*60*60*1000,1) 
end 
end 
) 
  
addEventHandler("onConsole",root, 
function (msg) 
 for _,v in ipairs(w) do 
  if msg == v[1] then 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
     if not getAccountData ( playeraccount, "time-"..msg) then 
      addPlayerTime(source,v[2]) 
      setAccountData( playeraccount, "time-"..msg,true) 
    end 
   end 
  end 
 end 
end 
) 
  
  
addEventHandler("addTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   addPlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    addPlayerTime(plr,time) 
    end 
 end 
end 
) 
  
  
addEventHandler("removeTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   removePlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    removePlayerTime(plr,time) 
    end 
 end 
end 
) 
  
  
addEventHandler("onResourceStart",resourceRoot, 
    function (      ) 
            executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime )" ) 
            outputDebugString ("Execute SQL Loadded !") 
    end 
) 
 function addPlayerTime(plr,time) 
 time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) + time 
 end 
  
  function removePlayerTime(plr,time) 
  time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) - time 
 end 
local t = { } 
  
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "PlayTime", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
function SaveDataOnQuit (  ) 
    local sValue = getElementData( source,'PlayTime' ) 
    local hour = tonumber( t[ source ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ source ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ source ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( source ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",serial) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
    end 
    t[ source ] = nil 
end 
addEventHandler("onPlayerQuit",root,SaveDataOnQuit) 
  
function SaveDataOnStop (  ) 
 for k,v in ipairs ( getElementsByType("player") ) do 
    local playeraccount = getPlayerAccount ( v ) 
    local sValue = getElementData( v,'PlayTime' ) 
    if not ( t [ v ] ) then 
        t [ v ]  = {    } 
    end 
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ v ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ v ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( v ) 
     local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
        end 
    end 
end 
addEventHandler("onResourceStop",resourceRoot,SaveDataOnStop) 
  
function GetDataOnStart ( ) 
 for _,v in ipairs ( getElementsByType ( "player" ) ) do 
 local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
   if not t[ v ] then 
    t[ v ] = {} 
   end 
        t[ v ]["hour"] = tonumber(Results[1]["Hours"]) 
        t[ v ]["min"] = tonumber(Results[1]["Minuts"]) 
        t[ v ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,GetDataOnStart) 
  
function GetDataOnJoin (    ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( source ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
            setElementData ( source, "PlayTime", Results[1]["PlayAllTime"] ) 
               if not t[ source ] then 
                    t[ source ] = {} 
                end 
            t[ source ]["hour"] = tonumber(Results[1]["Hours"]) 
            t[ source ]["min"] = tonumber(Results[1]["Minuts"]) 
            t[ source ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
addEventHandler("onPlayerJoin",root,GetDataOnJoin) 
  
  
addCommandHandler('لوحة', 
function(thePlayer) 
local account = getPlayerAccount ( thePlayer ) 
    if isObjectInACLGroup ( "user.".. getAccountName ( account ), aclGetGroup ( "Console" ) )   then 
        outputChatBox('* Welcome !',thePlayer,0,155,255,true) 
        triggerClientEvent(thePlayer,'openn',thePlayer) 
        else 
        outputChatBox('* You not have permission to Access',thePlayer,255,0,0,true) 
    end 
end 
) 
  

سيرفر^

  
GUIEditor = { 
    checkbox = {}, 
    staticimage = {}, 
    edit = {}, 
    button = {}, 
    window = {}, 
    label = {}, 
    gridlist = {} 
} 
  
    function cr() 
         GUIEditor.window[1] = guiCreateWindow(384, 91, 524, 553, "Mr.M[O]Dy", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1],false) 
        GUIEditor.gridlist[1] = guiCreateGridList(10, 56, 206, 327, false, GUIEditor.window[1]) 
        local PlayerName =  guiGridListAddColumn(GUIEditor.gridlist[1], " | إسم الآعب", 0.4) 
        local PlayerTime =  guiGridListAddColumn(GUIEditor.gridlist[1], "  | ساعات", 0.4) 
        GUIEditor.edit[1] = guiCreateEdit(247, 86, 246, 32, "", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(443, 57, 209, 19, "  | عدد الساعات :", false, GUIEditor.window[1]) 
        GUIEditor.checkbox[1] = guiCreateCheckBox(243, 149, 151, 18, "  | تحديد الجميع", false, false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(240, 322, 107, 45, "  | إعطاء ساعات", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF00FF00") 
        GUIEditor.button[2] = guiCreateButton(394, 322, 107, 45, "  | سحب الساعات", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF0000") 
        GUIEditor.edit[2] = guiCreateEdit(12, 29, 204, 21, "  | Search | البحث", false, GUIEditor.window[1]) 
        GUIEditor.label[2] = guiCreateLabel(1, 390, 566, 15, "_______________________________________________________________________________________________________________________", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[2], "default-bold-small") 
        guiLabelSetColor(GUIEditor.label[2], 255, 0, 0) 
        GUIEditor.label[3] = guiCreateLabel(421, 427, 90, 15, "  | كلمة التوزيع", false, GUIEditor.window[1]) 
        GUIEditor.edit[3] = guiCreateEdit(385, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[4] = guiCreateLabel(62, 427, 90, 15, "  | الساعات :", false, GUIEditor.window[1]) 
        GUIEditor.edit[4] = guiCreateEdit(47, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(216, 500, 133, 37, "  | Close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FF00FF00") 
        GUIEditor.edit[5] = guiCreateEdit(216, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[5] = guiCreateLabel(245, 427, 90, 15, "  | كلمة التوزيع !", false, GUIEditor.window[1]) 
        GUIEditor.staticimage[1] = guiCreateStaticImage(321, 187, 117, 96, "logo.png", false, GUIEditor.window[1]) 
    end 
addEventHandler("onClientResourceStart", resourceRoot,cr) 
addEventHandler("onClientGUIClick",root, 
function () 
 if source == GUIEditor.checkbox[1] then 
  if guiCheckBoxGetSelected(source) then 
  guiGridListSetSelectedItem(GUIEditor.gridlist[1],-1,-1) 
  end 
 elseif source == GUIEditor.gridlist[1] then 
  if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
  guiCheckBoxSetSelected(GUIEditor.checkbox[1],false) 
  end 
  elseif source == GUIEditor.edit[2] then 
   if guiGetText(source) == "بــحــث ...." then 
    guiSetText(source,"") 
   end 
  elseif source == GUIEditor.button[1] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("addTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("addTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
    elseif source == GUIEditor.button[2] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("removeTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("removeTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
  elseif source == GUIEditor.button[3] and guiGetText(GUIEditor.label[3]) ~= "" and guiGetText(GUIEditor.label[4]) ~= "" and guiGetText(GUIEditor.label[5]) ~= "" then 
  triggerServerEvent("ToServer",root,guiGetText(GUIEditor.edit[3]),guiGetText(GUIEditor.edit[4]),guiGetText(GUIEditor.edit[5])) 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
 end 
end 
) 
addEventHandler("onClientGUIChanged",root, 
function () 
 if source == GUIEditor.edit[2] then 
searchgd(GUIEditor.gridlist[1],guiGetText(source)) 
 end 
end 
) 
function getPlayerTime(plr) 
return getElementData(plr,"PlayTime") 
end 
function SetPlayersInGD( GridList ) 
 if GridList then 
  if getElementType ( GridList ) == "gui-gridlist" then 
   if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
  end 
 end 
end 
function searchgd(GridList,name) 
 if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     if not string.find(getPlayerName(v),name) then return end 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
end 
addEvent('openn',true) 
addEventHandler('openn',root, 
function () 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
  SetPlayersInGD(GUIEditor.gridlist[1]) 
  guiSetText(GUIEditor.edit[1],"") 
  guiSetText(GUIEditor.edit[2],"بــحــث ....") 
  guiSetText(GUIEditor.edit[3],"") 
  guiSetText(GUIEditor.edit[4],"") 
  guiSetText(GUIEditor.edit[5],"") 
end 
) 
  

Link to comment

-- # Client Side : 
  
GUIEditor = { 
    checkbox = {}, 
    staticimage = {}, 
    edit = {}, 
    button = {}, 
    window = {}, 
    label = {}, 
    gridlist = {} 
} 
  
    function cr() 
         GUIEditor.window[1] = guiCreateWindow(384, 91, 524, 553, "Mr.M[O]Dy", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1],false) 
        GUIEditor.gridlist[1] = guiCreateGridList(10, 56, 206, 327, false, GUIEditor.window[1]) 
        local PlayerName =  guiGridListAddColumn(GUIEditor.gridlist[1], " | إسم الآعب", 0.4) 
        local PlayerTime =  guiGridListAddColumn(GUIEditor.gridlist[1], "  | ساعات", 0.4) 
        GUIEditor.edit[1] = guiCreateEdit(247, 86, 246, 32, "", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(443, 57, 209, 19, "  | عدد الساعات :", false, GUIEditor.window[1]) 
        GUIEditor.checkbox[1] = guiCreateCheckBox(243, 149, 151, 18, "  | تحديد الجميع", false, false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(240, 322, 107, 45, "  | إعطاء ساعات", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF00FF00") 
        GUIEditor.button[2] = guiCreateButton(394, 322, 107, 45, "  | سحب الساعات", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF0000") 
        GUIEditor.edit[2] = guiCreateEdit(12, 29, 204, 21, "  | Search | البحث", false, GUIEditor.window[1]) 
        GUIEditor.label[2] = guiCreateLabel(1, 390, 566, 15, "_______________________________________________________________________________________________________________________", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[2], "default-bold-small") 
        guiLabelSetColor(GUIEditor.label[2], 255, 0, 0) 
        GUIEditor.label[3] = guiCreateLabel(421, 427, 90, 15, "  | كلمة التوزيع", false, GUIEditor.window[1]) 
        GUIEditor.edit[3] = guiCreateEdit(385, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[4] = guiCreateLabel(62, 427, 90, 15, "  | الساعات :", false, GUIEditor.window[1]) 
        GUIEditor.edit[4] = guiCreateEdit(47, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(216, 500, 133, 37, "  | Close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FF00FF00") 
        GUIEditor.edit[5] = guiCreateEdit(216, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[5] = guiCreateLabel(245, 427, 90, 15, "  | كلمة التوزيع !", false, GUIEditor.window[1]) 
        GUIEditor.staticimage[1] = guiCreateStaticImage(321, 187, 117, 96, "logo.png", false, GUIEditor.window[1]) 
    end 
addEventHandler("onClientResourceStart", resourceRoot,cr) 
addEventHandler("onClientGUIClick",root, 
function () 
 if source == GUIEditor.checkbox[1] then 
  if guiCheckBoxGetSelected(source) then 
  guiGridListSetSelectedItem(GUIEditor.gridlist[1],-1,-1) 
  end 
 elseif source == GUIEditor.gridlist[1] then 
  if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
  guiCheckBoxSetSelected(GUIEditor.checkbox[1],false) 
  end 
  elseif source == GUIEditor.edit[2] then 
   if guiGetText(source) == "بــحــث ...." then 
    guiSetText(source,"") 
   end 
  elseif source == GUIEditor.button[1] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("addTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("addTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
    elseif source == GUIEditor.button[2] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("removeTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("removeTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
  elseif source == GUIEditor.button[3] and guiGetText(GUIEditor.label[3]) ~= "" and guiGetText(GUIEditor.label[4]) ~= "" and guiGetText(GUIEditor.label[5]) ~= "" then 
  triggerServerEvent("ToServer",root,guiGetText(GUIEditor.edit[3]),guiGetText(GUIEditor.edit[4]),guiGetText(GUIEditor.edit[5])) 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
 end 
end 
) 
addEventHandler("onClientGUIChanged",root, 
function () 
 if source == GUIEditor.edit[2] then 
searchgd(GUIEditor.gridlist[1],guiGetText(source)) 
 end 
end 
) 
function getPlayerTime(plr) 
return getElementData(plr,"PlayTime") 
end 
function SetPlayersInGD( GridList ) 
 if GridList then 
  if getElementType ( GridList ) == "gui-gridlist" then 
   if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
  end 
 end 
end 
function searchgd(GridList,name) 
 if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     if not string.find(getPlayerName(v),name) then return end 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
end 
  
SetPlayersInGD(GUIEditor.gridlist[1]) 
  
addEvent('openn',true) 
addEventHandler('openn',root, 
function () 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
  SetPlayersInGD(GUIEditor.gridlist[1]) 
  guiSetText(GUIEditor.edit[1],"") 
  guiSetText(GUIEditor.edit[2],"بــحــث ....") 
  guiSetText(GUIEditor.edit[3],"") 
  guiSetText(GUIEditor.edit[4],"") 
  guiSetText(GUIEditor.edit[5],"") 
end 
) 

-- # Server Side : 
  
exports.scoreboard:addScoreboardColumn('PlayTime') 
  
addEvent("addTime",true) 
addEvent("removeTime",true) 
addEvent("ToServer",true) 
addEventHandler("onResourceStart",resourceRoot, 
    function (      ) 
            executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime )" ) 
            outputDebugString ("Execute SQL Loadded !") 
    end 
) 
local t = { } 
local w = {} 
 addEventHandler("ToServer",root, 
function (word,get,time) 
 if word and tonumber(get) and tonumber(time) then 
table.insert(w,{word,get}) 
setTimer(function () 
 for _,v in ipairs(w) do 
  if v[1] == word and v[2] == get then 
   table.remove(w,i) 
   end 
 end 
end,time*60*60*1000,1) 
end 
end 
) 
addEventHandler("onConsole",root, 
function (msg) 
 for _,v in ipairs(w) do 
  if msg == v[1] then 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
     if not getAccountData ( playeraccount, "time-"..msg) then 
      addPlayerTime(source,v[2]) 
      setAccountData( playeraccount, "time-"..msg,true) 
    end 
   end 
  end 
 end 
end 
) 
  
addEventHandler("addTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   addPlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    addPlayerTime(plr,time) 
    end 
 end 
end 
) 
  
addEventHandler("removeTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   removePlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    removePlayerTime(plr,time) 
    end 
 end 
end 
) 
 function addPlayerTime(plr,time) 
 time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) + time 
 end 
  function removePlayerTime(plr,time) 
  time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) - time 
 end 
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "PlayTime", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
addEventHandler("onPlayerQuit",root, 
function (  ) 
    local sValue = getElementData( source,'PlayTime' ) 
    local hour = tonumber( t[ source ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ source ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ source ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( source ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",serial) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
    end 
    t[ source ] = nil 
   end 
 ) 
  
addEventHandler("onResourceStop",resourceRoot, 
function (  ) 
 for k,v in ipairs ( getElementsByType("player") ) do 
    local playeraccount = getPlayerAccount ( v ) 
    local sValue = getElementData( v,'PlayTime' ) 
    if not ( t [ v ] ) then 
        t [ v ]  = {    } 
    end 
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ v ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ v ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( v ) 
     local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
            end 
        end 
   end 
) 
  
addEventHandler("onResourceStart",resourceRoot, 
function ( ) 
 for _,v in ipairs ( getElementsByType ( "player" ) ) do 
 local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
   if not t[ v ] then 
    t[ v ] = {} 
   end 
        t[ v ]["hour"] = tonumber(Results[1]["Hours"]) 
        t[ v ]["min"] = tonumber(Results[1]["Minuts"]) 
        t[ v ]["sec"] = tonumber(Results[1]["Seconds"]) 
        end 
    end 
 ) 
  
addEventHandler("onPlayerJoin",root, 
function (    ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( source ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
            setElementData ( source, "PlayTime", Results[1]["PlayAllTime"] ) 
               if not t[ source ] then 
                    t[ source ] = {} 
                end 
            t[ source ]["hour"] = tonumber(Results[1]["Hours"]) 
            t[ source ]["min"] = tonumber(Results[1]["Minuts"]) 
            t[ source ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
 ) 
  
  
addCommandHandler('لوحة', 
function(thePlayer) 
local account = getPlayerAccount ( thePlayer ) 
    if isObjectInACLGroup ( "user.".. getAccountName ( account ), aclGetGroup ( "Console" ) )   then 
        outputChatBox('* Welcome !',thePlayer,0,155,255,true) 
        triggerClientEvent(thePlayer,'openn',thePlayer) 
        else 
        outputChatBox('* You not have permission to Access',thePlayer,255,0,0,true) 
    end 
end 
) 
Link to comment

الله يعطيك العافية معليش تعبتك ض

بس تذكر أول عطيتني كود حق الكل مسج ملون ؟

ليش يطلعلي الملون كذآ والمو ملون شكل أخر

أنا ابي الملون نفس العادي

http://cdn.top4top.net/i_f52f378f331.png

dxText = {} 
dxText_mt = { __index = dxText }
local idAssign,idPrefix = 0,"c"
local g_screenX,g_screenY = guiGetScreenSize()
local visibleText = {}
------
local defaults = {
    fX                          = 0.5,
    fY                          = 0.5,
    bRelativePosition           = true,
    strText                     = "",
    bVerticalAlign              = "center",
    bHorizontalAlign            = "center",
    tColor                      = {255,255,255,255},
    fScale                      = 1,
    strFont                     = "default-bold-small",
    strType                     = "normal",
    tAttributes                 = {},
    bPostGUI                    = false,
    bClip                       = false,
    bHexColor                   = true,
    bWordWrap                   = true,
    bVisible                    = true,
    tBoundingBox                = false, --If a bounding box is not set, it will not be used.
    bRelativeBoundingBox        = true,
}
 
local validFonts = {
    default                     = true,
    ["default-bold-small"]            = true,
    clear                       = true,
    arial                       = true,
    pricedown                   = true,
    bankgothic                  = true,
    diploma                     = true,
    beckett                     = true,
}
 
local validTypes = {
    normal                      = true,
    shadow                      = true,
    border                      = true,
    stroke                      = true, --Clone of border
}
 
local validAlignTypes = {
    center                      = true,
    left                        = true,
    right                       = true,
}
 
function dxText:create( text, x, y, relative )
    assert(not self.fX, "attempt to call method 'create' (a nil value)")
    if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
        outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
        return false
    end
    local new = {}
    setmetatable( new, dxText_mt )
    --Add default settings
    for i,v in pairs(defaults) do
        new[i] = v
    end
    idAssign = idAssign + 1
    new.id = idPrefix..idAssign
    new.strText = text or new.strText
    new.fX = x or new.fX
    new.fY = y or new.fY
    if type(relative) == "boolean" then
        new.bRelativePosition = relative
    end
    visibleText[new] = true
    return new
end
 
function dxText:text(text)
    if type(text) ~= "string" then return self.strText end
    self.strText = text
    return true
end
 
function dxText:position(x,y,relative)
    if not tonumber(x) then return self.fX, self.fY end
    self.fX = x
    self.fY = y
    if type(relative) == "boolean" then
        self.bRelativePosition = relative
    else
        self.bRelativePosition = true
    end
    return true
end
 
function dxText:color(r,g,b,a)
    if not tonumber(r) then return unpack(self.tColor) end
    g = g or self.tColor[2]
    b = b or self.tColor[3]
    a = a or self.tColor[4]
    self.tColor = { r,g,b,a }
    return true
end
 
function dxText:scale(scale)
    if not tonumber(scale) then return self.fScale end
    self.fScale = scale
    return true
end
 
function dxText:visible(bool)
    if type(bool) ~= "boolean" then return self.bVisible end
    self.bVisible = bool
    if bool then
        visibleText[self] = true
    else
        visibleText[self] = nil
    end
    return true
end
 
function dxText:destroy()
    self.bDestroyed = true
    setmetatable( self, self )
    return true
end
 
function dxText:extent()
    local extent = dxGetTextWidth ( string.gsub(self.strText,  "#%x%x%x%x%x%x", ""), self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        extent = extent + self.tAttributes[1]
    end
    return extent
end
 
function dxText:height()
    local height = dxGetFontHeight ( self,fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        height = height + self.tAttributes[1]
    end
    return height
end
 
function dxText:font(font)
    if not validFonts[font] then return self.strFont end
    self.strFont = font
    return true
end
 
function dxText:postGUI(bool)
    if type(bool) ~= "boolean" then return self.bPostGUI end
    self.bPostGUI = bool
    return true
end
 
function dxText:clip(bool)
    if type(bool) ~= "boolean" then return self.bClip end
    self.bClip = bool
    return true
end
 
function dxText:wordWrap(bool)
    if type(bool) ~= "boolean" then return self.bWordWrap end
    self.bWordWrap = bool
    return true
end
 
function dxText:type(type,...)
    if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
    self.strType = type
    self.tAttributes = {...}
    return true
end
 
function dxText:align(horzA, vertA)
    if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
    vertA = vertA or self.bVerticalAlign
    self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
    return true
end
 
function dxText:boundingBox(left,top,right,bottom,relative)
    if left == nil then
        if self.tBoundingBox then
            return unpack(boundingBox)
        else
            return false
        end
    elseif tonumber(left) and tonumber(right) and tonumber(top) and tonumber(bottom) then
        self.tBoundingBox = {left,top,right,bottom}
        if type(relative) == "boolean" then
            self.bRelativeBoundingBox = relative
        else
            self.bRelativeBoundingBox = true
        end
    else
        self.tBoundingBox = false
    end
    return true
end
 
addEventHandler ( "onClientRender", getRootElement(),
    function()
        for self,_ in pairs(visibleText) do
            while true do
                if self.bDestroyed then
                    visibleText[self] = nil
                    break
                end
                local l,t,r,b
                --If we arent using a bounding box
                if not self.tBoundingBox then
                    --Decide if we use relative or absolute
                    local p_screenX,p_screenY = 1,1
                    if self.bRelativePosition then
                        p_screenX,p_screenY = g_screenX,g_screenY
                    end
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY
                    if self.bHorizontalAlign == "left" then
                        l = fX
                        r = fX + g_screenX
                    elseif self.bHorizontalAlign == "right" then
                        l = fX - g_screenX
                        r = fX
                    else
                        l = fX - g_screenX
                        r = fX + g_screenX
                    end
                    if self.bVerticalAlign == "top" then
                        t = fY
                        b = fY + g_screenY
                    elseif self.bVerticalAlign == "bottom" then
                        t = fY - g_screenY
                        b = fY
                    else
                        t = fY - g_screenY
                        b = fY + g_screenY
                    end
                elseif type(self.tBoundingBox) == "table" then
                    local b_screenX,b_screenY = 1,1
                    if self.bRelativeBoundingBox then
                        b_screenX,b_screenY = g_screenX,g_screenY
                    end
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4]
                    l = l*b_screenX
                    t = t*b_screenY
                    r = r*b_screenX
                    b = b*b_screenY
                end
                local type,att1,att2,att3,att4,att5 = self:type()
                if type == "border" or type == "stroke" then
                    att2 = att2 or 0
                    att3 = att3 or 0
                    att4 = att4
Link to comment

dxText = {} 
dxText_mt = { __index = dxText }
local idAssign,idPrefix = 0,"c"
local g_screenX,g_screenY = guiGetScreenSize()
local visibleText = {}
------
local defaults = {
    fX                          = 0.5,
    fY                          = 0.5,
    bRelativePosition           = true,
    strText                     = "",
    bVerticalAlign              = "center",
    bHorizontalAlign            = "center",
    tColor                      = {255,255,255,255},
    fScale                      = 1,
    strFont                     = "default",
    strType                     = "normal",
    tAttributes                 = {},
    bPostGUI                    = false,
    bClip                       = false,
    bHexColor                   = true,
    bWordWrap                   = true,
    bVisible                    = true,
    tBoundingBox                = false, --If a bounding box is not set, it will not be used.
    bRelativeBoundingBox        = true,
}
 
local validFonts = {
    default                     = true,
    ["default-bold-small"]            = true,
    clear                       = true,
    arial                       = true,
    pricedown                   = true,
    bankgothic                  = true,
    diploma                     = true,
    beckett                     = true,
}
 
local validTypes = {
    normal                      = true,
    shadow                      = true,
    border                      = true,
    stroke                      = true, --Clone of border
}
 
local validAlignTypes = {
    center                      = true,
    left                        = true,
    right                       = true,
}
 
function dxText:create( text, x, y, relative )
    assert(not self.fX, "attempt to call method 'create' (a nil value)")
    if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
        outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
        return false
    end
    local new = {}
    setmetatable( new, dxText_mt )
    --Add default settings
    for i,v in pairs(defaults) do
        new[i] = v
    end
    idAssign = idAssign + 1
    new.id = idPrefix..idAssign
    new.strText = text or new.strText
    new.fX = x or new.fX
    new.fY = y or new.fY
    if type(relative) == "boolean" then
        new.bRelativePosition = relative
    end
    visibleText[new] = true
    return new
end
 
function dxText:text(text)
    if type(text) ~= "string" then return self.strText end
    self.strText = text
    return true
end
 
function dxText:position(x,y,relative)
    if not tonumber(x) then return self.fX, self.fY end
    self.fX = x
    self.fY = y
    if type(relative) == "boolean" then
        self.bRelativePosition = relative
    else
        self.bRelativePosition = true
    end
    return true
end
 
function dxText:color(r,g,b,a)
    if not tonumber(r) then return unpack(self.tColor) end
    g = g or self.tColor[2]
    b = b or self.tColor[3]
    a = a or self.tColor[4]
    self.tColor = { r,g,b,a }
    return true
end
 
function dxText:scale(scale)
    if not tonumber(scale) then return self.fScale end
    self.fScale = scale
    return true
end
 
function dxText:visible(bool)
    if type(bool) ~= "boolean" then return self.bVisible end
    self.bVisible = bool
    if bool then
        visibleText[self] = true
    else
        visibleText[self] = nil
    end
    return true
end
 
function dxText:destroy()
    self.bDestroyed = true
    setmetatable( self, self )
    return true
end
 
function dxText:extent()
   local extent = dxGetTextWidth ( string.gsub(self.strText, "#%x%x%x%x%x%x", ""), self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        extent = extent + self.tAttributes[1]
    end
    return extent
end
 
function dxText:height()
    local height = dxGetFontHeight ( self,fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        height = height + self.tAttributes[1]
    end
    return height
end
 
function dxText:font(font)
    if not validFonts[font] then return self.strFont end
    self.strFont = font
    return true
end
 
function dxText:postGUI(bool)
    if type(bool) ~= "boolean" then return self.bPostGUI end
    self.bPostGUI = bool
    return true
end
 
function dxText:clip(bool)
    if type(bool) ~= "boolean" then return self.bClip end
    self.bClip = bool
    return true
end
 
function dxText:wordWrap(bool)
    if type(bool) ~= "boolean" then return self.bWordWrap end
    self.bWordWrap = bool
    return true
end
 
function dxText:type(type,...)
    if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
    self.strType = type
    self.tAttributes = {...}
    return true
end
 
function dxText:align(horzA, vertA)
    if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
    vertA = vertA or self.bVerticalAlign
    self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
    return true
end
 
function dxText:boundingBox(left,top,right,bottom,relative)
    if left == nil then
        if self.tBoundingBox then
            return unpack(boundingBox)
        else
            return false
        end
    elseif tonumber(left) and tonumber(right) and tonumber(top) and tonumber(bottom) then
        self.tBoundingBox = {left,top,right,bottom}
        if type(relative) == "boolean" then
            self.bRelativeBoundingBox = relative
        else
            self.bRelativeBoundingBox = true
        end
    else
        self.tBoundingBox = false
    end
    return true
end
 
addEventHandler ( "onClientRender", getRootElement(),
    function()
        for self,_ in pairs(visibleText) do
            while true do
                if self.bDestroyed then
                    visibleText[self] = nil
                    break
                end
                local l,t,r,b
                --If we arent using a bounding box
                if not self.tBoundingBox then
                    --Decide if we use relative or absolute
                    local p_screenX,p_screenY = 1,1
                    if self.bRelativePosition then
                        p_screenX,p_screenY = g_screenX,g_screenY
                    end
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY
                    if self.bHorizontalAlign == "left" then
                        l = fX
                        r = fX + g_screenX
                    elseif self.bHorizontalAlign == "right" then
                        l = fX - g_screenX
                        r = fX
                    else
                        l = fX - g_screenX
                        r = fX + g_screenX
                    end
                    if self.bVerticalAlign == "top" then
                        t = fY
                        b = fY + g_screenY
                    elseif self.bVerticalAlign == "bottom" then
                        t = fY - g_screenY
                        b = fY
                    else
                        t = fY - g_screenY
                        b = fY + g_screenY
                    end
                elseif type(self.tBoundingBox) == "table" then
                    local b_screenX,b_screenY = 1,1
                    if self.bRelativeBoundingBox then
                        b_screenX,b_screenY = g_screenX,g_screenY
                    end
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4]
                    l = l*b_screenX
                    t = t*b_screenY
                    r = r*b_screenX
                    b = b*b_screenY
                end
                local type,att1,att2,att3,att4,att5 = self:type()
                if type == "border" or type == "stroke" then
                    att2 = att2 or 0
                    att3 = att3 or 0
                    att4 = att4
Link to comment

تفضل هذا نفس العادي

dxText = {} 
dxText_mt = { __index = dxText }
local idAssign,idPrefix = 0,"c"
local g_screenX,g_screenY = guiGetScreenSize()
local visibleText = {}
------
local defaults = {
    fX                          = 0.5,
    fY                          = 0.5,
    bRelativePosition           = true,
    strText                     = "",
    bVerticalAlign              = "center",
    bHorizontalAlign            = "center",
    tColor                      = {255,255,255,255},
    fScale                      = 1,
    strFont                     = "default",
    strType                     = "normal",
    tAttributes                 = {},
    bColorCoded                     = true,
    bPostGUI                    = false,
    bClip                       = false,
    bWordWrap                   = true,
    bVisible                    = true,
    tBoundingBox                = false, --If a bounding box is not set, it will not be used.
    bRelativeBoundingBox        = true,
}
 
local validFonts = {
    default                     = true,
    ["default-bold"]            = true,
    clear                       = true,
    arial                       = true,
    pricedown                   = true,
    bankgothic                  = true,
    diploma                     = true,
    beckett                     = true,
}
 
local validTypes = {
    normal                      = true,
    shadow                      = true,
    border                      = true,
    stroke                      = true, --Clone of border
}
 
local validAlignTypes = {
    center                      = true,
    left                        = true,
    right                       = true,
}
 
function dxText:create( text, x, y, relative )
    assert(not self.fX, "attempt to call method 'create' (a nil value)")
    if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
        outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
        return false
    end
    local new = {}
    setmetatable( new, dxText_mt )
    --Add default settings
    for i,v in pairs(defaults) do
        new[i] = v
    end
    idAssign = idAssign + 1
    new.id = idPrefix..idAssign
    new.strText = text or new.strText
    new.fX = x or new.fX
    new.fY = y or new.fY
    if type(relative) == "boolean" then
        new.bRelativePosition = relative
    end
    visibleText[new] = true
    return new
end
 
function dxText:text(text)
    if type(text) ~= "string" then return self.strText end
    self.strText = text
    return true
end
 
function dxText:position(x,y,relative)
    if not tonumber(x) then return self.fX, self.fY end
    self.fX = x
    self.fY = y
    if type(relative) == "boolean" then
        self.bRelativePosition = relative
    else
        self.bRelativePosition = true
    end
    return true
end
 
function dxText:color(r,g,b,a)
    if not tonumber(r) then return unpack(self.tColor) end
    g = g or self.tColor[2]
    b = b or self.tColor[3]
    a = a or self.tColor[4]
    self.tColor = { r,g,b,a }
    return true
end
 
function dxText:scale(scale)
    if not tonumber(scale) then return self.fScale end
    self.fScale = scale
    return true
end
 
function dxText:visible(bool)
    if type(bool) ~= "boolean" then return self.bVisible end
    self.bVisible = bool
    if bool then
        visibleText[self] = true
    else
        visibleText[self] = nil
    end
    return true
end
 
function dxText:destroy()
    self.bDestroyed = true
    setmetatable( self, self )
    return true
end
 
function dxText:extent()
    local extent = dxGetTextWidth ( self.strText, self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        extent = extent + self.tAttributes[1]
    end
    return extent
end
 
function dxText:height()
    local height = dxGetFontHeight ( self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        height = height + self.tAttributes[1]
    end
    return height
end
 
function dxText:font(font)
    if not validFonts[font] then return self.strFont end
    self.strFont = font
    return true
end
 
function dxText:colorCoded(bool)
    if type(bool) ~= "boolean" then return self.bColorCoded end
    self.bColorCoded = bool
    return true
end
 
function dxText:postGUI(bool)
    if type(bool) ~= "boolean" then return self.bPostGUI end
    self.bPostGUI = bool
    return true
end
 
function dxText:clip(bool)
    if type(bool) ~= "boolean" then return self.bClip end
    self.bClip = bool
    return true
end
 
function dxText:wordWrap(bool)
    if type(bool) ~= "boolean" then return self.bWordWrap end
    self.bWordWrap = bool
    return true
end
 
function dxText:type(type,...)
    if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
    self.strType = type
    self.tAttributes = {...}
    return true
end
 
function dxText:align(horzA, vertA)
    if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
    vertA = vertA or self.bVerticalAlign
    self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
    return true
end
 
function dxText:boundingBox(left,top,right,bottom,relative)
    if left == nil then
        if self.tBoundingBox then
            return unpack(boundingBox)
        else
            return false
        end
    elseif tonumber(left) and tonumber(right) and tonumber(top) and tonumber(bottom) then
        self.tBoundingBox = {left,top,right,bottom}
        if type(relative) == "boolean" then
            self.bRelativeBoundingBox = relative
        else
            self.bRelativeBoundingBox = true
        end
    else
        self.tBoundingBox = false
    end
    return true
end
 
addEventHandler ( "onClientRender", getRootElement(),
    function()
        for self,_ in pairs(visibleText) do
            while true do
                if self.bDestroyed then
                    visibleText[self] = nil
                    break
                end
                local l,t,r,b
                --If we arent using a bounding box
                if not self.tBoundingBox then
                    --Decide if we use relative or absolute
                    local p_screenX,p_screenY = 1,1
                    if self.bRelativePosition then
                        p_screenX,p_screenY = g_screenX,g_screenY
                    end
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY
                    if self.bHorizontalAlign == "left" then
                        l = fX
                        r = fX + g_screenX
                    elseif self.bHorizontalAlign == "right" then
                        l = fX - g_screenX
                        r = fX
                    else
                        l = fX - g_screenX
                        r = fX + g_screenX
                    end
                    if self.bVerticalAlign == "top" then
                        t = fY
                        b = fY + g_screenY
                    elseif self.bVerticalAlign == "bottom" then
                        t = fY - g_screenY
                        b = fY
                    else
                        t = fY - g_screenY
                        b = fY + g_screenY
                    end
                elseif type(self.tBoundingBox) == "table" then
                    local b_screenX,b_screenY = 1,1
                    if self.bRelativeBoundingBox then
                        b_screenX,b_screenY = g_screenX,g_screenY
                    end
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4]
                    l = l*b_screenX
                    t = t*b_screenY
                    r = r*b_screenX
                    b = b*b_screenY
Link to comment
dxText = {} 
dxText_mt = { __index = dxText }
local idAssign,idPrefix = 0,"c"
local g_screenX,g_screenY = guiGetScreenSize()
local visibleText = {}
------
local defaults = {
    fX                          = 0.5,
    fY                          = 0.5,
    bRelativePosition           = true,
    strText                     = "",
    bVerticalAlign              = "center",
    bHorizontalAlign            = "center",
    tColor                      = {255,255,255,255},
    fScale                      = 1,
    strFont                     = "default",
    strType                     = "normal",
    tAttributes                 = {},
    bColorCoded                     = true,
    bPostGUI                    = false,
    bClip                       = false,
    bWordWrap                   = true,
    bVisible                    = true,
    tBoundingBox                = false, --If a bounding box is not set, it will not be used.
    bRelativeBoundingBox        = true,
}
 
local validFonts = {
    default                     = true,
    ["default-bold"]            = true,
    clear                       = true,
    arial                       = true,
    pricedown                   = true,
    bankgothic                  = true,
    diploma                     = true,
    beckett                     = true,
}
 
local validTypes = {
    normal                      = true,
    shadow                      = true,
    border                      = true,
    stroke                      = true, --Clone of border
}
 
local validAlignTypes = {
    center                      = true,
    left                        = true,
    right                       = true,
}
 
function dxText:create( text, x, y, relative )
    assert(not self.fX, "attempt to call method 'create' (a nil value)")
    if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
        outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
        return false
    end
    local new = {}
    setmetatable( new, dxText_mt )
    --Add default settings
    for i,v in pairs(defaults) do
        new[i] = v
    end
    idAssign = idAssign + 1
    new.id = idPrefix..idAssign
    new.strText = text or new.strText
    new.fX = x or new.fX
    new.fY = y or new.fY
    if type(relative) == "boolean" then
        new.bRelativePosition = relative
    end
    visibleText[new] = true
    return new
end
 
function dxText:text(text)
    if type(text) ~= "string" then return self.strText end
    self.strText = text
    return true
end
 
function dxText:position(x,y,relative)
    if not tonumber(x) then return self.fX, self.fY end
    self.fX = x
    self.fY = y
    if type(relative) == "boolean" then
        self.bRelativePosition = relative
    else
        self.bRelativePosition = true
    end
    return true
end
 
function dxText:color(r,g,b,a)
    if not tonumber(r) then return unpack(self.tColor) end
    g = g or self.tColor[2]
    b = b or self.tColor[3]
    a = a or self.tColor[4]
    self.tColor = { r,g,b,a }
    return true
end
 
function dxText:scale(scale)
    if not tonumber(scale) then return self.fScale end
    self.fScale = scale
    return true
end
 
function dxText:visible(bool)
    if type(bool) ~= "boolean" then return self.bVisible end
    self.bVisible = bool
    if bool then
        visibleText[self] = true
    else
        visibleText[self] = nil
    end
    return true
end
 
function dxText:destroy()
    self.bDestroyed = true
    setmetatable( self, self )
    return true
end
 
function dxText:extent()
    local extent = dxGetTextWidth ( self.strText, self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        extent = extent + self.tAttributes[1]
    end
    return extent
end
 
function dxText:height()
    local height = dxGetFontHeight ( self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        height = height + self.tAttributes[1]
    end
    return height
end
 
function dxText:font(font)
    if not validFonts[font] then return self.strFont end
    self.strFont = font
    return true
end
 
function dxText:colorCoded(bool)
    if type(bool) ~= "boolean" then return self.bColorCoded end
    self.bColorCoded = bool
    return true
end
 
function dxText:postGUI(bool)
    if type(bool) ~= "boolean" then return self.bPostGUI end
    self.bPostGUI = bool
    return true
end
 
function dxText:clip(bool)
    if type(bool) ~= "boolean" then return self.bClip end
    self.bClip = bool
    return true
end
 
function dxText:wordWrap(bool)
    if type(bool) ~= "boolean" then return self.bWordWrap end
    self.bWordWrap = bool
    return true
end
 
function dxText:type(type,...)
    if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
    self.strType = type
    self.tAttributes = {...}
    return true
end
 
function dxText:align(horzA, vertA)
    if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
    vertA = vertA or self.bVerticalAlign
    self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
    return true
end
 
function dxText:boundingBox(left,top,right,bottom,relative)
    if left == nil then
        if self.tBoundingBox then
            return unpack(boundingBox)
        else
            return false
        end
    elseif tonumber(left) and tonumber(right) and tonumber(top) and tonumber(bottom) then
        self.tBoundingBox = {left,top,right,bottom}
        if type(relative) == "boolean" then
            self.bRelativeBoundingBox = relative
        else
            self.bRelativeBoundingBox = true
        end
    else
        self.tBoundingBox = false
    end
    return true
end
 
addEventHandler ( "onClientRender", getRootElement(),
    function()
        for self,_ in pairs(visibleText) do
            while true do
                if self.bDestroyed then
                    visibleText[self] = nil
                    break
                end
                local l,t,r,b
                --If we arent using a bounding box
                if not self.tBoundingBox then
                    --Decide if we use relative or absolute
                    local p_screenX,p_screenY = 1,1
                    if self.bRelativePosition then
                        p_screenX,p_screenY = g_screenX,g_screenY
                    end
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY
                    if self.bHorizontalAlign == "left" then
                        l = fX
                        r = fX + g_screenX
                    elseif self.bHorizontalAlign == "right" then
                        l = fX - g_screenX
                        r = fX
                    else
                        l = fX - g_screenX
                        r = fX + g_screenX
                    end
                    if self.bVerticalAlign == "top" then
                        t = fY
                        b = fY + g_screenY
                    elseif self.bVerticalAlign == "bottom" then
                        t = fY - g_screenY
                        b = fY
                    else
                        t = fY - g_screenY
                        b = fY + g_screenY
                    end
                elseif type(self.tBoundingBox) == "table" then
                    local b_screenX,b_screenY = 1,1
                    if self.bRelativeBoundingBox then
                        b_screenX,b_screenY = g_screenX,g_screenY
                    end
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4]
                    l = l*b_screenX
                    t = t*b_screenY
                    r = r*b_screenX
                    b = b*b_screenY
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...