Jump to content

Noki

Members
  • Posts

    850
  • Joined

  • Last visited

Everything posted by Noki

  1. Not helpful at all. As for the OP, you're definitely on the right track. Just a few small syntax errors and some logic that could be improved on. function start() executeSQLQuery("CREATE TABLE IF NOT EXISTS stats_p (name STRING,serial STRING,played INT,wins INT,points INT,cash INT,kills INT,color STRING,wheel INT,wheelc STRING)") end addEventHandler("onResourceStart", resourceRoot, start) function join() local name = getPlayerName(source) local serial = getPlayerSerial(source) local tables = executeSQLQuery("SELECT name,played,wins,points,cash,kills FROM stats_p WHERE serial=?",serial) if #tables == 0 then executeSQLQuery("INSERT INTO stats_p (name,serial,played,wins,points,cash,kills,color,wheel,wheelc) VALUES(?,?,?,?,?,?,?,?,?,?)",name,serial,1,1,1,1000,1,"#FFFFFF",1,"#FFFFFF") setElementData(source,"played",1,true) setElementData(source,"wins",1,true) setElementData(source,"points",1,true) setElementData(source,"cash",1000,true) setElementData(source,"kills",1,true) setElementData(source,"color","#FFFFFF",true) setElementData(source,"wheel",1,true) setElementData(source,"wheelc","#FFFFFF",true) else setElementData(source,"played", tables[1].played,true) setElementData(source,"wins", tables[1].wins,true) setElementData(source,"points", tables[1].points,true) setElementData(source,"cash", tables[1].cash,true) setElementData(source,"kills", tables[1].kills,true) setElementData(source,"color",tables[1].color,true) setElementData(source,"wheel",tables[1].wheel,true) setElementData(source,"wheelc",tables[1].wheelc,true) end end addEventHandler("onPlayerJoin", root, join) function left() local played = getElementData(source,"played") local wins = getElementData(source,"wins") local points = getElementData(source,"points") local cash = getElementData(source,"cash") local kills = getElementData(source,"kills") local color = getElementData(source,"color") local wheel = getElementData(source,"wheel") local wheelc = getElementData(source,"wheelc") local name = getPlayerName(source) local serial = getPlayerSerial(source) executeSQLQuery("UPDATE stats_p SET name=?,played=?,wins=?,points=?,cash=?,kills=?,color=?,wheel=?,wheelc=? WHERE serial=?",name,played,wins,points,cash,kills,color,wheel,wheelc,serial) end addEventHandler("onPlayerQuit", root, left) function stopped() for i, player in ipairs(getElementsByType("player")) do local played = getElementData(player,"played") local wins = getElementData(player,"wins") local points = getElementData(player,"points") local cash = getElementData(player,"cash") local kills = getElementData(player,"kills") local color = getElementData(player,"color") local wheel = getElementData(player,"wheel") local wheelc = getElementData(player,"wheelc") local name = getPlayerName(player) local serial = getPlayerSerial(player) executeSQLQuery("UPDATE stats_p SET name=?,played=?,wins=?,points=?,cash=?,kills=?,color=?,wheel=?,wheelc=? WHERE serial=?",name,played,wins,points,cash,kills,color,wheel,wheelc,serial) end end addEventHandler("onResourceStop", resourceRoot, stopped) function findPlayer(namepart) for i, player in ipairs(getElementsByType("player")) do local name = getPlayerName(player) if string.find(name:lower(), namepart:lower(), 1, true) then return player, name end end return false end function dms() local players = getElementsByType("player") for k,v in ipairs(players) do if #players >=2 then setElementData (v,"played",getElementData(v,"played") + 1,true) else outputChatBox("Min 2 players to count stats",getRootElement(),0,191,0) end end end addEventHandler("onMapStarting", root, dms) function win(hh) local playername = getPlayerName(source) setElementData(source,"cash",getElementData(source,"cash")+1000,true) setElementData(source,"points",getElementData(source,"points")+10,true) outputChatBox(playername.." won this round.",getRootElement(),0,191,0) setElementData ( source ,"wins",getElementData(source, "wins") + 1,true) end addEvent("onPlayerWinDD", true) addEventHandler("onPlayerWinDD", root, win) function stats(source, command, player) if not player then local name = getPlayerName(source) local played = getElementData(source,"played") local wins = getElementData(source,"wins") local points = getElementData(source,"points") local cash = getElementData(source,"cash") local kills = getElementData(source,"kills") outputChatBox(name..": "..played.." DMs, "..wins.." Wins, "..cash.."$, "..points.." pts, "..kills.." Kills.",getRootElement(),0,191,0,true) else local player = findPlayer(player) local name = getPlayerName(source) local name1 = getPlayerName(player) local played1 = getElementData(player,"played") local wins1 = getElementData(player,"wins") local points1 = getElementData(player,"points") local cash1 = getElementData(player,"cash") local kills1 = getElementData(player,"kills") outputChatBox("<"..name.."> "..name1.." "..played1.." DMs, "..wins1.." Wins, "..cash1.."$, "..points1.." pts, "..kills1.." Kills.",getRootElement(),0,191,0,true) end end addCommandHandler("st", stats) addCommandHandler("stats", stats) addCommandHandler("sts", stats) function command(source, command) setElementData(source,"cash",1000000,true) end addCommandHandler("givem",command) function getPlayerStats(player) local played = getElementData(player,"played") local wins = getElementData(player,"wins") local points = getElementData(player,"points") local cash = getElementData(player,"cash") local kills = getElementData(player,"kills") return played,wins,points,cash,kill end executeSQLQuery("UPDATE stats_p SET name=?,played=?,wins=?,points=?,cash=?,kills=?,color=?,wheel=?,wheelc=? WHERE serial",name,played,wins,points,cash,kills,color,wheel,wheelc,serial) You forgot to put '=?' after the serial field in the WHERE clause. You did it on other places though. addEventHandler ( "onResourceStop", getRootElement(), stopped) addEventHandler("onResourceStart", root, start) Tying these events to the root element essentially means when any resource starts, or when any resource stops. In this case, you don't really need this event tied to such a high element. We can replace root/getRootElement() here with resourceRoot, which is the root of the resource it is running in. I would also recommend indenting your code as it makes it easier to read and understand.
  2. Noki

    Symbols

    Expanding on what Andrei said, make sure you set the encoding to UTF-8 and convert it to UTF-8 if you haven't done so already.
  3. Noki

    Decrypt Please

    I am sure if you were to crack the centralized encryption of pretty much all client-side files, MTA devs would rather reward you for it than let you run around with that knowledge. Something like that is more detrimental than a simple cheat or bug. But hey, let's hope a situation like that does not arise.
  4. Noki

    Decrypt Please

    I tell you what, if you do manage to decrypt and decompile it, I'm sure the MTA devs won't mind tossing a little bit of money your way.
  5. https://wiki.multitheftauto.com/wiki/In ... Web_Server
  6. You can use the cache="false" option in the meta.xml file to automatically delete the file after it is downloaded. You can also use luac.multitheftauto.com to obfuscate your scripts.
  7. I can't replicate that, KariiiM.
  8. Check if the player you're trying to warp to is in a vehicle (assuming you're using the default admin or freeroam resources).
  9. Noki

    MTA on Mac

    I believe qaisjp found a way to run MTA on macOS. I don't know if it still works though. Your best bet is to use parallels or VMWare and run Windows.
  10. function destroyPickups() local objects = getElementsByType("pickup") for i, k in ipairs(objects) do if (getResourceName(getElementID(getElementParent(getElementParent(k)))) == "race") then destroyElement(k) end end end addCommandHandler("destroypicks", destroyPickups) Try this. It checks if the resource a pickup belongs to is the race element. I'm sure you could do this more efficiently by looping through the children of the race resource, like this (untested): function destroyPickups() local pickups = getElementChildren(getElementChildren(getResourceFromName("race")), "pickup") for i, k in ipairs(pickups) do destroyElement(k) end end addCommandHandler("destroypicks", destroyPickups)
  11. Think of it like a machine. You put something into the machine to get something out. What you're doing with these parameters is telling the machine what you're going to be "feeding" it. They are called predefined variables. You can find all predefined variables here - https://forum.multitheftauto.com/viewtopic.php?f=91&t=39678. I just used 'playerSource' because that's what I usually use for command handlers. You can put anything you like in there. It's just a variable. You can put anything in there. I have always worked with the '_' (underscore) as a placeholder that I won't use. In the brackets of a function. function hello(argument1, argument2) They should check if a player was found from that name. local player = getPlayerFromPartialName(target) if (not player) then -- We haven't found a player outputChatBox(playerSource, "We couldn't find a player with that name", 255, 0, 0) return end No need to be sorry. We've all got to start somewhere.
  12. function getDistance(playerSource, _, target) local x, y, z = getElementPosition(playerSource) local x1, y1, z1 = getElementPosition(getPlayerFromPartialName(target)) local distance = getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) outputChatBox("Entfernung: "..distance.." meters", playerSource, 0, 255, 0) end addCommandHandler("entfernung", getDistance) You were definitely on the right track. However, addCommandHandler has two parameters, the player who typed the command and the command name (which we usually ignore). client, the variable which you were using, is used for events that have been triggered from the client-side. It's an easy mistake to make and I used to do it myself. Only after those two parameters do any arguments we type after the command (eg: /command arg1 arg2) get processed. Now you were declaring your variables as global. Which we don't really do as they're not needed outside of that function. Local variables get destroyed after the code block in which they're in ends. In the case of your script, they will get destroyed when the function ends. The actual command handler, we just need the command name. We don't need to specify anything that comes after. We do that in the handler function itself. I also don't think the command system plays well with spaces (as they're what are used to separate arguments). The only thing currently wrong with your code is it will output errors when it can't find a player with that name. A few simple if-statements could solve that.
  13. Not equal to. 5 ~= 3 -- true 5 ~= 5 -- false
  14. Is the position randomised within those top 7?
  15. You never defined accountsXML in your else statement. So it's trying to open a nil value instead of a file handler. Simply define accountsXML and it should work. else outputChatBox("creating accounts.xml") accountsXML = xmlCreateFile("accounts.xml","accounts") accountUsername = xmlCreateChild(accountsXML,newUser) xmlNodeSetAttribute(accountUsername,"password",newPass) xmlNodeSetAttribute(accountUsername,"money",0) xmlSaveFile(accountsXML) end
  16. Noki

    [HELP]Modules

    It's a 32-bit module and will not run on the 64-bit server.
  17. Sometimes I have problems with booleans. I use this to return an absolute boolean value. I don't know if it really fits in here. function boolean(var) return not (not var) end boolean("foo") -- true boolean(nil) -- false boolean(true) -- true
  18. I'm pretty sure he's talking about MTA.
  19. You can't set defaults for text fields in MySQL. Edit: didn't see it was SQLite. Silly me.
  20. Firstly, I would recommend using the db functions. When you perform a query and get the result, you end up with a table. Each row is identified with a numerical index, like this: result = { [1] = {column = data}, [2] = {column = data}, } If the result of your SQL query has more than 1 row, you will end up with more than 1 entry in your resultant table (returned from dbPoll). If you want to list that data like you said in the OP, just loop through it.
  21. As always, there are multiple ways to solve one problem. Yours is obviously much more elegant. Let me know how it goes.
  22. You might have more luck posting this where it's supposed to be posted.
  23. The answer to this is setObjectBreakable. However, as you said, the hay objects are server-sided. That makes it slightly trickier. We do know that most elements created server-side sync client-side. Which means we're in luck. Try putting all the hay objects into a table, sending this table client-side, and looping through each object and setting it to not breakable. From there, you can use breakObject in conjunction with onClientPlayerWeaponFire to break the object (use hitElement). Though that will only work for one client at a time. So you will need to trigger an event on the server which breaks it for all connected clients (which alsoo means another client event).
  24. I would strongly recommend moving towards the in-built db functions. db = dbConnect(...) addEventHandler("onPlayerLogin", root, function (_, acc) local userAccountName = getAccountName(acc) local qh = dbQuery(db, "SELECT accountName FROM accountdatas WHERE accountName = ?", accName) local result = dbPoll(qh, -1) if (#result == 0) then -- The query returned no rows local createData = dbExec(db, "INSERT INTO accountdatas (accountName, playerJoin) VALUES (?, ?)", userAccountName, 0) if (createData) then outputChatBox("#C1C1C1*Your account data was successfully created.", source, 255, 255, 255, true) end end end ) The question marks mean 'substitute something into here'. As we can see after the SQL query (in the same function), there are arguments. These are the arguments we pass into the query itself. It's called preparing a statement.
  25. Noki

    hoster

    I would recommend checking the Hosting solutions subforum. There are host giveaways from time to time. But honestly, you should spend the money on a proper host. Free hosts will tend to steal your resources, or just be a poor host in general (downtime, no support, lag etc). I recommend forking out the $5 or $10 it costs for a server. You can even get cheaper servers from Digital Ocean or Vultr and they even have pay-as-you-go models, the catch being you need to set it up yourself as it's a VPS.
×
×
  • Create New...