-
Posts
65 -
Joined
-
Last visited
Everything posted by vicisdev
-
I have a shared script that stores a parameter provided function into a table: -- shared_script.Lua local my_table = {} function addFunctionality(key, handler) my_table[key] = handler end The point is that it's stored two different tables - client and server side. When addFunctionality is called from a client script the handler is stored only inside the respective side table. What I need is a way to communicate between both client and server to store the handler in both tables independently of who is calling addFunctionality. The tables need to be synced and have the same data. I know there are functions server/client only, but forget that for now. For the purpose of this help bear in mind I'm trying to store this function: function() return true end But from the point of view of addFunctionality you never know how handler's implementation looks like. I've already tried to: - Use events, but they do not accept functions as arguments - Store the table in the root element, but it's not possible at all - Use loadstring, but 1) I don't know how handler's implementation looks like and 2) it doesn't return values Thanks
-
Solved! The point is that os.time() returns an integer in seconds, so even if I multiply it by a thousand we miss a lot of information on cents, decimals, units in a range from 0 to 999. Just replace os.time() by getTickCount() and you're good to go, since this returns an integer in milliseconds.
-
I don't know if it's enough, but basically this is what's called every frame -- self.behavior is a table that describes the animation properties local elapsedTime = os.time() * 1000 - initialTime local time = elapsedTime / self.behavior.duration local progress = bezierInterpolation(time, self.behavior["cubic-bezier"]).x local element = self.element local x, y, z = unpack(initialPosition) local toX, toY, toZ = unpack(self.behavior.to) local newX, newY, newZ = x + ((toX - x) * progress), y + ((toY - y) * progress), z + ((toZ - z) * progress) setElementPosition(element, newX, newY, newZ) if time == 1 then removeEventHandler("onClientPreRender", root, renderHandler) end This function is called every frame, but because the values is too close from each other the API tries to save processing and updates only per second, I guess. 24 FPS 100 FPS
-
Is there a way to prevent this from happening? I'm making a movement script with cubic-bezier support, but when I render the movement onClientPreRender the server kinda limit the executions. DEMONSTRATION
-
Yes, of course. I forgot to mention that. It's needed to have the files in the resource's folder so you can tell to the meta.xml where it is. Okay. We are conflicting ideas here lol. The last approach I sent it's not complementary of IIYAMA's approach - you can't put them together.
-
I changed the fetchRemote at line 66 fetchRemote(url, {}, fileRequest, {i, fileType}) And the fileRequest parameters to match the fetchRemote local fileRequest = function (data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end ... Have you tried downloadFile()? It seems to do exactly what you need. I made an alternative code using this function. It's not good, it's a concept... but let me explain how it works. To use downloadFile() it's needed to store your file paths in the meta.xml with download attribute set to false. In order to let you create only one file, I made a trick using the meta.xml as a config file as well. I don't know the implications of it - IIYAMA can tell us - but this way you're going to be able to loop through the meta.xml and get the <file> tags. The meta.xml will look like this: <file src="sultan.txd" download="false" modelid="560"/> <file src="sultan.dff" download="false" modelid="560"/> <!-- In this case the files are in the resource root folder --> I added a extra attribute to store the modelid, so you can know for what model the file is related. It's needed to put the <file> tags in the proper load oder (col, txd, dff). So the code wil loop this meta file and store the informations to the fileModelList table then it will iterate this table and download all entries. The table will look like this: local fileModelList = { ["sultan.txd"] = { model = "560", fileType = "txd" }, ["sultan.dff"] = { model = "560", fileType = "dff" } } Client: local fileModelList = {} local downloadFiles = function() local metaNode = getResourceConfig("meta.xml") for _, v in pairs(xmlNodeGetChildren(metaNode)) do if xmlNodeGetName(v) == "file" then local fileName = xmlNodeGetAttribute(v, "src") local modelId = xmlNodeGetAttribute(v, "modelid") local fileType = gettok(fileName, 2, "\.") setTimer(downloadFile, 500, 1, fileName) -- In the localhost the download is so fast that one event isn't triggered -- downloadFile(fileName) fileModelList[fileName] = { model = modelId, fileType = fileType } end end end addEventHandler("onClientFileDownloadComplete", resourceRoot, function(fileName, success) if not success then return end -- Later you should do something to handle failed downloads local model = fileModelList[fileName].model local type = fileModelList[fileName].fileType if type == "txd" then engineImportTXD(engineLoadTXD(fileName), model) end if type == "dff" then engineReplaceModel(engineLoadDFF(fileName), model) end fileModelList[fileName] = nil end) addEvent("downloadFiles", true) addEventHandler("downloadFiles", resourceRoot, downloadFiles) Server: addEventHandler("onPlayerJoin", root, function() -- triggerLatentClientEvent(source, "downloadFiles", 10^7, true, resourceRoot) -- Even 10 MBytes didn't work triggerClientEvent(source, "downloadFiles", resourceRoot) end) You will need to mess with the triggerLatentClientEvent() downloadFile() is good if you need to postpone the file downloads, but if you're going to download everything onPlayerJoin wouldn't it be better to let the server handle it? He's downloading 5 MB files (or even more). For his case, what's the correct value to put in the bandwidth parameter? I set it to 10^7 and didn't works lol
-
Wouldn't it be better if you attach the script directly to the brick part? I've never touched a Roblox script before, but I think it's not a good idea to create a listener to a part everytime a player joins. Also, you don't need to create two while loops (maybe none of those) because you're making simple condition so you should use an if-else statement, like so: while true do if hit.Parent:FindFirstChild("Humanoid") and player.GameStats.Body.Value <= 200 then a = true hit.Parent.Humanoid:TakeDamage(50) player.GameStats.Body.Value = player.GameStats.Body.Value + 2 else a = true hit.Parent.Humanoid:TakeDamage(1) player.GameStats.Body.Value = player.GameStats.Body.Value + 2 end wait(1.5) a = false end It's always good to avoid repeating yourself along your code, so even better: while true do damageTaken = 0 if hit.Parent:FindFirstChild("Humanoid") and player.GameStats.Body.Value <= 200 then damageTaken = 50 else -- if body >= 201 damageTaken = 1 end if a == false then a == true hit.Parent.Humanoid:TakeDamage(damageTaken) player.GameStats.Body.Value = player.GameStats.Body.Value + 2 end wait(1.5) a == false end There is this guy AlvinBlox who make a lot videos of Roblox scripting, it's really good! You should check this video to lean more about events and general Roblox coding, it's amazing. The code you need may be something like this: local canTrigger = true game.Workspace.Part.Touched:Connect(function(hit) if not canTrigger then return end canTrigger = false local damageTaken = 0 if hit.Parent:FindFirstChild("Humanoid") and player.GameStats.Body.Value <= 200 then damageTaken = 50 else damageTaken = 1 end hit.Parent.Humanoid:TakeDamage(damageTaken) player.GameStats.Body.Value = player.GameStats.Body.Value + 2 wait(1.5) canTrigger = true end)
-
The IIYAMA's logic works perfectly, but I needed to make some tweaks. For some reason in his code the argument data is always 0. When I changed the fetchRemote implementation to the one mentioned above, it works ok. Another one is that, I don't know why, but triggerLatentClientEvent isn't called when passing modelDataList as an argument. Switched it to triggerClientEvent and it works.
-
Oh, okay. It seems you're getting the HTML page instead of the file. You need a direct download link like this one from your sultan.txd
-
Uuuuh wee! It works like a charm! Thank you!
-
I see some possible problems there. - The version of fetchRemote - Callback args - File binary If you'll look at the wiki fetchRemote has tones of versions and maybe none of those are one of you are using. I used recently fetchRemote with the following sintax: fetchRemote(string url, table requestOptions, function callback, table callbackArgs) Maybe you can try it as well with some headers definitions. The first argument of the callback function seems to be always the data and not the request information. Particulary with the fetchRemote above, the arguments are responseData, responseInfo and callbackArgs. If you're not sure that it's downloading successfully, then you could try to create a file, write the response data in it and load the dff. Also, get the response code from the responseInfo to check if everything done ok. When you download a file you receive its binary through the response data and maybe the file binary it's not exactly the dff information that's needed to load a model into the game. Let's say I have a txt file with "I'm a txt file" wrote in it. If I try to request this file I'll receive its binary not the "I'm a txt file". Good luck
-
Acho que essas funções podem te ajudar com o que você precisa toggleControl() -- Essa aqui especificamente unbindKey()
-
By doing this am I avoiding this deeeeep copy? local myTable = {} -- Some filled in table setTimer(function() callAnotherFunction(myTable) end, 1000, 1)
-
ENGLISH Let's say I have a player and I want to spawn a car in front of it with a specific distance away from the player. It must considers the player's rotation. It involves some math calculations, but I can't formulate it. BRASIL Vamos supor que eu tenha um player e eu queira spawnar um carro na frente dele com uma distância específica. Para fazer isso, deve levar em consideração a rotação atual do player. Eu sei que isso envolve cálculos matemáticos, mas não consegui formulá-los. Thanks all