Jump to content

Bonus

Members
  • Posts

    297
  • Joined

  • Last visited

Everything posted by Bonus

  1. Bonus

    Element Data

    You should really write that element data should be avoided if not necessary. I see so many guys here using setElementData for every little storage. Your last code is the best example how to make your code as unperformant as possible. Only use setElementData if you want something to be synced with every player and every resource + if it's not that bad if someone changes it (NOT adminlevel, NOT money etc.) If you only want it clientsided you can use triggerClientEvent and save it serversided in a table. If you only want it serversided, use a table. If you want to use it in another resources, use export functions. Here a quote from sbx320:
  2. Ähm ... Welches Script überhaupt?! Du schreibst es so, als wäre es von MTA Standard.
  3. You won't set his interior to 0 but talk about "he left the store". What are you using to get him out of the store? There is a fkin setElementInterior ( element, 0 ) to get the player out of the store.
  4. Oh god ... Do you even know LUA and read that code? I mean do you even know what the code does?! You don't even give all informations. "Just use the code after setElementInterior ..." I mean your own fkin code you want to use. Just use it AFTER setElementInterior, what is the problem?! Your way: Ask the whole time if his interior is 0. My way: 1. There is a "setElementInterior" in use to get the player into interior 0. So just get the marker/colshape or whatever, search for setElementInterior ( player, 0 ) and use your code after that. 2. setElementInterior HAS TO BE USED to get the player into interior 0 (or spawnPlayer, but don't think so). So you can modify setElementInterior and ask if the element is the player doing the mission. If it's the player, just use your code. My Code from 1. comment does the 2. way.
  5. Just use the code after setElementInterior ...
  6. ... It works ... why shouldn't it work?!
  7. Just modify setElementInterior like that: local _setElementInterior = setElementInterior function setElementInterior ( element, int ) if isElement ( element ) and getElementType ( element ) == "player" and int == 0 then -- Do whatever you want here -- end return _setElementInterior ( element, int ) end
  8. local counter = 0 local vehicletable = nil addCommandHandler ( "dothatthing", function ( ) vehicletable = getElementsByType ( "vehicle" ) counter = 0 if vehicletable[1] then setTimer ( function ( ) counter = counter + 1 if isElement ( vehicletable[counter] ) then setElementData ( vehicletable[counter], "data", 1 ) end end, 2000, #vehicletable ) end end )
  9. Sure: local counter = 0 setTimer ( function ( ) local vehicles = getElementsByType ( "vehicle" ) if vehicles[1] then counter = #vehicles > counter and counter + 1 or 1 setElementData ( vehicles[counter], "data", 1 ) end end, 2000, 0 )
  10. I said what I learned from mta wiki. But you wrote it yourself: dbFree, iff you dont want the data, mysql_free_result if you get data. So dbFree ~= mysql_free_result, my "mysql_free_result isnt dbFree." is right.
  11. "Note: Vehicles (and other elements) created client-side are only seen by the client that created them, aren't synced and players cannot enter them. They are essentially for display only." Why do you even create the vehicle clientsided? Or use setElementModel?
  12. It's your own fault: local a = 0 if a == 0 then local a = 1 outputChatBox ( a ) --> outputs 1 end outputChatBox ( a ) --> outputs 0 local a = 0 if a == 0 then local b = 0 outputChatBox ( b ) --> 0 else local b = 1 outputChatBox ( b ) --> 1 end outputChatBox ( b ) --> nil Local is only available in the same "block". Blocks are: file function if else elseif for while repeat An end closes the block (not in file).
  13. local vehRainbowTimer = {} local sectoswitchcolor = 0.1 -- can change that local function colorTheVehicle ( veh ) if getVehicleOccupant ( veh ) then setVehicleColor ( veh, math.random ( 255 ), math.random ( 255 ), math.random ( 255 ) ) elseif isTimer ( vehRainbowTimer[veh] ) then killTimer ( vehRainbowTimer[veh] ) end end local function rainbowWhatever ( player ) local veh = getPedOccupiedVehicle ( player ) if veh and getPedOccupiedVehicleSeat ( player ) == 0 then vehRainbowTimer[veh] = setTimer ( colorTheVehicle, sectoswitchcolor * 1000, 0, veh ) end end I did it with "if getVehicleOccupant ( veh ) then" instead of "onVehicleExit" because in some situations it doesnt trigger onVehicleExit or onPlayerVehicleExit even if you are out (I think when you get ported out or spawn somewhere else with spawnPlayer, not sure).
  14. It's absolutely not the same -.- mysql_free_result: "Frees the last query result. This function should be called after every query, specially when these queries return any data." dbFree: "This function frees a database query handle. dbFree only needs to be used if a result has not been obtained with dbPoll" You should use mysql_free_result after EVERY query! Doesn't matter if you get any data or not. But you use dbFree ONLY if you DON'T want to get the result. With MySQL-module I had to use mysql_free_result every time, but with mta db functions I never used dbFree. It's not the same, it's too different.
  15. 1LoL1 thats wrong. mysql_free_result isnt dbFree. The functions you want to know: dbExec - Use it for a command where you don't need a result back (delete, update ...) - You get true or false back dbQuery - Can use it with everything - returns a query handle which you can turn into a result (dbPoll) or free when you dont want the result (dbFree) dbFree - Use it when you get a query handle and don't want the result dbPoll - Use it when you get a query handle and want the result You never use dbFree with dbPoll, always atleast one, but never both. dbPoll returns you are result. This result is a table. Its index is 1 to amount of rows. If you use WHERE name = "Bonus" and there is only 1 name="Bonus" row in db the result is like that: result = { [1] = { column1 = value1, column2 = value2, column3 = value3 ... } } If there are more rows with the name "Bonus" it is like that: result = { [1] = { column1 = value1 ... }, ... [amountrows] = { column1 = ... } } I always ask that way: local result = ... if result and result[1] then So I can see if dbPoll was succesfull and there is atleast 1 row. After that I can use a for: for i=1, #result do for column, value in pairs ( row) do outputChatBox ( column .. " : "..value ) end end And I've never used dbFree. If I don't want the result I'll just use dbExec.
  16. Bonus

    Few questions.

    How about giving informations about WHAT YOU DON'T UNDERSTAND. I learned everything by trying and looking into MTA Wiki, it's not hard. Why would someone explain the same **** again if it's already in the wiki?!
  17. Bonus

    Floating markers

    The code does: 1. Create a global variable a (why global and not local?) 2. Create the function float 3. Overwrite the function float 4. Call float with onClientRender There can't be 2 global functions with the same name. And you should really care about the performance, your code is ****. You use really bad names for global variables and functions. Example how to write the code MUCH better: local markerupspeed = 0.1 -- Use names describing the function local counttorevert = 0 -- Use local! Better performance + security local shopMarkers = {} -- Save the markers in a table, better than getElementsByType local function moveTheShopMarkes ( ) -- its called in every frame, localize it to speed up the access if counttorevert + 3000 <= getTickCount() then -- dont need for "not counttorevert" because of counttorevert = 0 markerupspeed = markerupspeed * -1 counttorevert = getTickCount() end for i=1, #shopMarkers do -- We use the table created at resource-start - its faster local x, y, z = getElementPosition ( shopMarkers[i] ) setElementPosition ( shopMarkers[i], x, y, z + markerupspeed ) end end addEventHandler ( "onClientResourceStart", resourceRoot, function ( ) local markers = getElementsByType ( "marker" ) -- save it to use for i=1, #markers local counter = 0 -- counter for integer index for i=1, #markers do -- Better than pairs or ipairs if getElementData ( markers[i], "shopMarker" ) then -- don't need "== true" if it can be only true or false counter = counter + 1 shopMarkers[counter] = markers[i] end end addEventHandler ( "onClientRender", root, moveTheShopMarkes ) end )
  18. Try to use renderTargets for large drawings which doesnt change (like HUD background). Try to use setElementData fewer. If you want to sync something for only one player (or some) (like your own statistics, which are not in playerlist), just use triggerClientEvent. Save your informations in a table instead of elementdata. Only use setElementData when you wanna sync an information with every player and every resource. triggerClientEvent is muuch better than setElementData (+ safer, can't get changed by client). Replace every ipairs with i=1, ... Try to localize everything possible. Even the functions, localize them if you don't use them from other datas. Try to use the db functions as few as possible. Save the informations in an array instead of letting the player use db functions whole time. If you use onClientGUIClick, dont use root, use the GUI. If you use onMarkerHit, use the marker, not root. If you have to use onClientClick for something special, add the event only when its needed and remove it when not needed. etc. When you have to use the same funcion multiple times in the same function with the same arguments, just save it to a variable and use that instead. Try to create timers as few as possible. Many times you can just use getTickCount instead, thats better. You got your own nametag? Try to get the players for nametag with streamed players (onClientElementStreamIn and out). Its much better than using getElementsByType. You got your own playerlist in dx? Put the players in a table and use the table, much better than getElementsByType. Use break in a loop. Don't loop long tables too many times. Try to use onClientRender as performant as possible. Its triggered in every framerate!
  19. You work with GUI Buttons? Then use onClientGUIClick, not onClientClick!! "This is linked to the GTA world, as oppose to GUI for which onClientGUIClick is to be used. This event allows detection of click positions of the 3D world."
  20. "The source of this event is the client's root element." Thats not onClientGUIClick, it's onClientClick.
  21. guiGridListGetSelectedItem and guiGridListGetItemText
  22. Do it yourself now. It's nearly the same.
  23. function spawnMyVehicle_func (id) if not playerVehicles[source] then playerVehicles[source] = {} end if #playerVehicles[source] >= 1 then for ind,car in ipairs(playerVehicles[source]) do if not isElement(car) then playerVehicles[source][ind] = nil end end end if #playerVehicles[source] >= 1 then exports.CSFtexts:output("You can only spawn 1 vehicle Destroy the Current vehicle first.", source, 255, 85, 0, true) return end local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1) if type(data) == "table" and #data ~= 0 then if getVehicleByID(id) then exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." is already spawned.", source, 255, 85, 0, true) else local color = split(data[1]["Colors"], ',') r1 = color[1] or 255 g1 = color[2] or 255 b1 = color[3] or 255 r2 = color[4] or 255 g2 = color[5] or 255 b2 = color[6] or 255 vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"]) setElementData(vehicle, "ID", id) table.insert(playerVehicles[source],vehicle) local fuelnu = data[1]["fuel"] or 100 local tune = fromJSON(data[1]["handling"]) -- outputChatBox(data[1]["handling"],source,255,0,0) --outputChatBox(tostring(tune),source,255,0,255) exports.CSFcarTune:setCarData(vehicle,tune,true) setElementData(vehicle, "vehicleFuel", fuelnu) local upd = split(tostring(data[1]["Upgrades"]), ',') for i, upgrade in ipairs(upd) do addVehicleUpgrade(vehicle, upgrade) end local Paintjob = data[1]["Paintjob"] or 3 setVehiclePaintjob(vehicle, Paintjob) setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) if data[1]["HP"] <= 255.5 then data[1]["HP"] = 255 end setElementHealth(vehicle, data[1]["HP"]) setElementData(vehicle, "Owner", source) vv[vehicle] = setTimer(function(source) -- if not isElement(source) and isTimer(vv[vehicle]) then killTimer(vv[source]) vv[source] = nil end -- if isElement(source) and getElementHealth(source) <= 255 then -- setElementHealth(source, 255.5) -- setVehicleDamageProof(source, true) -- setVehicleEngineState(source, false) -- end end, 50, 0, vehicle) addEventHandler("onVehicleDamage", vehicle, function(loss) local account = getAccountName(getPlayerAccount(getElementData(source, "Owner"))) setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source) end) addEventHandler("onVehicleEnter", vehicle, function(player) if getElementHealth(source) <= 255.5 then setVehicleEngineState(source, false) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end) exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." has been spawned.", source, 255, 85, 0, true) cur = getElementData(source,"spawnedcars") or {} table.insert(cur,getVehicleNameFromModel(data[1]["Model"])) setElementData(source,"spawnedcars",cur) end else exports.CSFtexts:output("There might be problem with this vehicle, please call an admin.", source, 255, 85, 0, true) end end addEvent("SpawnMyVehicle", true) addEventHandler("SpawnMyVehicle", root, spawnMyVehicle_func ) addCommandHandler ( "spawnvehicle", function ( player, _, int ) triggerEvent ( "SpawnMyVehicle", player, tonumber ( int ) ) end )
  24. You should really read the MTA Wiki: https://wiki.multitheftauto.com/wiki/CreateWeapon or atleast use the debugscript ...
×
×
  • Create New...