Jump to content

Aibo

Retired Staff
  • Posts

    1,105
  • Joined

  • Last visited

Everything posted by Aibo

  1. well, ok, when i think about it more, maybe you wanted it this way function LoginSystem(source, commandName,pw) local passwd = mysql_escape_string(sqllogin,pw) -- paswd > passwd local nick = mysql_escape_string(sqllogin, getPlayerName(source)) local query = mysql_query(sqllogin, "SELECT * FROM users WHERE username='" .. nick .."' AND password='" .. passwd .. "'") if (not query) then outputDebugString("mysql_query failed: (" .. mysql_errno(sqllogin) .. ") " .. mysql_error(sqllogin)) else if (mysql_num_rows(query) == 0) then outputChatBox("Wrong password", source) else outputChatBox("Loged in", source) -- i hope you'll put some login routines here later -- like setElementData or whatever -- or else how you'll know that player is logged in? end mysql_free_result(query) end end addCommandHandler("login", LoginSystem) as for login command, as i recall MTA package already includes authorization system and /login command is there already. if you're making your own, don't forget to disable it. and i think it's that login command that wasn't accepting your password, cause your code with that kind of error wouldn't even run. though ofc i may be wrong. EDIT: fixed your typo in paswd > passwd
  2. your if-else-ends are really messed up. i mean, function and 2 ifs means 3 ends and you have 4. clear that up with indents, cause i can't really think of the way you wanted it to be. function LoginSystem(source, commandName,pw) local paswd = mysql_escape_string(sqllogin,pw) local nick = mysql_escape_string(sqllogin, getPlayerName(source)) local query = mysql_query(sqllogin, "SELECT * FROM users WHERE username='" .. nick .."' AND password='" .. passwd .. "'") if (not query) then outputDebugString("mysql_query failed: (" .. mysql_errno(sqllogin) .. ") " .. mysql_error(sqllogin)) else if (mysql_num_rows(query) == 0) then -- then what? end outputChatBox("Wrong password", source) -- and here it becomes broken with "else" else outputChatBox("Loged in", source) end mysql_free_result(query) end end addCommandHandler("login", LoginSystem)
  3. oops, while i was typing answer was already posted well here's fun trick for you: try giving a negative amount of money (like -999999) there and see what happens anyway here's my part with a couple more checks: addCommandHandler("dardinero", function (thePlayer, theCommand, theTarget, amount) if theTarget then local giveTo = getPlayerFromName(theTarget) end if amount then amount = tonumber(amount) end if giveTo and amount then amount = math.floor(amount) if giveTo == thePlayer then outputChatBox("Error: You can't give money to yourself", thePlayer) elseif amount < 1 then outputChatBox("Error: You can't give nothing", thePlayer) elseif getPlayerMoney(thePlayer) < amount then outputChatBox("Error: You don't have $" .. amount, thePlayer) else takePlayerMoney(thePlayer, amount) givePlayerMoney(giveTo, amount) outputChatBox(getPlayerName(thePlayer) .. " gave you $" .. amount, giveTo) outputChatBox("You gave $" .. amount .. " to " .. theTarget, thePlayer) end else outputChatBox("Type /" .. theCommand .. " ", thePlayer) end end )
  4. error was in spawns[1].x, cause spawns is a table, while spawns[1] is not. you need to make a table before indexing it: local spawns = { } spawns[1] = { } spawns[1].x = -2030.1610107422 spawns[1].y = 172.25221252441 spawns[1].z = 28.8359375 spawns[1].rot = 90.0 spawns[2] = { } spawns[2].x = 423.2495 spawns[2].y = 453.2564 spawns[2].z = 564.6321 spawns[2].rot = 120.6928 etc. basically, the same thing DaK did *)
  5. INSERT adds a new row to the table UPDATE updates already existing row you should probably read about basic SQL syntax also, you can use executeSQLQuery, it'll be something like this: executeSQLQuery("UPDATE yourTableName SET SpawnX = '" .. x .. "', SpawnY = '" .. y .. "', SpawnZ = '" .. z .. "' WHERE Name = '" .. getPlayerName(thePlayer) .. "'")
  6. for SQLite (haven't tested though): function saveSpawn(thePlayer) local x, y, z = getElementPosition(thePlayer) if executeSQLUpdate("yourTableName", "SpawnX = '" .. x .. "', SpawnY = '" .. y .. "', SpawnZ = '" .. z .. "'", "Name = '" .. getPlayerName(thePlayer) .. "'") then outputChatBox("Spawn coordinates saved", thePlayer) else outputChatBox("Erorr blablablah", thePlayer) end end change "yourTableName" to.. well, your table name
  7. try this way: return array($ip, $country_code, $country_name, $region_name, $city, $zippostalcode, $latitude, $longitude, $timezone, $gmtoffset, $dstoffset); and instead of mta::doReturn: echo json_encode($ip_data);
  8. I've tried every possible thing I could imagine to retrieve the data from JSON objects, this is my thread. https://forum.multitheftauto.com/viewtop ... 4&p=301555 I never figured it out though, so I just decided to send the info to the MySQL databases via php then retrieve them with the server's mysql connection. Takes more time, but it was the only way I could do it. why didn't you just format all the data as JSON ordered array, like ["74.125.45.100", "United States", "California", "Mountain View"] if there was a problem with SDK doReturn, output the needed JSON string yourself with php echo this way it's all passed in order to the callback variables, my current geolocation script runs like this.
  9. yeah, i figured that out about requests, thanks. but what about JSON that goes to callback function (since it was my main question), is there some restrictions concerning recieved JSON format? everything is fine with arrays like [1,2,3] (and MTA PHP SDK returns data this way, as i recall), but how to get objects like {"key":"value"}? am i missing something, or there's no way? ofc it won't be an issue if i set up my own page, i'll just format JSON as needed or use the SDK. just out of curiosity
  10. guiCreateLabel with some big font or dxDrawText
  11. well wiki indeed says POST, but not "POST only" or "GET is not supported". just wanted to be sure. and yea, i know it's a table. and i wouldn't write here, haven't i tried all the ways i could think of, though i'm not a scripter addCommandHandler("cr", function () callRemote("http://pixelterror.ru/json.php", remoteCallback) end ) function remoteCallback(aTable) if aTable then -- something is there outputChatBox("one: " .. aTable.one) else -- got nothing outputChatBox(":(") end end i got nothing there. and if i try to index aTable right away it obviously gives "attempt to index local aTable (a nil value)" error. what do you mean by "this kind"? it's a common JSON object, "unordered set of name/value pairs". *) and it's not covered in wiki, whether callRemote supports only JSON arrays. if it is - i've no further questions. yea i've tried that too, no luck: function remoteCallback(...) local aTable = {...} if #aTable > 0 then -- something is there outputChatBox("table: " .. table.concat(aTable,", ")) else -- got nothing outputChatBox(":(") end end still ":(", cause it just makes an empty table. the thing is, i've been asked to make a trace script (ehehe). and ran into 2 obstacles: 1. geoip site supports only GET, while callRemote only POST 2. geoip site returns JSON key/value object, and not an ordered array. for now i have that taken care of by another php script which connects callRemote and geoip site. i guess i'll have to setup own geoip database
  12. damn, i thought it's something JRPG-like
  13. let's say i have some webpage that returns JSON array: ["1","value2","third value"] and i can access these values in callback function just fine: function remoteCallback(one,two,three) end my question is, how to get keys/values from a JSON object like this one: { "one" : "1", "two" : "value2", "three" : "third value" } maybe i'm missing something, but i couldn't *( and another question: callRemote does not support GET method? cause every address with GET parameters returns curl error 22.
  14. maybe engineLoadCOL, engineReplaceCOL? and here (https://wiki.multitheftauto.com/wiki/COL) it says:
  15. Aibo

    [Mysql] HELP

    you just need to fetch username and password from DB in some function. if combination found, function returns true, if not - false. is that so hard? well you can't just take some code and stick it in yours expecting that it will work. if it's not your code - check DB address/login/pass, table/row names, etc. and it's hard to read when it's not in english and not in [lua]
  16. have you added locations.xml to meta.xml of the resource?
  17. A command handler always passes the player who executed the command as first parameter so this should be valid. Somehow it still seems like this is not the case. Try "outputChatBox(type(playerSource))" somewhere to check the type of the variable (should be "userdata" in case of a player element ). damn i missed the handler at the bottom
  18. use [lua] tags, please error means that playerSource either not defined or is not a player element, so getPlayerName returns "false", which cannot be put into string. is playerSource passed to the function? *) and you have a typo in "playerSoure" here: outputServerLog( getPlayerName(playerSoure).. "gibt es schon!") outputChatBox( getPlayerName(playerSoure).. "getb es schon!", playerSource)
  19. first, replace "end if" with elseif, cause right now if portalBool is 0 you're setting it to 1 and then setting it back to 0: addCommandHandler ( "portal", function( commandName ) if portalBool == 0 then portalBool = 1 outputChatBox( "Portalgun turned on." ) elseif portalBool == 1 then portalBool = 0 if isElement(portalMarker1) then destroyElement(portalMarker1) end if isElement(portalMarker2) then destroyElement(portalMarker2) end outputChatBox( "Portalgun turned off." ) end outputChatBox( "Command done." ) end ) and i guess its better to check if element exists, before destroying it (otherwise you can get "Bad pointer" warnings in log). if you want to remove variable, use "nil", because "0" is still a value: addEventHandler("onClientPlayerQuit", rootElement, function() if isElement(portalMarker1) then destroyElement(portalMarker1) end if isElement(portalMarker2) then destroyElement(portalMarker2) end portalBool = nil portalMarker1 = nil portalMarker2 = nil end ) and why don't you use boolean for portalBool? addCommandHandler ( "portal", function( commandName ) if portalBool then portalBool = false if isElement(portalMarker1) then destroyElement(portalMarker1) end if isElement(portalMarker2) then destroyElement(portalMarker2) end outputChatBox( "Portalgun turned off." ) else portalBool = true outputChatBox( "Portalgun turned on." ) end outputChatBox( "Command done." ) end ) one more thing, onClientPlayerWeaponFire returns an ELEMENT with hitElement, not it's type, so "if not hitElement == "player" then" won't work, use getElementType: addEventHandler( "onClientPlayerWeaponFire", thisPlayer, function( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) if (portalBool == 1) and (weapon == 31) and (getElementType(hitElement) ~= "player") then if getKeyState( "1" ) then if isElement(portalMarker1) then destroyElement(portalMarker1) end portalMarker1 = createMarker( hitX, hitY, hitZ, "corona", 4, 0, 125, 35, 200 ) elseif getKeyState( "2" ) then if isElement(portalMarker2) then destroyElement(portalMarker2) end portalMarker2 = createMarker( hitX, hitY, hitZ, "corona", 4, 180, 0, 0, 200 ) end end end )
  20. well, but -- in front of ]] enables little trick: --[[ this way it's a block comment function someFunction(someVar) local anotherVar = someOtherFunction(someVar) someVar = nil anotherVar = nil return false end --]] and to uncomment the block, one more "-" is added at the start: ---[[ and this way it's a single line comment function someFunction(someVar) local anotherVar = someOtherFunction(someVar) someVar = nil anotherVar = nil return false end --]] and this is too and the code's on again *)
  21. events have the hidden variable "source" containing the element which triggered the event. thats why you were told to not overwrite it and use some other variable for player elements in functions. you dont have to use some specific player variable, it can be anything you want, just dont overwrite "source" if it exists, cause it can be confusing later. here you have to use that source variable, cause plr isnt defined anyway: function playerjoined() spawn(source) setTimer(keys, 1000, 1, source) setTimer(LichtAnlageOn, 500, 0, source) outputChatBox("Hi Noob!", source) end addEventHandler("onPlayerJoin", root, playerjoined) you just have to understand, where to use "source" and where to pass the player element with your own variable (plr/thePlayer/theGuy/whatEverItIs), that's all.
  22. as i told you, i don't know how exactly MySQL module works, since i never used it. the code i've posted was for SQLite. erorr is caused by "if #result > 0 then", because "result" is not a table. i think you need to use https://wiki.multitheftauto.com/wiki/Mod ... sql_result to get the data from "result" there. personally, i'd stick with SQLite
  23. almost, it would be something like this: executeSQLQuery("CREATE TABLE 'example' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'name' TEXT, 'age' INTEGER)") (that is if you use SQLite, of course. never tried MySQL module, but i guess there you'll have to use MySQL syntax and module's own query functions.)
×
×
  • Create New...