-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
That is probably related with the mathematics behind the colshape. For example a cube requires some basic mathematics, while a rotated cube requires some advanced mathematics.
-
bindKey getElementMatrix getDistanceBetweenPoints3D findRotation3D --https://wiki.multitheftauto.com/wiki/FindRotation3D getTickCount createProjectile "onClientRender" "onClientPreRender" --(timeSlice benefit) function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end Just one of the concepts you can use: This function allows you to calculate the distance between a line and a point. This can be very powerful, when you combine that with getPositionFromElementOffset, because that function allows you create offset points from the vehicle. These offset points can be used to create a line in front of you, which you can use to compare the distance between all vehicles. Now you will able to exclude most of the vehicles behind you. Be creative, there a lot of options out there to do the same based on other mathematics calculations like rotation. (which you can also include as another layer) local getDistanceBetweenPointAndSegment3D = function (pointX, pointY, pointZ, x1, y1, z1, x2, y2, z2) -- vector1 -- local A = pointX - x1 local B = pointY - y1 local C = pointZ - z1 -- -- vector2 -- 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 Another concept: You can just simple use getDistanceBetweenPoints3D on a point in front of you. If you make the detection size 300 units and you do it 300 units in front of you. You will be able to capture all vehicles in front of you inside of a giant circle. > From that segment you can use getDistanceBetweenPoints3D again to compare the vehicle distance from the hydra and all other vehicles and this time you use a detection size of 150 units.
-
Nope, unless you make the lock system yourself. I can give you a list of functions and events for that, if you so desire. But it is not a project for beginners.
-
Locked This is a scripting request, which may not look like one, but this user has already made 2 scripting requests in this section and doesn't know Lua. And he is exceedingly bumping on all of his topics.
-
Not a bug: https://wiki.multitheftauto.com/wiki/SetPedStat Serverside: addCommandHandler("setMaxHealth", function (player) setPedStat(player, 24, 650) end) Also according to this formula: (not sure if this is valid) stat = 650 print(100 + (stat - 569) / 4.31) -- 118.79350348028 max health Source: https://wiki.multitheftauto.com/wiki/GetPedMaxHealth
- 2 replies
-
- 1
-
-
- health
- max health
-
(and 6 more)
Tagged with:
-
Maybe, but you do not really need a lot of work to make that to work. addCommandHandler("callclient", function (player) -- An addCommandHandler is needed, because the client hasn't loaded it's scripts yet. callClient(player, "hello", function (value) iprint(value) end) end, false, false) function hello () return exports. -- ... end That is not possible, as the table reference can't be transferred to the other side. When you export tables from 1 resource to another, it deep copies the table. And functions can't be transferred at all. If you really want that. You need to transfer the method as a string. local methods = { { key = "test1", value = [[ function (self, something) return somthing * 2 end ]] }, { key = "test2", value = [[ function (self, something) return somthing * 2 end ]] } }
-
Because the table is not an array format. That is why I split up the formats in to register and list. if not self.vehicles.register[vehicle] then self.vehicles.list[#self.vehicles.list + 1] = vehicleData self.vehicles.register[vehicle] = vehicleData else return false end #self.vehicles.list -- item count #self.vehicles.register -- always 0 In your case you can do 4 things. Recount local count = 0 for _,_ in pairs(vehicleCreator.vehicles) do count = count + 1 end Manually keep track of the count: self.vehicleCount = self.vehicleCount + 1 -- when you add a vehicle self.vehicleCount = self.vehicleCount - 1 -- when you remove a vehicle Or use an array format. --- at the cost of more search work with loops Or use 2 formats: array and custom indexes (vehicle = key) -- at the cost of more clean work I can answer that with an easy answer, but I do not think that would match your case, since that would kill some people their network. It is very important to write down the synchronization rules and pay a lot of attention to data reduction. Give it a 20 min brainstorm. Do you have to receive data when you are inside of a vehicle? Or when you are close by? Do you send the same value X when the user already know that the value is X? -- easy answer triggerClientEvent(players, "sync-vehicle-fuel", resourceRoot, { vehicleData1, vehicleData2, vehicleData3 }) addEvent("sync-vehicle-fuel", true) addEventHandler("sync-vehicle-fuel", resourceRoot, function (data) end, false) Exports do not work across clientside and serverside. Could work, but you can't reduce data. Element data maybe be smaller than triggerServerEvents, but you no control. But I do recommend to test both, so that you can get an idea, which one works better for you. To make the fuel system feel smoother, instead of only regular updates, you can also consider adding something that predicts what the fuel will be on clientside. So for example the server sends every 5 second an update. The updates from serverside: 100 > 95 > 90 While on clientside you make an future prediction and do: 100 > 99 > 98 > 97 > 96 > 95 > 94 > 93 > 92> 91 > 90
-
That is not so simple. Especially if you set a value from both sides at the same time. If there is a 'large' connection delay between the client and server. Client says the vehicle has 70 fuel. When that message is still underway, serverside says the vehicle has been filled up to 100 fuel. 1. Client set 70 2. Server sets 100 3. Client sets 100 4. Server sets 70 Now it is desynchronized, so the first step is to set the rules. For example: The server is only allowed to set the fuel value. You also need to make an collection of all vehicles, else you can't synchronize. vehicleCreator = {totalSavedVehicles = 0, totalTemporaryVehicles = 0, vehicles = {list={}, register={}}} The list is optional, it can be used to increase processing time for loops, since it is an array. if not self.vehicles.register[vehicle] then self.vehicles.list[#self.vehicles.list + 1] = vehicleData self.vehicles.register[vehicle] = vehicleData else return false end You can also turn these operations in to functions, but this is just basics. If you have a register, you have already have access to those data. The vehicle is the key of course. local data = vehicleCreator.vehicles.register[source] if data then -- magic end -- or function vehicleCreator:getVehicleData (vehicle) return self.vehicles.register[vehicle] end -- or vehicleCreator.getVehicleData = function (self, vehicle) return self.vehicles.register[vehicle] end Did you know that the JS libraries jquery and D3 are working very similar to that? They just put their own layer on top of it. jquery var element = $( "#id" ); d3 var element = d3.select("#id") Lua ??? local vehicleData = vehicleCreator:getVehicleData(vehicle) I know you want to work cleanly but you have to keep in mind that in order to do that, you have to start wrapping a lot of things. > Even if you did save these information into the class, you will lose that as soon as the element is destroyed. Which is another thing to keep in mind.
-
local consumeFuel = function() local vehicle = vehicleData.element local distance = getDistanceBetweenPoints2D(vehicle.position.x, vehicle.position.y, newPosition.x, newPosition.y) local engineConsumption = 0 if vehicle:getEngineState() then engineConsumption = 0.7 end if vehicleData.fuel >= 1 then vehicleData.fuel = vehicleData.fuel - (VEHICLE_FUEL_CONSUMPTION*(distance+engineConsumption)) newPosition.x, newPosition.y = vehicle.position.x, vehicle.position.y print(vehicleData.fuel) end if vehicleData.fuel < 1 then vehicleData.fuel = 0 vehicle:setEngineState(false) end end You do not have to create another function, you can just use 1 function instead. Every new function you create within a block, will keep the block alive. addEventHandler("onVehicleEnter", vehicleData.element, function(_, seat) if seat == 0 then local fuelTimer = setTimer(function(vehicle) consumeFuel() vehicle:setData("vehicle.datatable", vehicleData) end, 1000, 0, source) addEventHandler("onVehicleExit", source, function(_, seat) if seat == 0 then if isTimer(fuelTimer) then killTimer(fuelTimer) fuelTimer = nil end end end) end end) This code can cause a memory leak, since the code is merged with addEventHandler's that leave the Lua environment. Also here make use of 2 already existing function. If I want to have OOP tables (not meta table) shared between client/server. I have to split up the methods and re-attach them when they are available on the other side. > [1 file] Client only methods > [1 file] Server only methods > [1 file] Shared methods I do not know the best practice for this, but re-attaching them seems to work fine. Maybe you can use rawset: (not sure if that is allowed, I do not use MTA OOP, only regular) http://www.Lua.org/manual/5.1/manual.html#pdf-rawset And if you can't edit those classes, you can just put another meta layer on top of it, to make it work. I am not a pro,so I am pretty sure there are smarter people around here to give you the best answers.
-
For melee hits, there is 1, which only works for break-able objects. If you want other elements as well, you need to make the event yourself: https://wiki.multitheftauto.com/wiki/ProcessLineOfSight https://wiki.multitheftauto.com/wiki/BindKey For bullets: https://wiki.multitheftauto.com/wiki/OnClientPlayerWeaponFire
-
Locked, on request of the author. Request 'delete'. But deleting the topic is unnecessary, since this section is not for private help.
-
Hmm speed. It can be used. But it will be less accurate, because you are making assumptions about the future. > You do not know how far your car will have driven in the future. For example you hit the wall or another car. local previousVelocity addEventHandler("onClientPreRender", root, function (timeSlice) local vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then if previousVelocity then local travelDistance = getDistanceBetweenPoints3D(0,0,0, previousVelocity[1], previousVelocity[2], previousVelocity[3]) -- 1/50 of a second -- here you have to do something with timeSlice (which is the time between the [now] frame and [last] frame) and the speed... -- maybe: 1000 / 50 = 20 ?????????????? dxDrawText(travelDistance / 20 * timeSlice, 300,300 ) end local vX, vY, vZ = getElementVelocity(vehicle) previousVelocity = {vX, vY, vZ} end end) You still will have to test that with the position method.
-
https://forum.multitheftauto.com/topic/123569-hi-help-me-with-this-script-please/ As you said in your previous scripting request topic: You are not interesting in learning it, else you would have asked different questions. And yet I see you here again making the same scripting request, including unnecessary bumping. LOCKED
-
Just compare the distance between positions of the vehicle. So you get the position. And you wait with a delay. And then you get the position again. Now you can calculate the distance between them with: https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints2D https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D Just like a GPS does it's thing.
-
This tutorial is about scaling, not about positioning. If you are going to place it in the right + bottom corner, you have to start from that corner, not from the center. textWidth DOES NOT EXIST with the dxDrawText function. This function is making use of a text bounding box, which has a START (x,y) and an END (x,y). In this box you can align the the text: left, right, top, bottom. center(x), center(y). The following bounding box > starts at 0,0 which is the left + top corner and > ends on the right + bottom corner with some offset from the sides. The text is aligned to the right and to the bottom. local offsetFromSides = scaleV * 10 local textEndX = sx - offsetFromSides local textEndY = sy - offsetFromSides dxDrawText( text, 0, 0, textEndX, textEndY, tocolor(255, 255, 255, 255), scaleV*2, "arial", "right", "bottom")
-
Not really, but in the past I did create an experimental tablet / mobile / desktop version of the game as web app. This is exclusive serverside multiplayer, only local multiplayer. Note: Docs is in Dutch. Download JavaScript
-
@Sergo86 You should script this most partly serverside. And tell each client the direction of the ball. Synchronisation Server: ball position + direction > streamed to the clients. Client: position of the bars (to block the ball) > streamed to server Physics Server: mathematically collision calculations. Client: same mathematically collision calculations, except it gets overruled by the server in certain events. Like: ball misses bar or game ends. Key component: getTickCount()
-
@Swagy You can capture the screen with the following function: [input] https://wiki.multitheftauto.com/wiki/DxCreateScreenSource You can also figure out when somebody makes a screenshot: [timing] https://wiki.multitheftauto.com/wiki/BindKey You can get the pixels from that captured moment : [transform] https://wiki.multitheftauto.com/wiki/DxGetTexturePixels Save the image inside of the resource folder: [save] https://wiki.multitheftauto.com/wiki/DxConvertPixels And using XML or JSON to keep track of the saved files. [register]
-
Removing the addEventHandler does not stop the video. This handler only triggers when the browser is ready to be used. This only happens 1 time, per browser. If you want to stop playing YouTube, you could change the url or destroy the browser.
-
function getB() loadBrowserURL(source, "https://www.youtube.com/") end local browser function createYouTubeBrowser () if not browser then browser = guiCreateBrowser(0, 0, 1, 300, false, false, true, bbas) end local theBrowser = guiGetBrowser(browser) if source == youbutton then addEventHandler("onClientBrowserCreated", theBrowser,getB) guiSetEnabled ( youbutton, false ) guiSetEnabled ( googlebutton, false ) elseif source == stopbutton then removeEventHandler("onClientBrowserCreated", theBrowser,getB) guiSetEnabled ( youbutton, true ) guiSetEnabled ( googlebutton,true) end end addEventHandler("onClientGUIClick", stopbutton, createYouTubeBrowser) addEventHandler("onClientGUIClick", youbutton, createYouTubeBrowser) Something like that. Problem: You created multiple browsers. Tweak: Reduced event trigger rate, by attaching them to the right elements. @SoManyTears
-
Hey people, that some how get once again another super annoying pop-up...
I just wanted you to know that I kept my promise, project trains V2.0.0 is out with open source.
It took a little bit longer to clean up the old code, so `soon` was unfortunately not so soon. If you want to edit it, I have to apologies that I didn't clean up all the inconsistency within the code style. But never the less it has tabs and comments
!
I wish you the best of luck in these crazy times!
- Show previous comments 3 more
-
@IIYAMA carwars, it's kinda training server based on one of popular DayZ (not casual one - more like madness), mode - could say, most popular in Russia
-
-
@IIYAMA thank you, but it supports more than just Russian language - English, Polish, French.
-
You can download 2.0.0 now. See key features on the first page.
- 28 replies
-
- 1
-
-
- trains
- not compiled
-
(and 2 more)
Tagged with:
-
Then use a private message with him... leave me out of it. Locked, reason: scripting request
-
This section is for learning to script, feel free to make use of that. Unfortunately scripting requests are not allowed in this section. Please read the section rules:
