Jump to content

FSXTim

Members
  • Posts

    220
  • Joined

  • Last visited

Everything posted by FSXTim

  1. FSXTim

    Endless loop

    @Alan.Alexander: This doesn't work. @TAPL function setZeit() outputChatBox("Test1", getRootElement()) for index, spieler in ipairs (getElementsByType("player")) do outputChatBox("Test2", getRootElement()) if getElementData( spieler, "LoggedIn" ) then outputChatBox("Test3", getRootElement()) setElementData(spieler, "Spielzeit", getElementData(spieler, "Spielzeit") + 1) local result = mysql_query(sqlcon, "UPDATE user_data SET Spielzeit='"..tostring(getElementData(spieler,"Spielzeit")).."' WHERE Username='"..tostring(getElementData(spieler,"Username")).."';") if (result) then mysql_free_result(result) end end end setTimer(setZeit2, 30000, 1) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), setZeit) function setZeit2() setTimer(setZeit, 30000, 1) end The ChatBox outputs the following two times: Greets
  2. FSXTim

    Endless loop

    Hay, I'm trying to raise the playtime (Spielzeit) every 60 seconds about 1. So I created a endless loop, but it isn't endless. After two times, it stops. function setZeit() for index, spieler in ipairs (getElementsByType("player")) do if getElementData( spieler, "LoggedIn" ) then setElementData(spieler, "Spielzeit", getElementData(spieler, "Spielzeit") + 1) local result = mysql_query(sqlcon, "UPDATE user_data SET Spielzeit='"..tostring(getElementData(spieler,"Spielzeit")).."' WHERE Username='"..tostring(getElementData(spieler,"Username")).."';") if (result) then mysql_free_result(result) end end end setTimer(setZeit2, 30000, 1) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), setZeit) function setZeit2() setTimer(setZeit, 30000, 1) end Greets
  3. Everything doesn't work, but I found a solution. I had to change this line local bt = tonumber(MySQL_GetString("Bann", "user_data", '"..nick"')) to local bt = tonumber(MySQL_GetString("Bann", "user_data", nick)) But thanks at all! Greets
  4. Dude, you didn't change anything! You also didn't change anything. Greets
  5. Thanks, I will test it in few hours. I have to go. Triggered: function bannCheck (nick, ip, username, serial) local bt = tonumber(MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'")) if bt then if bt > 0 then cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bannCheck) Greets
  6. Thanks for the answer, but no I have another problem. The DebugString sais 'Test', indifferent what 'Bann' is. It can be 0, 5 or 10 (line 13). The DebugString sais '0', although 'Bann' is '15' (line 6). function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else outputDebugString(mysql_num_rows(result)) if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldN mysql_free_result(result) return ds[feldN] else outputDebugString("Test!") mysql_free_result(result) return false end end end What do I have to do to fix it? Greets
  7. What do you mean? What do I have to change? I think I found the problem. The DebugString sais 'Test', indifferent what 'Bann' is. It can be 0, 5 or 10 (line 13). The DebugString sais '0', although 'Bann' is '15' (line 6). function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else outputDebugString(mysql_num_rows(result)) if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldN mysql_free_result(result) return ds[feldN] else outputDebugString("Test!") mysql_free_result(result) return false end end end What do I have to do to fix it? Greets
  8. Hello, although I set 'Bann' in the database to 10, the event is not canceled. function bannCheck (nick, ip, username, serial) local bt = tonumber(MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'")) if bt then bool = not (bt == 0) end if bool then if bt < 0 then MySQL_DelRow ("Bann", "user_data", "Name LIKE '"..nick.."'") elseif bt > 0 then cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bannCheck) Greets
  9. function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, bedingung).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets
  10. I know that, but how can I fix it? Greets
  11. Thanks, no more errors in the second script. But I have one problem, the DebugString doesn't say 'Test' and the event isn't canceled. Error (line 3): attempt to compare number with boolean function bannCheck (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bannCheck) Greets
  12. Thanks, Solidsnake14, but I had to change it to: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE Username='"..mysql_escape_string(sqlcon, username).."';") if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Error: Bad argument #2 'mysql_escape_string' (string expected, got nil) Greets
  13. It's working now. Sorry, it was my mistake. But no I have another problem. DebugString: Unknown 'Name' in 'where clause'. And also the DebugString doesn't say 'Test'. First script: function bann (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt then bool = not (bt == 0) end if bool then if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bann) Second script: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets
  14. Hello, I have a small problem again. DebugString: Unknown 'Name' in 'where clause'. And also the DebugString doesn't say 'Test'. First script: function bann (nick, ip, username, serial) local bt = MySQL_GetString("Bann", "user_data", "Name LIKE '"..nick.."'") if bt then bool = not (bt == 0) end if bool then if bt > 0 then outputDebugString("Test") cancelEvent(true, "Du bist gebannt!") end end end addEventHandler("onPlayerConnect", getRootElement(), bann) Second script: function MySQL_GetString(feldN, tableN, bedingung) local result = mysql_query(sqlcon, "SELECT "..feldN.." FROM "..tableN.." WHERE "..bedingung) if (not result) then outputDebugString(mysql_error(sqlcon)) else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets
  15. Thanks for your answer. Here i definied sqlcon: host = "XX" user = "XX" pass = "XX" db = "XX" port = 3306 sqlcon = mysql_connect(host, user, pass, db, port) Just for example, here is a script, which is working perfectly with the mysql_query and sqlcon: function playerLogin ( username,password,email ) local result = mysql_query(sqlcon,"SELECT * FROM user_data WHERE Username='"..mysql_escape_string( sqlcon, username ).."';") if result then rows = mysql_num_rows(result) if rows == 1 then row = mysql_fetch_row(result) end mysql_free_result(result) end end Greets
  16. Hello, I have a small problem. The DebugString sais 'Error!' (line 4), but why? function MySQL_GetString(tableN, feldN, bedingung) local result = mysql_query(sqlcon, "SELECT "..tableN.." from "..feldN.." WHERE "..bedingung) if (not result) then outputDebugString("Error!") else if(mysql_num_rows(result) > 0) then local ds = mysql_fetch_assoc(result) local savename = feldname mysql_free_result(result) return ds[feldname] else mysql_free_result(result) return false end end end Greets
  17. I do only retrieve it here: function playerJoin() setElementData(source, "Bann", tonumber(getElementData(source, "Bann"))) local bt = tonumber(getElementData(source, "Bann")) if bt >= 1 then kickPlayer(source, "Du bist gebannt! ["..zeit.."]") end end addEventHandler("onPlayerJoin", getRootElement(), playerJoin) local bt = tonumber(getElementData(source, "Bann")) Greets
  18. Ok, I understand you. I tried it like this. Error: attemt to compare number with nil function playerJoin() setElementData(source, "Bann", tonumber(getElementData(source, "Bann"))) local bt = tonumber(getElementData(source, "Bann")) if bt >= 1 then kickPlayer(source, "Du bist gebannt! ["..zeit.."]") end end addEventHandler("onPlayerJoin", getRootElement(), playerJoin) There has to be a solution to check the row of the username (in the database) which is connecting to the server. If the value is > 0 then cancelEvent, else continue connecting to the server. Greets
  19. I think true. Because in the database I can see the bann time, which I set. Greets
  20. I created my own database (mysql). I will tell you a little bit more about my script. I created my own admin panel and I have to enter a number. The number is the bann time of the player. setElementData(source, "Bann", timeOfBann) -- the time is saved in my mysql database Then the player is disconnected from the server. If he trys to join again, this script is activated: function playerConnect(nick) local name = getPlayerFromName(nick) if (tonumber(getElementData(name, "Bann")) ~= 0) then bannT = (tonumber(getElementData(name, "Bann"))) zeit1 = math.floor ( bannT / 60 )..":"..( bannT - math.floor ( bannT / 60 ) * 60 ) zeit2 = ( bannT - math.floor ( bannT / 60 ) * 60 ) if zeit2 > 9 then zeit = math.floor ( bannT / 60 )..":"..( bannT - math.floor ( bannT / 60 ) * 60 ) else zeit = math.floor ( bannT / 60 )..":0"..( bannT - math.floor ( bannT / 60 ) * 60 ) end cancelEvent(true,"Du bist gebannt! ["..zeit.."]") end end addEventHandler("onPlayerConnect", getRootElement(), playerConnect) Greets
  21. Sure, I did, 'Bann' is saved in the database. And how can I check the 'Bann'-data otherwise? Greets
  22. Hay, there is an error is this script. Could you please jave a look at it? Error: attempt to perform arithmetic on global 'bannT' (a nil value) function playerConnect(nick) local name = getPlayerFromName(nick) if (tonumber(getElementData(name, "Bann")) ~= 0) then bannT = (tonumber(getElementData(name, "Bann"))) zeit1 = math.floor ( bannT / 60 )..":"..( bannT - math.floor ( bannT / 60 ) * 60 ) zeit2 = ( bannT - math.floor ( bannT / 60 ) * 60 ) if zeit2 > 9 then zeit = math.floor ( bannT / 60 )..":"..( bannT - math.floor ( bannT / 60 ) * 60 ) else zeit = math.floor ( bannT / 60 )..":0"..( bannT - math.floor ( bannT / 60 ) * 60 ) end cancelEvent(true,"Du bist gebannt! ["..zeit.."]") end end addEventHandler("onPlayerConnect", getRootElement(), playerConnect) Greets
×
×
  • Create New...