Jump to content

driver2

MTA Contributors
  • Posts

    139
  • Joined

  • Last visited

Member Title

  • MTA Contributor

Details

  • Gang
    Hells Angels

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

driver2's Achievements

Poot-butt

Poot-butt (14/54)

1

Reputation

  1. Just one thing about that admin login. Maybe it was just an excercise to learn scripting, but you should be aware that clientside scripts are not safe for that kind of things. That password could simply be read by looking at the script, since it is downloaded to each player. They are stored in MTA\mods\deathmatch\resources. Clientside scripts should never be used to do anything security related.
  2. "Table" is the datastructure of Lua that can be used as an array, list or even class. The ipairs() iterator only works with increasing indices (1,2,3,4, ..). If you want to loop through all numbers, use a numeric for loop: for i = 1,10 do .. end -- loops from 1 to 10 in steps of 1 If you want to loop through all elements of a table in no particular order, use pairs(): for k,v in pairs(table) do .. end Maybe you also want to use table.insert() and table.remove() which shifts the indices to create increasing indices. http://lua-users.org/wiki/ForTutorial http://www.lua.org/manual/5.1/manual.html#5.5
  3. You have to use onClientRender to draw the lines, because it only draws them for one frame. It won't be any stress for the server, since it's clientside. The Client however may loose a considerable amount of fps, depending on how much static you draw and how. I just made a quick test: local w,h = guiGetScreenSize() local startX = 1 local time = 0 local previousTime = nil local direction = 1 local waitFor = 0 local static = {} local amountOfStatic = 2 local waitChance = 1 function draw() local amount = w/10 if not previousTime then previousTime = getTickCount() return end if math.random(0,1000) == 0 then return end time = time + getTickCount() - previousTime previousTime = getTickCount() for i=1,amountOfStatic do if static[i] == nil then static[i] = { direction=1, waitFor=0, startX=0 } end if math.random(1,100*i*waitChance) == 1 then static[i].waitFor = getTickCount() + math.random(100,2000) end if static[i].waitFor > getTickCount() then break end if math.random(1,20) == 1 and time > 1*1000 then static[i].startX = math.random(1,w) time = 0 else if math.random(1,20) == 1 then static[i].direction = math.random(-4,4) end static[i].startX = static[i].startX + static[i].direction end local startX = static[i].startX local startY = 1 while startY < h do local length = math.random(1,6) if math.random(1,4) == 1 then local x = startX + math.random(1,2) dxDrawLine(x,startY,x,startY+length,tocolor(255,255,255,math.random(80,150))) end if math.random(1,4) == 1 then local x = startX + math.random(-30,30) dxDrawLine(x,startY,x,startY+1,tocolor(255,255,255,math.random(100,255))) end startY = startY + length end end for i=1,amountOfStatic*10 do local x = math.random(1,w) local y = math.random(1,h) local length = 1 local color = tocolor(255,255,255,math.random(100,255)) --dxDrawLine(x,y,x+1,y+length,color,1,true) end end local showStatic = true addCommandHandler("static",function() if showStatic then addEventHandler("onClientRender",getRootElement(),draw) else removeEventHandler("onClientRender",getRootElement(),draw) end showStatic = not showStatic end) Maybe it is useful for you, just play with it a bit. There may be better way to do it though. It also shows the addEventHandler/removeEventHandler which works fine for me.
  4. Adding rows to SQLite is considerably slower than reading data. However, you also have to use it correctly to make a fair comparison. I'm certainly no expert, but here's an interesting comparison: I added 100 rows to an empty table, which took about 8.8590 seconds. Then I used "BEGIN" and "COMMIT" (http://www.sqlite.org/lang_transaction.html) to send it all in one transaction, and it took only 0.1090 seconds. That's not always usable of course, but if you add much data at once, it can be useful (much like prepared statements in MySQLi, even if the method might be different). Also, if you compare it with MySQL, you also have to take into account that not everyone may have access to a MySQL database on the same server and sending it to another takes again more time, depending on the connection.
  5. Hi, I was thinking how the performance of using account data compares to using SQLite for saving/accessing account-related stuff. The advantage of account data is that it's easy to use and it is stored together with the accounts, which is sensible for stuff closely related to the account (like register date or something). However if you have a lot of accounts (let's say a few hundred) and want to filter or sort them by register date (or anything else), I was wondering if SQLite wasn't better suited for that. What do you think? Greetings
  6. What about if it's not in the meta.xml? Note that I would NOT like to have that function, so other servers CAN'T read the file. The server who has written it obviously knows the filename.
  7. Hi, say there's a file saved in a clienside resource directory called '8902342348092349908.xml'. Is there any way to read that from a clientside resource without knowing it's name? Like list all files in the directory? I want to save a file that can only be read by the server who has written it. Greetings
  8. You could probably use string.find() while looping through all players. Be careful to set the plain-argument to true, or else you might accidently use lua patterns. You should also check if there was more than one match, else you could accidently execute the command on someone you didn't intend to.
  9. driver2

    Teams

    How about reading the readme?
  10. This is what it says in the WIKI Yes, but only if you use parameter binding. If you just put the values directly in the query string, it can't escape them to prevent SQL Injection. The function doesn't prevent you from doing it 'wrong'. Just use the method with the questionmarks, that way the function will know which part of the query is a value and create a safe query for you.
  11. driver2

    Teams

    Maybe try this: https://community.multitheftauto.com/index.php?p= ... ils&id=612
  12. onClientPlayerJoin is not triggered for the local player. What you want is onClientResourceStart: addEventHandler("onClientResourceStart",getResourceRootElement(),LoginWindow)
  13. Something like that seems problematic to me or is SQL Injection no issue in MTA/SQLite? Why not use parameter binding? executeSQLQuery("UPDATE yourTableName SET SpawnX = ?, SpawnY = ?, SpawnZ = ? WHERE Name = ?",x,y,z,getPlayerName(theplayer)) Of course it depends on where you get your data from. But even something like the player name is a value the user inputs. I don't know if or how much damage could be done, but I guess parameter binding should be safer.
  14. I think lua is pretty easy and flexible to use. The tables are extremely versatile, e.g. you can use anything as a key, even another table. You don't have to predefine the size or somehting. Functions can return multiple values, which can come in very handy, e.g. you could return a boolean to say if a function succeded, as well as a message that contains the reason. And of course there are functions like getElementPosition() which you can use like that: local x,y,z = getElementPosition() Instead of: local pos = getElementPosision() -- would have to return a table to return several values local x = pos.x local y = pos.y local z = pos.z Of course you first have to get used to a new language.
×
×
  • Create New...