-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
local result = tonumber(getElementData (source,dataName)) if result then
-
Use both. But I do not understand how you get this problem in the first place. That bindKey scenario is very unclear because it is incomplete for me as reader. In my damage over write script I am working around it, by calculating the damage of explosions serverside. And sync the effects with triggerLatentClientEvent > client createExplosion(damaging = false).
-
When you set the maxVelocity it doesn't mean it will actually reach it. That has to do with the acceleration, wheel grip and probably the amount of weight too. The property maxVelocity is for downgrading your vehicle speed. A kind of limiter.
-
hmm, didn't know that because I never used it. if meta and next(meta) then textWidth = dxGetTextWidth(meta.stream_title or "", 1, "default-bold")
-
2 reasons why this error shows up. The meta data isn't downloaded yet from the streamed song. You have to keep in mind that the meta isn't directly available. The first part of the song have to be downloaded before it will shows up, while the lua code doesn't wait for it. The song doesn't have a title. Can be simply solved with: if meta then -- check if there is a meta available. textWidth = dxGetTextWidth(meta.stream_title or "", 1, "default-bold")
-
I still do not recommend you to do it that way. (with streamed in/out) But make sure you freeze the player position when they spawn, till the process has been finished.
-
Using onClientElementStreamIn, will not give you the result you want. And you have to uses the slow loading function for loading the objects. What you want is assigning elements to a 2D grid of X(300) units. local gridHolder = {} local gridSize = 300 local objects = getElementsByType("object") for i=1,#objects do local object = objects[i] local x,y,z = getElementPosition(object) local gridX = math.floor((x/gridSize)+0.5) local gridY = math.floor((y/gridSize)+0.5) local gridDataX = gridHolder[gridX] if not gridDataX then gridHolder[gridX] = {} gridDataX = gridHolder[gridX] end local gridDataY = gridDataX[gridY] if not gridDataY then gridDataY[gridY] = {} gridDataY = gridDataX[gridY] end gridDataY[#gridDataY+1] = getElementModel(object) end local gridsAroundPlayer = { {0,0},--center {0,-1},-- top {1,-1},-- right/top {1,0},-- right {1,1},-- right/bottom {0,1},-- bottom {-1,1},-- left/bottom {-1,0},-- left {-1,-1}-- left/top } local loadedIds = {} local loadedGrids = {} local nextGridUpdate = 0 addEventHandler("onClientRender",root, function () local timeNow = getTickCount() if timeNow > nextGridUpdate then nextGridUpdate = timeNow+300 local playerX,playerY,playerZ = getElementPosition(localPlayer) local gridX = math.floor((playerX/gridSize)+0.5) local gridY = math.floor((playerY/gridSize)+0.5) local newLoadedIds = {} local loadingGridsNew = {} for j=1,#gridsAroundPlayer do local offSet = gridsAroundPlayer[j] local gridX = gridX + offSet[1] local gridY = gridY + offSet[2] if not loadedGrids[gridX.."/".. gridY] then local gridDataX = gridHolder[gridX] if gridDataX then local gridDataY = gridDataX[gridY] if gridDataY then -- -- gridDataY, -- store every id inside: newLoadedIds[id] -- loadedIds[id] < make sure that id isn't placed in this variable. -- load mods on id... loadingGridsNew[gridX.."/".. gridY] = true end end end end for key, data in pairs(loadedGrids) do if not loadingGridsNew[key] then local gridDataX = gridHolder[gridX] if gridDataX then local gridDataY = gridDataX[gridY] if gridDataY then -- gridDataY, -- newLoadedIds < make sure the id isn't in this table. -- unload mods from id end end end end loadedGrids = loadingGridsNew loadedIds = newLoadedIds end end) This is not tested.
-
That is the spirit!
-
How about replacing only the ones that are nearby? > Problem solved.
-
I do not know if there is a limit. But if you want to replace 2000+ objects, it might be handy to process the data a little bit slower. Create yourself a slow processing function. You will get the best performance with: (clientside only) local thisTable = {} local slowProcessingIndex = 1 function slowProcessingFunction () local endLoopTime = getTickCount()+10 -- 10 ms = 100fps. repeat local tableData = thisTable[slowProcessingIndex] slowProcessingIndex = slowProcessingIndex+1 until getTickCount() > endLoopTime or slowProcessingIndex > #thisTable if slowProcessingIndex > #thisTable then removeEventHandler("onClientRender",root,slowProcessingFunction) end end addEventHandler("onClientRender",root,slowProcessingFunction) I see a lot of people messing with timers, but works 100 times better. Stable fps(depending on how large the mods are) and doesn't crash. I am using something similar with on my custom map loader and Dutch saying: "Het loopt als een trein" >(probably)> "It works/moves like a train".
-
It is not about the errors or your end result, it is about learning to script. Ones you understand tables very well, you will be able to script much greater scripts. They are the key to let your code doing every you want. If this is too hard, you should focus more on lua than mta functions.
-
It depends what kind of things you store in it. Elementdata is for sync data with all clients, which you only want to use for letting all player know that one specific player has 60 fps. When it comes to how much "items" a player caries, elementdata would totally ruining your server. You don't want/need to let other players know that information. Waste of your bandwidth if you ask me. Your question: many elementdata vs one big Every time you update the key "data", all players in your server have to re-download the elementdata. Is a big elementdata efficient? No, it is exactly the opposite. But there is one exception, if the elementdata has to be downloaded only ones, it might be more efficient.
-
Doing that would make your code not very efficient. Also, ones you used a table location which you aren't going to use anymore, you have to nil it. jTrucker[source] = nil else it is still in the memory... And this is a wrong validation, because if one element isn't valid the other elements won't get destroyed. if (isElement(pTrucker["marker"]) and isElement(pTrucker["blip"]) and isElement(pTrucker["truck"]) and isElement(pTrucker["trailer"])) then destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) destroyElement(pTrucker["truck"]) destroyElement(pTrucker["trailer"]) end if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end
-
There is no pick-up that gives money, you have to script that.
-
I do not fully understand what is wrong. If you show these conditions and actions as a schematic, I might understand it better. 1) if... 2) then .. 3) and..
-
getPlayerSerial getPlayerAccount --[[>>]] not isGuestAccount --[[>>]] getAccountName --And if you are using very long jail times: setAccountData Replace the table key with the results of: table[getPlayerSerial] or table[getAccountName]
-
function checkHisTime (player) -- < you use addCommandHandler and not an event. local playerjailSystemData = jailSystemData[player] And the addEventHandler ( "onPlayerJoin", getRootElement(), checkIfJailed ) event in combination with a table + userdata is a bit useless. Because when a player leaves the server, his userdata becomes invalid. And when he rejoins, his userdata is not the same. You should use serials or account names for that.
-
The addCommandHandler doesn't have a source element. The first argument is the player. And if that isn't the problem, you should show more of your code because I do not have enough information to debug it.
-
Which event's is attached on both function? And remember, timers don't support a source element.
-
Move these lines bellow the showgui function. for k, v in pairs(markersPosTable) do local marker= createMarker(v[1], v[2], v[3], "cylinder", 1.0, 0, 122, 43, 211) setElementInterior(marker, v[4]) setElementDimension(marker, v[5]) addEventHandler("onClientMarkerHit", marker, showgui) end
-
If nothing is showing in debug script, you have to find out till where your code works. Add debug lines after the lines: 2, 5, 7, 9, 13 A debug line is: outputDebugString("function jailOrNotPlayer has been executed") In the console you will see this line, when it gets executed. Ones you added them all, you can see how many debug-lines are executed. After the last one that is executed, there is mostly your mistake. So for example: outputDebugString(1) if true then outputDebugString(2) if true then outputDebugString(3) if true then outputDebugString(4) if false then outputDebugString(5) if false then outputDebugString(6) end end end end end The code will show the debug-lines 1,2,3,4 but not 5 and 6. Now you know that there is a mistake between the debug-lines 4 and 5.
-
Not tested. But by putting the conditions and actions inside a schematic another scripter can easier understand what he needs to rewrite. I normally don't write somebody else his code, but for this learning point I am making an exception. Copy the code to your editor for a better view. function hitTheMarker(vehicle,matchingDimension,marker) if matchingDimension then -- 1) Player hits marker local marker = marker or source -- if marker from the recheck timer or use the source element from the event. if source or -- < if triggered by event(source) isElement(marker) and isElement(vehicle) then -- or < called by timer if getElementData(marker,'gasStation') and getElementType(vehicle) == 'vehicle' then local vehicleType = getVehicleType(vehicle) if vehicleType == 'Automobile' or vehicleType == 'Bike' or vehicleType == 'Monster Truck' or vehicleType == 'Quad' or vehicleType == 'Plane' or vehicleType == 'Boat' or vehicleType == 'Helicopter' then local driver = getVehicleController(vehicle) if driver then -- 2) If players engine is on, it alerts him to turn it off if getVehicleEngineState ( vehicle ) then outputChatBox("Press J or do /engine to turn engine off.",driver, 255, 255, 255) --[[ 4) If not it keeps checking --What I originally planned to replace this with is when the player presses space it checks, if not alerts driver to turn engine off, if so it continues. / --Which ever would be easier, first option or this./ ]] setTimer(hitTheMarker,500,1,vehicle,matchingDimension,marker) -- < recheck else-- 3) It checks if engine is off -- 5) If it is off, it refuels the vehicle setTimer(hitTheMarker,1500,1,vehicle,marker,driver) end end end end end end end addEventHandler('onMarkerHit',root,hitTheMarker) function vehicleRefuel(vehicle,marker,driver) if isElement(driver) and isElement(marker) and isElement(vehicle) and -- validation getPedOccupiedVehicle(driver) == vehicle and isElementWithinMarker(vehicle,marker) then -- validation local maxFuel = carFuel[0] if getPlayerMoney(driver) < 25 then outputChatBox("You cannot afford any more fuel.",driver, 255, 255, 255); return end local vehicleModel = getElementModel(vehicle) if carFuel[vehicleModel] then maxFuel = tonumber(carFuel[vehicleModel]) or 0 end if getCarFuel(vehicle) < maxFuel then addCarFuel(vehicle,15) takePlayerMoney(driver,25) -- 6) After vehicle is fully refueled it alerts the driver. if getCarFuel(vehicle) >= maxFuel then outputChatBox("Your vehicle has been 100% refueled.",driver, 255, 255, 255); takeCarFuel(vehicle,getCarFuel(vehicle)-maxFuel); return end setTimer(vehicleRefuel,500,1,vehicle,marker,driver) end end end
-
Just make as much as possible serverside, except for the effects, visuals, etc.
-
Can you put it as a schematic(list)? Because I do not understand the steps you are taking. So: 1) Hit marker 2) Player puts vehicle engine off. etc.
