Jump to content

cheez3d

Members
  • Posts

    290
  • Joined

  • Last visited

Everything posted by cheez3d

  1. cheez3d

    Solved

    addEventHandler("onPlayerChangeNick", getRootElement(), function(oldNick, newNick) if (newNick) then outputChatBox(""..oldNick.." --> "..newNick.."",getRootElement(), 255, 100, 100, true) local logFile = fileExists("logs/logs.log") and fileOpen("logs/logs.log") or fileCreate("logs/logs.log") if (logFile) then local size = fileGetSize(logFile) fileSetPos(logFile, size) fileWrite(logFile, ""..oldNick.." --> "..newNick.."") fileClose(logFile) end end end)
  2. local Table = {level = 1}; Table.maxcount = 1000+1000*Table.level
  3. And this should also be available for dxCreateShader!
  4. More like math.randomseed(getRealTime().timestamp);
  5. cheez3d

    [[text]]

    Lua makes use of the C string formatting. %d represents a digit and %s represents an array of characters. http://www.cplusplus.com/reference/cstdio/printf/ When you do print(("%d"):format(10)) it will print 10 instead of %d (it replaces %d with 10). When you do print(("String: %s"):format("This is my string!")) it will print "String: This is my string!" instead of "String: %s".
  6. http://wiki.multitheftauto.com/wiki/Element_tree You could also make it even faster by only ataching the event to the menuButton instead of guiRoot. local RenderHandler = function() dxDrawImage(screenWidth/2.20,screenHeight/1.50,150,40,'images/exitmenu_hover.png'); end; local ButtonEnter = function() addEventHandler("onClientRender",root,RenderHandler); end; addEventHandler("onClientMouseEnter",menuButton,ButtonEnter,false); local ButtonExit = function() removeEventHandler("onClientRender",root,RenderHandler); end; addEventHandler("onClientMouseLeave",menuButton,ButtonExit,false) That 4th false in the addEventHandler will make sure the event will not propagate trough the parent and the children of the button.
  7. cheez3d

    [[text]]

    local String = [[Name: %s UpTime: %s Occupation: %s Health: %d Group: %s Group Rank: %s Cash %d Wanted Level: %d Country: %s]]; guiSetText(GUIEditor.label[1],String:format(playername,getElementData(thePlayer,"UpTime"),getElementData(thePlayer,"Occupation"),getElementHealth(thePlayer),getElementData(thePlayer,"Group"),getElementData(thePlayer,"GroupRank"),getPlayerMoney(thePlayer),getPlayerWantedLevel(thePlayer),getElementData(thePlayer,"Country")));
  8. Stop posting if you don't know what you're talking about...
  9. No. Every resourceRoot has it's own guiRoot.
  10. Don't use root, use guiRoot.
  11. cheez3d

    Table :s

    local Punishments = {}; -- Table to store punishments; local PunishPlayer = function(punisher,player,type,time) -- Player to punish, type of punishment, time; if Punishments[player] then return false; -- Player is already punished; end; Punishments[player] = { Punisher = punisher, Time = time, Type = type; }; return Punishments[player]; end; addCommandHandler("punish",function(punisher,_,player,type,time) PunishPlayer(punisher,getPlayerFromName(player),type,time); end);
  12. tocolor() converts your numbers to Hex and then it converts that Hex back to one decimal number. tocolor(255,255,255) => 0xFFFFFF => 16777215 (without alpha); tocolor(255,255,255,255) => 0xFFFFFFFF => 4294967295 (with alpha); To get the Hex back from the decimal number just format the string "%x" like this: ("%x"):format(tocolor(r,g,b)) And that is your Hex. If you want to go deeper and convert that Hex back to 3 or 4 decimals you do it like this: local Hex = ("%x"):format(tocolor(r,g,b)); local Color = {}; for i = 1,6,2 do table.insert(Color,tonumber(Hex:sub(i,i+1),16)); -- supply 16 as an argument because we are converting from base 16; end; And that is your RGB.
  13. cheez3d

    Hex Color

    Or if you want to convert from 3 or 4 numbers without tocolor: local ConvertRGBToHex = function(r,g,b,a) if a then return ("%02x%02x%02x%02x"):format(r,g,b,a); end; return ("%02x%02x%02x"):format(r,g,b); end;
  14. addEventHandler("onPlayerWasted",root,function(_,killer) if killer and getElementType(killer) == "player" then local VictimX,VictimY,VictimZ = getElementPosition(source); local KillerX,KillerY,KillerZ = getElementPosition(killer); local Distance = getDistanceBetweenPoints3D(VictimX,VictimY,VictimZ,KillerX,KillerY,KillerZ); outputChatBox(getPlayerName(source).." was killed by "..getPlayerName(killer).." from a distance of "..tostring(Distance).."!",root,255,255,255); end; end);
  15. You can use timestamps and then convert the difference to normal time.
  16. if not username:find("%W") then if (accountAdded) then exports.gtc:sendMessage("You have successfully registered. Username: "..username..", Password: "..password,0,255,0,source); triggerClientEvent(source,"hideRegisterWindow",source); end; else triggerClientEvent(source,"set_warning_text",source,"MG:RP Register","Choose a different username or password."); end;
  17. Use %W instead of ^%w. As for your problem: if username:find("%W") then outputChatBox("Your name contains invalid characters!"); else -- Valid username; end;
  18. cheez3d

    Help pls,

    addEventHandler("onClientPreRender",root,function(delta) outputChatBox(tostring(1000/delta)); -- This is the player's FPS; end); Use this to calculate the player's FPS and set a minimum amount you need to have to play, otherwise kick the player.
  19. https://wiki.multitheftauto.com/wiki/Cl ... _functions https://wiki.multitheftauto.com/wiki/Se ... _functions
  20. I'm talking about this: Is there any possible way you can fix this using MTA?
  21. local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); local StartTick,Duration,EndTick = nil,5000,nil; local Debounce = false; local function RenderHandler() local CurrentTick = getTickCount(); -- get the current tick; local Progress = (CurrentTick-StartTick)/Duration; -- calculate the progress between 0 and 1 using simple math; local Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad"); dxDrawText("This text is fading in...",ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"bankgothic"); if CurrentTick>=EndTick then -- if the animation is finished; StartTick,EndTick = nil,nil; -- clear variables; removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler; Debounce = false; -- we can now use /dx again; end; end; addCommandHandler("dx",function() if not Debounce then -- if the text isn't already rendering; Debounce = true; StartTick = getTickCount(); -- get the current tick as the start tick of the animation; EndTick = StartTick+Duration; -- calculate the end tick; addEventHandler("onClientRender",root,RenderHandler); -- add the render handler only when you type the command; end; end); I have not tested it, but it should work.
  22. local Lobby = {}; Lobby.__index = Lobby; function Lobby:Constructor(player) if not self.m_Lobby[player] then self.m_Lobby[player] = {}; end; local mL = self.m_Lobby[player]; mL.public = false; mL.name = nil; mL.maxPlayers = nil; mL.map = nil; end; function Lobby:New() local Object = setmetatable({ m_Lobby = {}; maps = { {0,0,3,1}; }; },self); -- create our object; if Object.Constructor then addEventHandler("onPlayerResourceStart",root,function() Object:Constructor(client); -- use syntactic sugar; end); end; return Object; end; I think this is what you wanted.
×
×
  • Create New...