-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
Shouldn't be notice able. (unless really really really :~ty internet)
-
If you do this every second, yes. (little network lagg, which will be visible by players with slow internet) But every 2 minutes will be fine.
-
Scoreboard isn't related to nametags. First-person isn't to both of them. Hud might be related to scoreboard and yet it isn't. So if you want to merge this in to a single resource. Then merge it in to the main gamemode. Because they aren't all huds (even though they might contain them). And for the files: /scripts/... /fonts/...
-
Multiple resources and multiple files. Every resource for every gamemode component. (hud, external interfaces) And each file for sub tasks. Sometimes it can be difficult to determine if you should split it up or not. Which can sometimes mean that it can actually be both. When split it up? > If the tasks which the code full fill, are entirely different from each other. As @CodyJ(L) did mention: performance There are two types of performance showing up when doing this: Computer performance. Your own performance. (writing/reading code speed) You will slowly learn how to keep those balanced, based on experience and inspiration.
-
There isn't really a good file structure. The real question is: "Does it work for you? If yes, then it might be a good file structure for you."
-
Yes, could be bad depending on your code style. Because files are also code blocks. Which limit the accessibility of local variables. Example, where it can go wrong: File 1 local variableName = "can't be changed outside of this file" function show () iprint(variableName) end File 2 variableName = "yes" show () -- call the function show It should output: "can't be changed outside of this file" Because the local variable can't be changed outside of it's scope. Now put it in 1 file. local variableName = "can't be changed outside of this file" function show () iprint(variableName) end variableName = "yes" show () -- call the function show It should output: "yes" We have 1 file, 1 file scope. The `variableName` is available at the place where it is overwritten. (so the local variable will be overwritten)
-
This is how you can fetch data(DOWNLOADING, not streaming) from a website. (need acl rights) https://wiki.multitheftauto.com/wiki/FetchRemote You can pass some data with the url. Or use the option argument to send it with: Optional Arguments options: A table containing any request options: queueName: Name of the queue to use. Any name can be used. If not set, the queue name is "default". Requests in the same queue are processed in order, one at a time. connectionAttempts: Number of times to retry if the remote host does not respond. (Defaults to 10) connectTimeout: Number of milliseconds each connection attempt will take before timing out. (Defaults to 10000) postData: A string specifying any data you want to send to the remote HTTP server. postIsBinary : A boolean specifying if the data is text, or binary. (Defaults to false) method: A string specifying the request method. (Defaults to GET or POST) headers: A table containing HTTP request headers. e.g.{ Pragma="no-cache" } maxRedirects: An integer limiting the number of HTTP redirections to automatically follow. (Defaults to username: A string specifying the username for protected pages. password: A string specifying the password for protected pages. FROM VERSION 1.5.4-9.11413 ONWARDS formFields: A table containing form items to submit. e.g.{ name="bob", email="[email protected]" } arguments: A table containing arguments you may want to pass to the callback.
- 1 reply
-
- 1
-
-
triggerClientEvent ( source, "sess", root ) Syntax: bool triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] ) https://wiki.multitheftauto.com/wiki/TriggerClientEvent Required Arguments sourceElement: The element that is the source of the event. name: The name of the event to trigger client side. You should register this event with addEvent and add at least one event handler using addEventHandler Optional Arguments NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments. sendTo: The event will be sent to all players that are children of the specified element. By default this is the root element, and hence the event is sent to all players. If you specify a single player it will just be sent to that player. This argument can also be a table of player elements. arguments...: A list of arguments to trigger with the event. You can pass any lua data type (except functions). You can also pass elements. You might want to reply here as well...
-
function player_Wasted ( ammo, attacker, weapon, bodypart ) if isElementWithinColShape(source, lvcol) then outputChatBox("öldün") end end addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) https://wiki.multitheftauto.com/wiki/IsElementWithinColShape
-
Tables are indeed a good way to deal with this. Included optimise this code. (speed/performance) But first things first.
-
If tables are too much for you, then you can also consider the function block as part of functional programming. The only thing about it, is that memory leaks can occur more often. Which happens for example if you do not remove an addEventHandler from a local function. This code will create the functions `markersize` and `colhit` for every new projectile. And when ALL eventHandlers are removed, so will be the functions. (Warning: if one of the handlers remains to exist, so will remain the whole block.) addEventHandler("onClientProjectileCreation", root, function(creator) if getProjectileType(source) == 17 then setTimer(markerfunc, 2000, 1, source) end end) function markerfunc(elem) local ms = 0 local mst = 0.5 local x,y,z = getElementPosition(elem) setElementPosition(elem, 0, 0, 0) local m = createMarker(x, y, z, "cylinder", 1, 0, 255, 0, 255) local col = createColSphere(x, y, z, mst * 12) local function markersize() ms = ms + mst setMarkerSize(m, ms) local mx,my,mz = getElementPosition(m) setElementPosition(m, mx, my, mz-mst / 1.3) end local function colhit(thePlayer, matchingDimension) if getElementType ( thePlayer ) == "player" then outputChatBox(tostring(getPlayerName(thePlayer))) end end addEventHandler("onClientRender", root, markersize) addEventHandler("onClientColShapeHit", col, colhit) setTimer(function() removeEventHandler("onClientColShapeHit", col, colhit) removeEventHandler("onClientRender", root, markersize) destroyElement(m) destroyElement(col) end, 500, 1) end
-
Afaik mysql does have such things as events: https://dev.mysql.com/doc/refman/5.7/en/events-privileges.html (never used it thought) I am not sure what the possibilities with this are, but it can do a part of the administration for you.
-
local rotationDirection = "right" -- function scope ... if rotationDirection == "right" then rotationDirection = "left" setPedCameraRotation(localPlayer, -(getPedCameraRotation(localPlayer) + 0.08)) else rotationDirection = "right" setPedCameraRotation(localPlayer, -(getPedCameraRotation(localPlayer) - 0.08)) end -- end
-
Face toward at dxDrawMaterialLine3D depending on rotations
IIYAMA replied to Dzsozi (h03)'s topic in Scripting
getElementMatrix(getCamera()) function getElementMatrix(element) local rx, ry, rz = getElementRotation(element, "ZXY") rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz) local matrix = {} matrix[1] = {} matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry) matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry) matrix[1][3] = -math.cos(rx)*math.sin(ry) matrix[1][4] = 1 matrix[2] = {} matrix[2][1] = -math.cos(rx)*math.sin(rz) matrix[2][2] = math.cos(rz)*math.cos(rx) matrix[2][3] = math.sin(rx) matrix[2][4] = 1 matrix[3] = {} matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx) matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx) matrix[3][3] = math.cos(rx)*math.cos(ry) matrix[3][4] = 1 matrix[4] = {} matrix[4][1], matrix[4][2], matrix[4][3] = getElementPosition(element) --image position. matrix[4][4] = 1 return matrix end https://wiki.multitheftauto.com/wiki/GetElementMatrix 》getPositionFromElementOffset《 And full control depending on the camera. -
Please use tabs in your code, I am not going to read this otherwise.
-
I already gave you the methode to built that. You only have to edit it in terms of your needs...
-
That happens when you do not fill in valid para. (which has to be a string which only contains numbers.) para = tonumber(para) -- `para` is already a local as it is a parameter. function (parameters...) if para and para > 10001 and para < 99 then -- works good! end And your bug is here: function spin(source, cmd, para) function spin(cmd, para) As it is clientside, only the localPlayer(YOU/You/you/and just you) can activate an addCommandHandler. Which means they decided to not pass the player on to the first parameter. Check wiki: https://wiki.multitheftauto.com/wiki/AddCommandHandler Serverside syntax: player playerSource, string commandName, [string arg1, string arg2, ...] Clientside syntax string commandName, [string arg1, string arg2, ...] Please do not use `source` in addCommandHandlers, it is for eventHandlers! You will only confuse yourself!
-
For the spin delay, use tickCount. local nextSpinTime = 0 local spinDelay = 10000 -- 10 sec -- function () local timeNow = getTickCount() if timeNow > nextSpinTime then nextSpinTime = timeNow + spinDelay -- -- You can only execute this code every 10 sec. -- else -- Not so fast... end --end
-
Then you do not need this: local para = math.min = (100) and math.max (10000) Only this: para = tonumber(para)
-
local para = math.random(100, 10000)
-
An object isn't a streamed able element. There is no way for server-side to know where this colshape is located in the world. (Especially when the client moves the object) It might be possible based on last set position but even so it is very inaccurate.
-
local getDistanceBetweenPointAndSegment3D = function (pointX, pointY, pointZ, x1, y1, z1, x2, y2, z2) local A = pointX - x1 local B = pointY - y1 local C = pointZ - z1 -- local D = x2 - x1 local E = y2 - y1 local F = z2 - z1 -- local point = A * D + B * E + C * F local lenSquare = D * D + E * E + F * F local parameter = point / lenSquare local shortestX local shortestY local shortestZ if parameter < 0 then shortestX = x1 shortestY = y1 shortestZ = z1 elseif parameter > 1 then shortestX = x2 shortestY = y2 shortestZ = z2 else shortestX = x1 + parameter * D shortestY = y1 + parameter * E shortestZ = z1 + parameter * F end local distance = getDistanceBetweenPoints3D(pointX, pointY,pointZ, shortestX, shortestY,shortestZ) -- return distance end 3D version of this one: https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPointAndSegment2D Useful for detecting if something is between 2 points.
- 1 reply
-
- 2
-
-
local peds = getElementsByType("ped", root, true) for i=1, #peds do local ped = peds[i] end getDistanceBetweenPoints3D() local x, y, z = getElementPosition(ped) local x2, y2, z2 = getElementPosition(localPlayer) killPed(ped) etc. https://wiki.multitheftauto.com/wiki/Scripting_Introduction
-
On the brick of annihilation: bool setElementData ( element theElement, string key, var value [, bool synchronize = true ] ) Put it to FALSE setElementData ( theElement, key, value, false )
