Jump to content

Noki

Members
  • Posts

    850
  • Joined

  • Last visited

Everything posted by Noki

  1. Check if the resource the file is in is running, and check if the file exists.
  2. On the server side, you can encode the .dff/.txd files with teaEncode and send them to the client (you can encode the actual files, or load the files in when the resource starts and perform the encoding - I would do the former). Once they have been downloaded, you can send the key you used to encode them to the client. Once you have all that, decode the mods and load the replacements in memory. I haven't done it before, but this is the way I would go about making this system.
  3. viewtopic.php?f=91&t=47897 setTimer( function () for _, vehicle in ipairs(getElementsByType("vehicle")) do -- Code end end, 15000, 0 )
  4. Anubhav, 'organisation' is how it's spelled in Australia, Britain and New Zealand. And Simple01 was correct - it is 'separate' (separation), not 'seperate'. Anyway, Dealman made a very nice guide on keeping your code clean. Although I don't agree with 100% of it (everyone has different coding preferences, which is perfectly okay), it is a very good guide on the principles of setting out code nicely. For resources, I would recommend using carpets, which are folders denoted by square brackets, like "[private]" or "[admin]" to organise resources. MTA does this in their default resources and it works quite nicely. Maps are separated from the admin panel and runcode. Which makes perfect sense. Put all resources that fall within the scope of the carpet name in the carpet. So don't put the resource with all your mods in "[admin]" for example. Anubhav brought up indentation, which is a great point. Indentation helps you organise your code, especially if it is long and has lots of nests. I use tabs to indent my code. . At the end of the day, that's personal preference. Indents should be done on a new line after a control statement (if, for, do, while). Spacing is also relatively important in regards to the readability of code. Some like to put spaces between 'if' and the bracket that follows, some don't. Some like to put spaces between every bracket, some don't. Some space their arguments, some don't. Personal preference yet again. Although I think you should space properly like you do in the English language (eg: 1, 2, 3). Callum, an MTA contributor, doesn't put any spaces between his arguments (eg: 1,2,3). mabako's spacing scheme in mta-paradise: As for how you organise files within a resource, that's tricky. It's good to put your images in a sub folder (:resourceName/images/), similar to how web developers do so with '/src/' and others of the like. I like to have two files in small scripts - 'server.lua' and 'client.lua'. I write all of my server-sided code in one, and all of my client-sided code in the other. For bigger resources, I tend to prefix my files with their type ('c_' and 's_') followed by their purpose or what they contain (eg: 'c_utils.lua' and 's_sync.lua'). And as Simple01 said, OOP is the way to go. I personally think 'player.name' is much easier to read than 'getPlayerName(player)'. Less typing and more elegant code for the same result? Yes please! Metatables are another thing and can make things overly complicated at times, but also very simple at other times. Try them out for yourself.
  5. First off, you must add an event using addEvent on the side (client or server) which you want to pass data to. Make sure to make the second parameter (after the name of the event) true, so it can be executed from the other end (client -> server & server -> client). Every event must have a handler (ie a function that handles what happens when the event is triggered), so we add one in with addEventHandler. Usually tying it to the root element or resourceRoot element will suffice. Remember, it triggers down the element tree, so be careful with what element you tie it to. From here, we just triggerClientEvent and triggerServerEvent. triggerClientEvent is used to transfer data to a client. You can specify which client(s) you want it to trigger on and any other data you want to pass. triggerServerEvent is used to transfer data to the server. There is a source parameter, which can be a little confusing, especially if the source is just the localPlayer. So for safety and ease of use, we can use client on the server if the source is the localPlayer and set the source parameter to 'resourceRoot'. There is also triggerLatentClientEvent if you don't want to interrupt traffic. It works the same as triggerClientEvent. Have a look at the event system for further explanation.
  6. Noki

    color code

    Here is a snippet of some old code from CSG. It checks for hex, and if a player's name is just hex (which some people do, I don't know why), it will assign them a random name. -- Remove hex function removeHEX(oldNick, newNick) local name = getPlayerName(source) if newNick then name = newNick end if name:find("#%x%x%x%x%x%x") then local name = name:gsub("#%x%x%x%x%x%x","") if name:len() > 0 then setPlayerName(source, name) else setPlayerName(source, "Player"..tostring(math.random(10000,99990))) end if newNick then cancelEvent() end end end addEventHandler("onPlayerJoin", root, removeHEX) addEventHandler("onPlayerChangeNick", root, removeHEX)
  7. You're not passing 'v' to the timer inside onResourceStart. Line 4: setTimer(function (v) Line 11: end, 500, 1, v)
  8. Noki

    Miner job.

    Looking at the video, there would definitely need to be some work with animations and objects. The objects also get attached to the player, so the bone_attach resource could be useful for that. There's an inventory, which would need to be made with tables. The player can't run when holding a rock, so toggleControl would need to be used. As with any problem solving task, here are many ways to go about it, and there really isn't a set of functions that you "should" use. However, I am willing to bet that you will definitely be using animations and objects at bare minimum. Also, be creative. This job has already been made this way by SeeMTA. Don't try and replicate it. Make it a bit different and more interesting if you can.
  9. Use isTransferBoxActive to check if a player is downloading. You can freeze players with setElementFrozen. I also recommend toggleAllControls as an extra precautionary measure as frozen players can still aim. isTransferBoxActive setElementFrozen toggleAllControls
  10. That's probably for an older version of IP Board, judging from the post date. I doubt it will still be compatible with a newer version.
  11. .db files are locked while they are open or being modified. Use setAccountData to modify it instead.
  12. You give the partial names of the two players when you type the command. So you could write "/getdist noki overmind" and getPlayerFromPartialName would try and resolve these partial names into player elements. The function works by checking all players and seeing if the string given (the partial name you entered in /getdist) is a close match to the name of an online player. If there is a match, it will return a player element. If my name in-game was "[MTA]Noki", it would still resolve "noki" into my player element. The same would go for you. "overmind" would get resolved to your player element, even if that wasn't your exact name.
  13. The problem lies in the parameters you have for the distCmd function. You have all the arguments for coordinates specified, but not the ones for the player names. You can also remove the player1 and player2 lines as they serve no purpose. You also don't have 'player' defined in your code. If we are talking about the player who typed the command, we need to specify it in the function's arguments. function distCmd(player, cmd, pla3, pla4) You can also remove the if statement that checks if cmd is "getdist". You're using a command handler, so the function will only be called if you type '/getdist'. However, if you were using the onPlayerCommand event, you would need that if statement.
  14. You can use getPlayerFromPartialName.
  15. For what? Web, operating system, game, search engine or a web browser? Each programming language serves its own function. Some better than others. But no language is really objectively better than another for general use (unless it's something ridiculous like whitespace). It's like a toolbox. Each tool within serves its own purpose. I would have a much easier time screwing a screw with a screwdriver than I would with a hammer.
  16. https://wiki.multitheftauto.com/wiki/Sc ... ing_Reused Far fetched, but you shouldn't leave any stone unturned. It's a possibility that there's some other referencing error in one of your scripts, like others have suggested.
  17. Correct me if I'm wrong, but as long as any client-side files haven't changed, the file transfer box shouldn't appear when starting/restarting/stopping a resource.
  18. No, because if clients were able to use fetchRemote and callRemote, a server with a large amount of players could potentially set up a large botnet.
  19. Noki

    Search box

    function IM.onSearchForPlayer() phone.im.gridlist["players"]:clear() local text = phone.im.edit["search_players"].text for _, plr in ipairs(Element.getAllByType("player")) do if (plr ~= localPlayer and plr.name:lower():find(text:lower())) then local row = guiGridListAddRow(phone.im.gridlist["players"]) guiGridListSetItemText(phone.im.gridlist["players"], row, 1, plr.name, false, false) end end end addEventHandler("onClientGUIChanged", phone.im.edit["search_players"], IM.onSearchForPlayer, false) Here's some code I used to filter players in a gridlist based on name. You can do the same and change the player to a table. Some other edits here and there as well.
  20. I don't believe there is a function that specifically gives you the number of months in a year. So we usually use a table to act as a database of sorts. However, we have to remember that there are leap years and that February has 29 days instead of the usual 28 on these years. local months = { [1] = 31, [2] = 28, [3] = 31, [4] = 30, [5] = 31, [6] = 30, [7] = 31, [8] = 31, [9] = 30, [10] = 31, [11] = 30, [12] = 31, } This StackOverflow answer gives us some pseudo-code to calculate a leap year. Let's convert that to Lua. function isLeapYear(year) if ((year % 4 == 0) and (year % 100 ~= 0)) or (year % 400 == 0) then return true end return false end function getMonthMaxDays(month, year) if (months[month]) then if (month ~= 2 and not isLeapYear(year)) then return months[month] else return 29 end end return false end getMonthMaxDays(2, 2016) --> 29 getMonthMaxDays(2, 2011) --> 28 getMonthMaxDays(2, 2000) --> 29 getMonthMaxDays(11, 1945) --> 30 I also recommend using getRealTime.year to get the years since 1900. Just add 1900 onto that result to get the current year. That way the code will work years into the future! Note: This is all untested. Edit: Changed a few words and a couple of typos.
  21. function spawnMyVeh(button, state, absoluteX, absoluteY) if (source == gridListVariable) then addEventHandler("onClientGUIDoubleClick", guiRoot, spawnMyVeh) Change 'gridListVariable' to the grid list's variable.
  22. Noki

    dbConnect bug

    KariiiM, I feel you could expand on your answer and explain why. So basically, whenever you want to get a result in SQL, we use the dbQuery function. That is commonly used with the SELECT clause. If you don't need to get a result (like when you update a table, change a setting, creating a new table etc), you can just use dbExec. dbQuery returns a handler and dbExec just returns a boolean value. It's faster to use dbExec (by a very little amount), but remember you won't get a result from it.
  23. Sold. Hello, In January of this year I acquired USG (United Social Gamers), a multi gamemode server. After a failed revival attempt, we all agreed to call it quits on USG once and for all. I am selling this so USG may no longer just idle on my hard drive and maybe actually go to use somewhere. Plus, I kind of need the money. USG was originally intended to be a new version of CSG, but turned into a whole new server after some ownership difficulties. Launched by Soap and FabioGNR in early 2014, the server was regarded as a success among players. Now to the code. FabioGNR wrote the whole code base by himself from scratch over the period of a year. Some code is written in full OOP (with metatables and all) so it's quite nice. The code base is also quite clean compared to other servers. In its last few iterations, there were significant updates made to the code base. New features were added (like job ranks, an augmented thing to replace the traditional phone, single player activities etc) and many bugs were fixed in these time periods. Some features: - Custom scoreboard - Multiple game modes (CnR, shooter, DD, DM, tactics) - Interactive augmented panel (as opposed to a traditional phone) - Enter-able vehicles (as opposed to spawners) - Customizable GUI Elaborating on the custom GUI, you can change the colour of the GUI depending on how you feel. This change is persistent and server wide. You can also choose from different preset customizable themes. Some media: http://i.imgur.com/hCD5Fha.png (Note: the trucker job has been improved since this video) What you get when you buy: - The whole database (forum, in-game and wiki) - All the USG resources - The right to do whatever you want with them - Complete code history (Git & SVN repositories - if you don't know what this is, it basically means you can see every single change that has ever happened in code). - My complete support with anything you may need (setting up, fixing some bugs) - The "usgmta.co" domain if you like (it expires in July though) I don't have a definitive price for all of this. But if you're going to offer anything less than 20 USD, please do not bother. You can contact me here, on Skype (i.love.kuda.noki) or via email ([email protected]).
  24. getPedSimplestTask List of player tasks
×
×
  • Create New...