Jump to content

MaddDogg

Members
  • Posts

    189
  • Joined

  • Last visited

Everything posted by MaddDogg

  1. Hi! I'm currently working on a car system and I just tried something out at the odometer. The number is shown digitally using dxDrawText and has 2 decimal digits. But now I thought, let's have some more digits in front of the decimal position. But the problem is that when I use a directive inside of string.format with a number in front of the '%', it naturally uses this number for the digit amount of decimal digits. On the other hand, the %d directive uses this system to determine the amount of decimal digits. (I hope you can still follow me ) Now I came up with the following, but I just ask myself, if there's a simpler way to do it: local integer = string.format("%07d", kmDistance) -- getting the integer value for the predecimal digits local decimals = string.sub(string.format("%.2f", kmDistance - math.floor(kmDistance)), 2, 4) -- this creates the string holding the decimal digits - the '0' in front of it is cut away dxDrawText(integer .. decimals,scrW*0.3,scrH*0.9297,scrW*0.3661,scrH*0.9619,tocolor(50,65,100,255),1.0,"default-bold","center","center",true,false,true) -- drawing the odometer number So, is there a better way to do this? And is it a problem do have this in an onClientRender handler function? Or is it a bit too heavy for slow PCs? Thanks for any help in advance. Madd
  2. MaddDogg

    Serial ban???

    Yes, it works, because the serial is generated at installation of MTA and not directly connected to the MTA community.
  3. You could script the command server-side and then trigger a client event to play the sound for every player. This could look like this: Server-side: addCommandHandler("sound", function (player) triggerClientEvent("onSoundRequest", player) end ) Client-side: addEvent("onSoundRequest", true) addEventHandler("onSoundRequest", getRootElement(), function () playSound("sounds/mySound.mp3") end )
  4. Now I also want to join the party Here my first try.. (original is in 1600x2000)
  5. Oh, my mistake, the code snippet was actually the one to hide it again, the actual one has a true in it. I already thought about using dx functions for that, that would also probably be easier to handle since I constantly check for a change in element data and adapt the image according to that. I'll try dx now, thanks for the help.. If I'll run into another problem, I will post it in here, else problem kinda solved.
  6. Hi, I'm currently working on a car panel system, which uses among other things images, which are showing up when entering a car. Those images are created at the client resource start and hidden by default. I didn't have a problem with my system until some of my friends working with me wanted to have a look at the new scripted stuff. But some of them just crashed when they entered a car, to be exact, at the point where the images where instructed to show up (code for that below). This is the main code: carSymbols["highbeams"] = guiCreateStaticImage(scrW*0.2530,scrH*0.9619,40,40,"images/icon_car_highbeams.png",false) carSymbols["lights"] = guiCreateStaticImage(scrW*0.2095,scrH*0.9619,40,40,"images/icon_car_lights.png",false) carSymbols["park"] = guiCreateStaticImage(scrW*0.5089,scrH*0.9619,40,40,"images/icon_car_park.png",false) carSymbols["doors"] = guiCreateStaticImage(scrW*0.4690,scrH*0.9635,40,40,"images/icon_car_doors.png",false) carSymbols["indicator_left"] = guiCreateStaticImage(scrW*0.3167,scrH*0.9619,40,40,"images/icon_car_indicator_left.png",false) carSymbols["indicator_right"] = guiCreateStaticImage(scrW*0.3607,scrH*0.9619,40,40,"images/icon_car_indicator_right.png",false) carSymbols["fuel"] = guiCreateStaticImage(scrW*0.6190,scrH*0.9619,40,40,"images/icon_car_fuel.png",false) carSymbols["battery"] = guiCreateStaticImage(scrW*0.5482,scrH*0.9619,40,40,"images/icon_car_battery.png",false) carSymbols["engine"] = guiCreateStaticImage(scrW*0.1655,scrH*0.9619,40,40,"images/icon_car_engine.png",false) carSymbols["oil"] = guiCreateStaticImage(scrW*0.5863,scrH*0.9619,40,40,"images/icon_car_oil.png",false) carSymbols["warn"] = guiCreateStaticImage(scrW*0.4298,scrH*0.9619,40,40,"images/icon_car_warn.png",false) The following is responsible for making these images visible: for key, imageElement in pairs(carSymbols) do guiSetVisible(imageElement, false) end I already tried several approaches to fix the problem like putting the loop to make the images visible into a command, but it doesn't matter, when these lines are called, as soon as the images are made visible, my friends have a crash. I was able to narrow down the problem to the table. This means that when I don't put the images into carSymbols[] and give all of them "their own variable", my friend won't get a crash. Btw the table is created at client resource start. And the odd thing is that it works for 50% of the people who entered a car on my server, the other half got a crash. So, can somebody explain to me, why this table is making such problems and why it is just effecting some of the people, who tried it out? Thanks in advance! Madd
  7. THANK YOU! That solved my problem. Did not know that the ACL even restricts some functions. Thank you again.
  8. Hi! I just ran into a strange problem. Maybe someone could help me with it. I wrote a script which amongst other things is supposed to save the player's ip in a database. So I used getPlayerIP to return the IP for me which I then put into a query. But for some reason I am getting the following result in the server.log (and no result ingame, the script stops executing the called function at this point): WARNING: script.lua: Access denied @ 'getClientIP' - Line: 2 Odd is that it says 'getClientIP' although I used getPlayerIP. Even when I used getClientIP I got the exact same error message. Then I asked myself, if I misunderstood a function or something else so I tried out the following code, which I copied from the wiki: function printIp ( thePlayer ) outputChatBox ( "IP: " .. getPlayerIP ( thePlayer ), thePlayer ) end addCommandHandler ( "ip", printIp ) And what did I get? The error message.. So, what is my problem? Is there anything I have to do or consider using this function? I also use the 'admin' resource by lil_toady and here the function works fine and in the GUI window the IP adress of a player is displayed correctly, so it is not a global problem of my server (configuration). To prevent standard questions: Yes, I used it in a server-side script. Yes, I restarted the server process several times. Thanks for any help in advance. Madd
  9. Alright, thanks for the help! I now did it with the MySQL module, because later on I want to be able to modify the data through a web browser UCP. Here's my example code, if it helps anyone to create his account system: pData = {} pDataValueTypes = {"name", "password", "level", "points"} function CheckMySQLConnection() if mysqlCon == nil or mysql_ping(mysqlCon) == false then outputServerLog("Establishing MYSQL connection..") mysqlCon = mysql_connect("localhost", "CHANGEME", "CHANGEME", "CHANGEME", 3306, "/var/run/mysqld/mysqld.sock") if mysqlCon == nil then outputServerLog("ERROR: Couldn't connect to database!") return false end end return true end function getAccountValues(player, cmd, loginname, password) if CheckMySQLConnection() == false then return outputChatBox("#FF0000Wasn't able to connect to database!", player, 0, 0, 0, true) end if pData[player] ~= nil then -- if player table already exists --> player is already logged in return outputChatBox("#FF0000You're already logged in!", player, 0, 0, 0, true) end if loginname == nil or password == nil then -- if parameters are not given return outputChatBox("#55FF55Use this syntax: /testlogin [NAME] [PASSWORD]", player, 0, 0, 0, true) end tmpResult = mysql_query(mysqlCon, "SELECT name, password, level, points FROM pdata WHERE name = '" .. loginname .."'") -- getting account data if(mysql_num_rows(tmpResult) == 0) then -- if name is not existent return outputChatBox("#FF0000This name is not registered!", player, 0, 0, 0, true) end -- fetching the data local tmpValues = mysql_fetch_assoc(tmpResult) mysql_free_result(tmpResult) if password ~= tmpValues["password"] then -- if given password is not matching saved one return outputChatBox("#FF0000The password is not correct!", player, 0, 0, 0, true) end pData[player] = {} -- initialize player table -- fill player table with fetched data for i,types in pairs(pDataValueTypes) do pData[player][types] = tmpValues[types] end outputChatBox("#FF0000You were successfully logged in! Your points: #00FFFF" .. pData[player]["points"], player, 0, 0, 0, true) -- success message end addCommandHandler("testlogin", getAccountValues, false, false)
  10. Okay, so the following is then giving me my wanted result?: pData = { "name" = {}, "password" = {}, "level" = {}, "points" = {} } pDataValueTypes = {"name", "password", "level", "points"} function getAccountValues(player, loginname) local tmpvalues = executeSQLQuery("SELECT name, password, level, points FROM playerdata WHERE name = '" .. loginname .. "'") for i=1, types in ipairs(pDataValueTypes) do pData[player][types] = tmpvalues[1][types] end outputChatBox("#FF0000Data successfully read!", player, 0, 0, 0, true) end Everything correct here? The table correctly initialized? Is there perhaps an example or published account system, at which I can take a look to see how it's done there? Or any tutorial?
  11. Thanks for the answers! So, would the following be correct? addEventHandler("onCorrectLoginData", getRootElement(), function (player, loginname) pData[player] = executeSQLQuery("SELECT level, money, points FROM playerdata WHERE name = '" .. loginname .. "'") outputChatBox("You're now logged in!", player) end ) The result should be a table which can be used like this: ... if pData[player]["level"] > 1 then outputChatBox("You are an admin!", player) end ... Thank you again!
  12. First of all thanks for the answers It really cleared up some things for me. So, when I want to call a custom function, which lies in a second serverside script of the resource, I just call it normally by for example.. local value = getSomePlayerValue(player) But if this function is in a clientside script and I want to call it out of the serverside script, I have to use events? But how do I get the value that is returned? Because of course I can't fetch this from triggerClientEvent. And another question: I have an account system and fetch the account data of an user by a query. What would be the best way to store the data? I want to store the data in a big table called pData, but how do I do that exactly? The players don't have fixed server slot IDs, so I can't just put them into pData[5] for player in slot 5. And I also want to clear the data again, when the player leaves. Thank you guys for your help!
  13. Hi! I just switched from SA:MP to MTA, because SA:MP p*ssed me off more and more, and so I just started learning LUA from yesterday on. Luckily, I can connect several behaviours and syntaxes from LUA with Pascal and ActionScript, in which I'm quite experienced. But still I got some (noob) questions, for which I couldn't figure out an answer yet. It would be very nice, if you could help me with the following: How to call a function from a lua script inside the same resource? For example a function in the clientside script, which I need to call by the serverside script. I already tried with something like this.. call(getResourceFromName("test"), "setSomeVar", var, "string") ..but it didn't work. Also just calling the function like it would be inside the same script didn't work. Or do I always have to use event triggering? And yes, I added an export node to the meta.xml to export my function. Also, how call an outside function then, which returns values? Is there a resource or something like that that provides a graphical interface for the inbuilt SQL server? Or is there a way to use an external server, so that I could use phpMyAdmin? It's not that I'm too unskilled in MySQL, but it would spare me the scripting of an ingame GUI for it. You don't have to, if you think this question is too nooby, but can you explain to me the meaning of 'in ipairs' and 'in pairs' as used in for loops? What is the LUA equivalent of "new const IM_A_CONST[] = {100, 200, 300};"? Thanks, if you could help me with all this, I would really appreciate it. And respect to the MTA team, I'm just amazed by the mass of manipulable things ingame =D>
×
×
  • Create New...