-
Posts
1,060 -
Joined
-
Last visited
-
Days Won
9
Everything posted by Addlibs
-
You need to call setDevelopmentMode(true) on a client-side script, and then use the /showcol command. Judging by the fact you use onColShapeHit rather than onClientColShapeHit, I'm guessing that this script is server-side. So you can't use setDevelopmentMode in this file.
-
Break a string into separate lines depending on length
Addlibs replied to Dzsozi (h03)'s topic in Scripting
local function wordWrap(text, maxwidth, scale, font, colorcoded) local lines = {} local words = split(text, " ") -- this unfortunately will collapse 2+ spaces in a row into a single space local line = 1 -- begin with 1st line local word = 1 -- begin on 1st word local endlinecolor while (words[word]) do -- while there are still words to read repeat if colorcoded and (not lines[line]) and endlinecolor and (not string.find(words[word], "^#%x%x%x%x%x%x")) then -- if on a new line, and endline color is set and the upcoming word isn't beginning with a colorcode lines[line] = endlinecolor -- define this line as beginning with the color code end lines[line] = lines[line] or "" -- define the line if it doesnt exist if colorcoded then local rw = string.reverse(words[word]) -- reverse the string local x, y = string.find(rw, "%x%x%x%x%x%x#") -- and search for the first (last) occurance of a color code if x and y then endlinecolor = string.reverse(string.sub(rw, x, y)) -- stores it for the beginning of the next line end end lines[line] = lines[line]..words[word] -- append a new word to the this line lines[line] = lines[line] .. " " -- append space to the line word = word + 1 -- moves onto the next word (in preparation for checking whether to start a new line (that is, if next word won't fit) until ((not words[word]) or dxGetTextWidth(lines[line].." "..words[word], scale, font, colorcoded) > maxwidth) -- jumps back to 'repeat' as soon as the code is out of words, or with a new word, it would overflow the maxwidth lines[line] = string.sub(lines[line], 1, -2) -- removes the final space from this line if colorcoded then lines[line] = string.gsub(lines[line], "#%x%x%x%x%x%x$", "") -- removes trailing colorcodes end line = line + 1 -- moves onto the next line end -- jumps back to 'while' the a next word exists return lines end This variant will append the latestly used colorcode on every subsequent line to preserve color. However, due to a number of more intensive functions used here, like string.find, string.reverse and string.gsub, this code runs 25% slower with colorcode enabled than the previous version, and only 5-6% slower without colorcode than the previous version. Same-version comparison yields that colorcoded being enabled slows it down by 22% compared to without. Still pretty fast though, took around 0.000167465 seconds (0.167465 ms) (mean over 200 iterations) for the paragraph above to be processed by the function using own pure-lua implementations of split* and a simplified implementation of dxGetTextWidth (simply returning the length of characters excluding colorcodes), since I was using standalone Lua rather than via MTA client. * Turns out, while checking the speed of MTA's split, my pure-lua implementation is a lot faster, like 10× faster. MTA's split (on the server side) managed to take up to 2 seconds to process the “However,…” paragraph. -
Break a string into separate lines depending on length
Addlibs replied to Dzsozi (h03)'s topic in Scripting
local function wordWrap(text, maxwidth, scale, font, colorcoded) local lines = {} local words = split(text, " ") -- this unfortunately will collapse 2+ spaces in a row into a single space local line = 1 -- begin with 1st line local word = 1 -- begin on 1st word while (words[word]) do -- while there are still words to read repeat lines[line] = lines[line] and (lines[line].." ") or "" -- appends space if line already exists, or defines it to an empty string lines[line] = lines[line]..words[word] -- append a new word to the this line word = word + 1 -- moves onto the next word (in preparation for checking whether to start a new line (that is, if next word won't fit) until ((not words[word]) or dxGetTextWidth(lines[line].." "..words[word], scale, font, colorcoded) >= maxwidth) -- jumps back to 'repeat' as soon as the code is out of words, or with a new word, it would overflow the maxwidth line = line + 1 -- moves onto the next line end -- jumps back to 'while' the a next word exists return lines end This code should work. It'll return a table of lines that you need to draw separately. The colorcoded parameter, when set to true, means dxGetTextWidth will remove #rrggbb from the text before calculating width since that's how it'll render it. I have not measured the performance of this script, but for short sentences like less than 50 words it shouldn't cause any significant lags. It iterates based on word count rather than character count. -
You can't really add new IDs for walking styles, but you can use the new custom animations function engineReplaceAnimation and override* animations of a specific walking style for a particular ped (you'll have to call this function on each client so everyone sees the same thing). If you're looking for which anims are used on which walking style, you should check out Animation Groups (e.g., walking style 132 uses animation group sexywoman of the ped block) * You can only override default animations with custom loaded animations.
-
You could try using a set of pairs, but these would not be indexed by key. local _set = { {"OB1", 8}, {"OB2", 1}, {"OB3", 10}, {"OB4", 6} } table.sort(_set, function(a, b) return a[2] > b[2] -- if pair a's 2nd value is greater than pair b's 2nd value, sort a above b end ) -- After sorting: -- set[1] = {"OB3", 10} -- set[2] = {"OB1", 8} -- set[3] = {"OB4", 6} -- set[4] = {"OB2", 1}
-
It's easier if you use the key in that table, since your contains function had to iterate the whole table (in cases where the ID wasn't in it), or iterate a part of the table until it found the ID (could be a lot of iterations for a larger table). I'm not sure if Lua's indexing does actually iterate any storage container under the hood, and even if it does, that would be done via C which is a lot faster. local IDsToCheck = {[2]=true, [3]=true} -- If you then index the table, you'll find that: -- ... -- IDsToCheck[0] = nil -- IDsToCheck[1] = nil -- IDsToCheck[2] = true -- IDsToCheck[3] = true -- IDsToCheck[4] = nil -- IDsToCheck[5] = nil -- ... -- In other words, everthing is nil except the IDs which you defined as true. addEventHandler("onVehicleEnter", resourceRoot, function(player) local vehID = vehicles[source].vehicleID if IDsToCheck[vehID] then -- evaluates nil if vehID isn't in IDsToCheck table, jump to else block; evaluates true if vehID is set to true, and executes the next block outputChatBox("ID matches", player, 255, 204, 0) else outputChatBox("Does not match", player, 255, 0, 0) end end )
-
-- The structure is as follows local vehicleIDs = { --[id] = vehElem, } local vehicles = { --[vehElem] = { -- vehicleID=id, -- respawnInterior=int, -- respawnDimension=dim, -- characterID=character, -- engineState=engine, -- tintedWindows=windows, -- fuel=fuelAmount --} } So if you want the vehicle with ID x, you use vehicleIDs[x] And if you want to get the ID of a vehicle v, use vehicles[v].vehicleID
-
There's OnClientConsole/OnConsole that gives the full command string along with parameters for any command, except /login where the parameters are censored into triple asterisks. I don't believe it gets triggered if you cancelEvent on onPlayerCommand for the same command though.
-
Have you read attachElementsOffsets (it's linked in the attachElements wiki page)? Maybe something in there will help.
-
The error message is self-evident: `safeusername` local variable is a nil value (null or undefined), and you tried to append or concatenate it in a string on like 857 in s_account_system.lua of resource `account-system`. Most likely you just didn't define a value for it.
-
In the last 17 hours, you've made 5 topics and 3 of them provided you with fixed code, so don't pretend like it's "just this time." Please, for the sake of us all, get help from us to learn to script instead of leeching off the work of others. We're here to help, not work for you. Please try it yourself just this time
-
Element hierarchy and parenting has nothing to do with sync, its mostly about propagation. The second parameter is simply a question of where in the element tree the map will be loaded. On the second point, everything created on the client side is only created on client, it is not synced to the server. This includes objects, vehicles, markers, peds, blips, everything.
-
local x,y,z = getElementPosition(source) And make sure when you trigger that event on the server, that the source of the event is the player who played the song. I.e. triggerClientEvent(root, "syncSong", thePlayerWhoPlayedTheSong) -- ^ who will hear the song ^ event source
-
"error attempt to index upvalue "users" (a nil value)" This means that the local variable users is a nil value, and you tried to index it (users[name]). Is what you posted here the whole code? Perhaps somewhere in the full code users is changed to a nil? The snippet alone seems to be correct so I don't know why users would be a nil value.
-
You don't need the skill to be 1000. It's enough to change walking style to 56 and you basically have exactly the same animations you'd get with 1000 muscle stat CJ. Sprinting still doesn't work, just it doesn't work with CJ on 1000 stat.
-
First of all, you should have clarified from the beginning that you're talking about sprinting. I was under the impression "run" means "run", not "sprint". Now, I have never heard of being able to sprint with an M4 in SA with the muscular animations (or any other armed animations for that matter). I have just tried it and you can't sprint as CJ with or without 1000 muscle stat or whatever. It's not possible, unless you change the walking style into something other than armed animation sets). Indeed, there is literally no animation for sprinting with a two-handed weapon within the muscular animation set. You can use a different walking style and override (with engineReplaceAnimation) whatever you need. If you need original animations of muscular style, you need to extract them and put them into your custom ifp to use for engineReplaceAnimation (unfortunately it seems engineReplaceAnimation doesn't allow for redirecting default anims to other default anims. Perhaps that might be a good suggestion/issue to open).
-
MTA's default "info" chatbox outputs (including this connect message) use RGB 255, 100, 100 (#FF6464) https://github.com/multitheftauto/mtasa-blue/blob/40118f7875516304ff585c4c9ef360a7e887ca41/Client/mods/deathmatch/logic/CClientCommon.h#L52
-
If it's not on the community site then it's most likely propriety - that MTA PUBG server owns that script and if you want it from them, you should contact them directly. If you're looking for someone to script a copy of it for you, you're in the wrong place - we're here to help, not to fulfil requests.
-
engineApplyShaderToWorldTexture Tip: • When using with a 'ped', ensure you have set 'ped' or 'all' in the elementTypes when calling dxCreateShader By default, dxCreateShader does not create a shader that works on peds. You need to manually set that.
-
TeaEncode returns a base64 representation of the encoded payload that's about 33% inflated in size from the original text. When dealing with DFFs or other binary, TeaEncode needs a base64 encoded input, a ~33% larger input. The output size with base64'd input is ~76.89% larger. encodeString doesn't base64 the output nor does it need the input to be base64'd, and seems to return a barely inflated output; Specifically, 100.00168517551% of the original size in my quick test using a vehicle model DFF for input.
-
Because non-latent events are guaranteed to arrive in order, a side effect is that a large payload (such as a file) in such event will hang the event manager, since subsequent events need to wait and yield to this big event, so that they arrive after that big one, ensuring order. Using latent events, however, allows you to forego this guarantee, and also limit transfer rates among other things. Latent events are suited for sending over large data that isn't sync-like, such as file contents. As to fileDownload, it downloads the file as-is on the server, and at every reconnect or restart, it compares the server's hash; if the file is different on the client (outdated, for example), it will re-download; so if you encrypt the file after downloading, it's no longer identical to the server file and thus will be re-downloaded on restart. You should, as suggested above, encrypt it on the server and send to the client via a latent event, later caching the contents into some file on the client's computer. You will also need manual hash checks to make sure the client didn't replace, edit or break the file, on onClientResourceStart. Further, the loading errors are almost definitely because you did not Base64 the TEA input (required for binary data in teaEncode); preferably move towards encodeString and decodeString as these do not require Base64ing (thus lower CPU and bandwidth use). Finally, I'd ultimately recommend just pre-encryping rather than encrypting on-the-go whenever a client demands either a hash check or the encrypted contents from the server, as that causes the server becomes busy encrypting what could have just as easily been encrypted earlier.
-
How about you attempt it on your own and come back if you encounter any problems? We're not here to script for you.
-
MTA raises that error when the DFF's headers don't add up, indicating some data integrity error (possible file corruption). Perhaps these mods do work, but they share similarities (corrupted header) with mods that crash the client, so that's why they get blocked.
-
I would refer you to Specifically, use code markings to make the code readable and tell us what the problem is, don't just paste your code. Tell us what is your issue, any errors you get, and what the intended behaviour is.
-
Could you tell us precisely what error/problem this is rather than what it's related to? And are you absolutely 100% sure the image is in meta.xml? Did you make sure to save it properly (it often that people don't realise their meta.xml wasn't saved, or that they didn't update the changes on the remote server). Check whether the file got downloaded by your client, that would be in MTA client directory/mods/deathmatch/resources/<your resource name> - make sure to look for it on your client, not on the server. If it's not there, then almost surely your meta.xml is wrong.