-
Posts
6,089 -
Joined
-
Last visited
-
Days Won
216
Everything posted by IIYAMA
-
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.
-
Validate elements if isElement(element) then -- < validate destroyElement(element) -- < destroy end Locals Local variables are active within a block. local marker = createMarker(2234, -2216, 12.5, "cylinder", 4, 255, 0, 0, 255, source) local blip = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) local truck = createVehicle(515, 2202, -2249, 14) local trailer = createVehicle(435, 0, 0, 4) Blocks: Functions functions functionName() local variable -- active t/m end end if elseif else if true then local variable -- active t/m elseif elseif true then local variable -- active t/m else else local variable -- active t/m end end Loops for i=1,10 do local variable -- active t/m end end You can also look here for inspiration: https://forum.multitheftauto.com/viewtopic.php?f ... 9&start=30 He had circa the same question.
-
Why hard?.. i said server-side work normally i want only client-side fix. Because I am trying to teach you something so you can find your problem, but you are with your head somewhere else. I can take a look at your code, spending 20 min looking for the mistake or I can let you debug it and you will learn something from it. And it will only cost 5 min of my time. The last methode is a standard of the scripting section, which is the one I prefer. It is a learning section after all.
-
Sorry, but you are very hard to help and only interested in the end product. I can't help you any further now, you should try to find somebody else who doesn't care about the debug process unlike me. Good luck!
-
This is what you must add: https://wiki.multitheftauto.com/wiki/OutputDebugString Why would we look for an unknown mistake all the way down the code, while you can locate circa the location for us?
-
It is very important to validate data before re-using it. This can be done with the isElement function. Ones data has been stored in variable or elementData and when you are going to re-use it over time, validation is required in order to have 0 warnings/errors. And study what the word local is for, because you are using it the wrong way.
-
There are no debug lines in this code. Add them, test it and then come back and tell me where it stops working.
-
remove line 38, it overwriting something you don't want to be overwritten.
-
The same way as with the label. Using guiSetText. I understand what a variable is, I only don't understand why you call it:www The name is just too hazy.
