-
Posts
1,060 -
Joined
-
Last visited
-
Days Won
9
Everything posted by Addlibs
-
It might be easy, but it takes up CPU during encoding and decoding, and takes up more space in memory (buffer), on disk (when saved) and in transit (downloading). decodeString("tea", data_to_decode, {key = "your key"}) is just as easy, and also more efficient.
-
Well, first of all, countPlayersInTeam takes a team element, not team name. Use getTeamFromName to get a team element from name. local dende = "dende" local acari = "acari" local cidadealta = "cidadealta" -- [...] local comandovermelho = countPlayersInTeam(getTeamFromName(dende)) -- fixed this for ya local comandovermelho2 = countPlayersInTeam(getTeamFromName(acari)) -- fixed this for ya local comandovermelho3 = countPlayersInTeam(getTeamFromName(cidadealta)) -- fixed this for ya Another thing you did is -- this snippet does not include the fix from above local comandovermelho = countPlayersInTeam(dende) -- [...] if(countPlayersInTeam(comandovermelho) > 0)then comandovermelho is not a team element, but the return from countPlayersInTeam, in this case, a false (boolean) as you've tried to count players in a team name rather than the actual team (the team element). Use the fixed comandovermelho from the snippet above, and the if-statement line should read if (comandovermelho > 0) then
-
It's actually better to use encodeString and decodeString (added as of 1.5.5 r11849) as these functions allow you to avoid converting Base64 which is less efficient in terms of data storage - length of data n turns into a length of 4*(n/3) in Base64 (33% data increase), plus padding (=) this can add up to even 36.55% increased data use (16000 bytes is 21848 bytes of base64) encodeString("tea", DATA_TO_ENCODE, {key="your key"}) decodeString("tea", DATA_TO_DECODE, {key="your key"}) -- The following code can be used to test local f = File.open("some_model.dff", true) local data = f:read(f.size) -- read all data f:close() local key = "xTN5#Gqm=sKn**dF" local opt1 = teaEncode(base64Encode(data), key) local opt2 = teaEncode(data, key) local opt3 = encodeString("tea", base64Encode(data), {key = key}) local opt4 = encodeString("tea", data, {key = key}) outputChatBox("teaEncode with base64: " .. (base64Decode(teaDecode(opt1, key)) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt1) outputChatBox("teaEncode without base64: " .. (teaDecode(opt2, key) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt2) outputChatBox("encodeString with base64: " .. (base64Decode(decodeString("tea", opt3, {key = key})) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt3) outputChatBox("encodeString without base64: " .. (decodeString("tea", opt4, {key = key}) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt4)
-
You need to store 'message' somewhere if you want to use it in renderNotification. In the following code, I've placed it into notification[1] as well as r, g, b and colorCoded in the subsequent indices. local sw, sh = guiGetScreenSize() local sx, sy = sw/1920, sh/1080 local notificationBaseX, notificationBaseY = (sw/677)/2, 40 local notificationWidth, notificationHeight = 677, 40 local notificationMargin = 7 local notification -- current notification data storage function sendClientMessage(message, r, g, b, colorCoded) if type(message) == "string" then if not colorCoded then r, g, b = tonumber (r) , tonumber(g) , tonumber(b) colorCoded = false else r, g, b = getColorFromString(message) colorCoded = true end notification = {message, r, g, b, colorCoded} -- set current notification data setTimer(function() notification = nil -- reset current notification data after 15000ms -- but don't remove event handler as that will prevent further notifcations showing up -- unless you re-attach the handler every time a new notifcation comes end, 15000, 1) end end addEvent("sendClientMessage", true) addEventHandler("sendClientMessage", root, sendClientMessage) function renderNotifications() if notification then -- if there is any current notication (data) -- collect notification data local message = notification[1] local r, g, b = notification[2], notification[3], notification[4] local colorCoded = notification[5] local notificationX, notificationY = notificationBaseX +notificationMargin, notificationBaseY+(notificationHeight +notificationMargin)*1 dxDrawRectangle(sx*notificationX, sy*notificationY, sx*notificationWidth, sy*notificationHeight, tocolor(0, 0, 0, 255)) dxDrawText(message, sx*notificationX, sy*notificationY, sx*notificationX+notificationWidth, sy*notificationY+notificationHeight, tocolor(r, g, b, 255), sx*1.2, "default-blod", "left", "top", false, false, false, colorCoded, false) end end addEventHandler("onClientRender", root, renderNotifications) The way you modified the code allows only for one message to render at any time. If this is not what you intended, you should try to more closely mirror what LopSided gave you.
-
You want an example of how to calculate position on a 2D map image? Well, you'll want something like this: local pos pos = ((cursorPos-mapPos)/mapSize) -- calculate cursor pos relative to map image pos = pos - Vector2(0.5,0.5) -- change range from 0–1 to -0.5–0.5 so (0,0) is in the center rather than top left corner pos = pos * 6000 -- scale it by map size in meters -- this is equivalent to local pos = ((((cursorPos-mapPos)/mapSize)-Vector2(0.5,0.5))*6000 cursorPos, mapPos and mapSize should be of type Vector2, absolute values used for testing but should work with relatives too. Resulting pos is also a Vector2. This will probably require changes if you want to use it for a zoomed-in section of the map.
-
What is this supposed to do? if worldx == x2 and worldy == y2 then Seems like your code requires that world position clicked on using the cursor is exactly the same as the X and Y screen positions of the GUI element clicked. Here's a tip: if something doesn't work - try adding other debug outputs to see the flow control in action - so that you can easily tell if and which flow branch failed, as I can see you only gave yourself a debug output only at the point of success but not at points of potential failure. At this point I think it's also worth pointing out that getCursorPosition world absolutes are related to what the cursor actually points at in the viewport, not on a map image - for the latter, you need to do manual calculations to convert screen position to a range between 0 and 1 of the map image, and then scale it up to world scale (6000x6000 meters) to get the world position indicated by the cursor click on a map image.
-
Let's assume tick count is 1000 this frame, and 1016.6666667 on the next frame (60 FPS). That is a 16.6666667 increase in tick count. 1000.0000000 ÷ 20 = 50.0000000 1016.6666667 ÷ 20 = 50.8333333 This is a 0.8333333 increase rather than a 16.6666667 increase, an increase 20 times lower, thus making the rotation per frame slower by 20. Note that the modulo operation doesn't reset the tick count number but only the resulting number of the modulo operation. On the other hand, if you did modulo first and division later, you wouldn't be able to get a degree higher than 360° / 20, that is, 18°, which isn't what was intended in this situation.
-
You could try drawing 5 texts to a render target, only when necessary, to avoid drawing them on every frame; or perhaps draw only 1 text to a render target and use a shader for outline but I have no idea how to write such a shader.
-
Do you mean you want to have alpha blending enabled? That requires slightly more than this simple shader, namely, AlphaBlendEnable, SrcBlend and DestBlend and I believe that might require a pixel shader.
-
If anything, it's the modulo operator that's redundant here, as the rotation argument will take any number, not necessarily one that is truly between 0 and 360. Regarding the division, it should make a difference -- diving the tick count will slow it down, in this case, the ticks will increment 20× slower, meaning a 20× slower rotation speed, from 1000 deg·s-1 to 50 deg·s-1
-
Read up wiki pages for setTimer and aclReload, and that should be enough to get you started.
-
That is simple string concatenation (the double dot operator): outputChatBox( "Money has been sent to "..getPlayerName(targetPlayer).." some money.", sourcePlayer, 255, 0, 0 ) -- send to source player message confirming his transaction with his target's name outputChatBox( getPlayerName(sourcePlayer).." has sent you some money.", targetPlayer, 255, 0, 0 ) -- send to target player a different message including the source's name
-
I'm sorry but your statement makes no sense. Care to, perhaps, use different words when someone asks to rephrase the question?
-
Well, yes you can use addDebugHook, but “it should only be used when debugging scripts as it may degrade script performance.” (wiki)
-
You can getWorldFromScreenPosition with getCursorPosition to get the ground that's been clicked on, and then testLineAgainstWater from camera position to the ground you clicked to determine whether there was water in the way and the precise x, y and z position where water was found
-
Exports currently do not support this. Workarounds include exporting a function which returns a string of lua code which you can loadstring() to have the class defined within the current resource.
-
Show us your code so far and we'll help you out. We won't however, write the code for you.
-
Seems like you deleted local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) which existed between lines 8 and 9, which means CreatTop is nil (not defined). Try adding that line back in.
-
local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 local experience = tonumber ( getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ) ) or 0 -- attempt to convert to a number or return a 0 table.insert (Top, { Account = getAccountData ( getAccount ( CreatTop[i].hesap_adi ), "nickname" ) or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = level + ( experience / 100000 ) -- add them together } ) I've accidentally added one closing bracket too many in my previous post. Anyway, making use of variables makes this a lot clearer.
-
giveMeVehicles shouldn't be called with a string in the first parameter, but a table (or a number which gets converted to a table containing the number on lines 2–4). Seems like you tried using the vehicle name, while the code clearly expects vehID, that is, vehicle model ID, a number between 400 and 611 according to line 29.
-
aTecrube = (tonumber(CreatTop[i].level) or 0) + (tonumber(getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' )) or 0)/100000), Make sure to add 'or' fallbacks when using tonumber: tonumber("invalid number") returns a nil, not a 0. To get a 0 if an invalid number is entered, use (tonumber("invalid number") or 0)
-
theKey == data[i] theKey[i] == data[i][i] I believe you wanted to use theKey[1], theKey[2], theKey[3] rather than theKey[i][1], theKey[i][2], theKey[i][3]
-
If you formatted your indentation correctly, you would quickly realise what the problem is: function info ( message ) removeEventHandler ( "onClientRender", getRootElement( ), dx ) function dx () local screenW, screenH = guiGetScreenSize () local localPlayerName = getPlayerName(getLocalPlayer()) dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false) dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end addEventHandler("onClientRender", getRootElement( ), dx ) end if command == "info" then addEventHandler("onClientRender", getRootElement(), drawText) elseif command == "stopinfo" then removeEventHandler("onClientRender", getRootElement(), drawText) end addCommandHandler("info", info) addCommandHandler("stopinfo", info) You've ended the function 'info' on line 10 and then added if command statements outside the function. What you probably wanted was this function dx () local screenW, screenH = guiGetScreenSize () local localPlayerName = getPlayerName(getLocalPlayer()) dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false) dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end addEventHandler("onClientRender", getRootElement( ), dx ) -- start off with info showing function info ( command ) if command == "info" then addEventHandler("onClientRender", getRootElement(), dx) -- note that this will cause debugscript errors saying that the function is already -- handled if you type /info more than once in sequence without a /stopinfo in between. -- If you want to prevent that, use a variable to determine whether you've already -- added the handler, or use getEventHandlers() elseif command == "stopinfo" then removeEventHandler("onClientRender", getRootElement(), dx) end end addCommandHandler("info", info) addCommandHandler("stopinfo", info)
-
Indeed they might "load" faster, but they need to be downloaded every time you reconnect to the server, meaning, for larger files there is a download delay that could mean it takes longer to load than without it. Reading from a cached file is definitely faster than downloading the file every time.