FSXTim Posted May 19, 2012 Share Posted May 19, 2012 Hello, When I buy a repair, the database doesn't set 'Repair' from '0' to '1' and it doesn't revoke the money (50$)! This is my Script: function repair1_Button (state) if state == "left" then if source == GUIEditor_Button[1] then setElementData(localPlayer, "Money", (getElementData(localPlayer), "Money") or 0) - 50) setElementData(localPlayer, "Repair", (getElementData(localPlayer, "Repair") or 0) +1) outputChatBox ("Du hast Dir ein Auto Repair gekauft!", 0, 255, 0 ) end end end addEventHandler("onClientGUIClick", getRootElement(), repair1_Button) This is my start.lua (mysql): host = "XX" user = "XX" pass = "XX" db = "XX" port = 3306 sqlcon = mysql_connect(host, user, pass, db, port) --, "/var/run/mysqld/mysqld.sock") Maybe it only works with this sock! Debian 5.0 Lenny ?? local gRoot = getRootElement(); local gResRoot = getResourceRootElement( getThisResource () ); function nickprotect( onick, nnick ) local thePlayer = getPlayerFromName(onick) cancelEvent() outputChatBox("Du kannst deinen Namen nicht ändern!", thePlayer,255,0,0) end addEventHandler( "onPlayerChangeNick", getRootElement(), nickprotect ) function checkMySQLConnection ( ) if ( mysql_ping ( sqlcon ) == false ) then outputDebugString("MySQL Verbindung wird wiederhergestellt ...") mysql_close ( sqlcon ) sqlcon = mysql_connect(host, user, pass, db, port) --, "/var/run/mysqld/mysqld.sock") Maybe it only works with this sock! Debian 5.0 Lenny ?? end end addEventHandler( "onPlayerJoin", getRootElement(), checkMySQLConnection ) 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 if rows ==1 then if ( row[2] == md5(password) ) then setElementData(source,"Username",row[1]) setElementData(source,"Password",row[2]) setElementData(source,"EMail",row[3]) setElementData(source,"Repair",tonumber(row[32])) local playerMoney = getElementData(source,"Money") setPlayerMoney (source, tonumber ( playerMoney ) ) setPlayerName(source, getElementData(source,"Username")) else if not attemp then attemp=1 else attemp=attemp+1 end if attemp == 3 then kickPlayer( source, "Du hast zu viele Loginversuche gebraucht") end outputChatBox( "Das angegebene Passwort ist nicht korrekt!", source ) return end elseif rows == 0 then if not email or email=="" then outputChatBox("Bitte gebe eine gültige E-Mail Adresse an, danke!",source) return end local result = mysql_query(sqlcon, "INSERT INTO user_data SET Username='"..mysql_escape_string(sqlcon, username).."', Password='"..md5(password).."', EMail='"..mysql_escape_string(sqlcon,email).."', Fraktion='0', Skin='136', Rank='0', Spawn='0', Job='0', Materials='0', Drugs='0', LicA='0', LicB='0', LicC='0', Money='150', Bank='1500', Adminlevel='0', PlayedM='0', PlayedH='0', Wanted='0', Jailtime='0', Slot1='Frei', Slot2='Frei', Slot3='Frei', Slot4='Frei', Slot5='Frei', Slot6='Frei', Slot7='Frei', Slot8='Frei', Slot9='Frei', Slot10='Frei', Housekey='255', Repair='0';") mysql_free_result(result) result = mysql_query(sqlcon,"SELECT * FROM user_data WHERE Username='"..mysql_escape_string( sqlcon, username ).."';") if mysql_num_rows( result ) == 1 then row = mysql_fetch_row(result) else outputChatBox( "Der Account konnte nicht erfolgreich erstellt werden, bitte kontaktiere einen Admin", source ) end mysql_free_result(result) setElementData(source,"Username",row[1]) setElementData(source,"Password",row[2]) setElementData(source,"EMail",row[3]) setElementData(source,"Repair",tonumber(row[32])) setPlayerTeam(source, Zivilisten) setPlayerMoney (source, getElementData( source, "Money" )) setPlayerName(source, getElementData( source, "Username" )) end setElementData( source, "LoggedIn", true ) triggerClientEvent ( source, "hideLoginWindow", getRootElement() ) end addEvent("onPlayerGUILogin",true) addEventHandler ( "onPlayerGUILogin", getRootElement(), playerLogin ) function onQuit ( quitType, reason, responsibleElement ) setElementData( source, "Money", getPlayerMoney( source ) ) setElementData( source, "Wantedlevel", getPlayerWantedLevel( source ) ) if getElementData( source, "LoggedIn" ) then local result = mysql_query(sqlcon, "UPDATE user_data SET Fraktion='"..getElementData(source,"Fraktion").."', Skin='"..getElementData(source,"Skin").."', Rank='"..getElementData(source,"Rank").."', \ Spawn='"..getElementData(source,"Spawn").."', Job='"..getElementData(source,"Job").."', Materials='"..getElementData(source,"Materials").."', Drugs='"..getElementData(source,"Drugs").."', \ LicA='"..getElementData(source,"LicA").."', LicB='"..getElementData(source,"LicB").."', LicC='"..getElementData(source,"LicC").."', Money='"..getElementData(source,"Money").."', Bank='"..getElementData(source,"Bank").."', \ Adminlevel='"..getElementData(source,"Adminlevel").."', PlayedM='"..getElementData(source,"PlayedM").."', PlayedH='"..getElementData(source,"PlayedH").."', \ Wanted='"..getElementData(source,"Wanted").."', Jailtime='"..getElementData(source,"Jailtime").."', \ Slot1='"..getElementData(source,"Slot1").."', Slot2='"..getElementData(source,"Slot2").."', Slot3='"..getElementData(source,"Slot3").."', Slot4='"..getElementData(source,"Slot4").."', Slot5='"..getElementData(source,"Slot5").."', \ Slot6='"..getElementData(source,"Slot6").."', Slot7='"..getElementData(source,"Slot7").."', Slot8='"..getElementData(source,"Slot8").."', Slot9='"..getElementData(source,"Slot9").."', Slot10='"..getElementData(source,"Slot10").."', \ Housekey='255', Repair='"..getElementData(source,"Repair").."' WHERE Username='"..getElementData(source,"Username").."';") mysql_free_result( result ) end end addEventHandler ( "onPlayerQuit", getRootElement(), onQuit ) function onStop ( ) for index,v in ipairs( getElementsByType("player") ) do if getElementData( v, "LoggedIn" ) then setElementData( v, "Money", getPlayerMoney( v ) ) setElementData( v, "Wantedlevel", getPlayerWantedLevel( v ) ) local result = mysql_query(sqlcon, "UPDATE user_data SET Fraktion='"..getElementData(v,"Fraktion").."', Skin='"..getElementData(v,"Skin").."', Rank='"..getElementData(v,"Rank").."', \ Spawn='"..getElementData(v,"Spawn").."', Job='"..getElementData(v,"Job").."', Materials='"..getElementData(v,"Materials").."', Drugs='"..getElementData(v,"Drugs").."', \ LicA='"..getElementData(v,"LicA").."', LicB='"..getElementData(v,"LicB").."', LicC='"..getElementData(v,"LicC").."', Money='"..getElementData(v,"Money").."', Bank='"..getElementData(v,"Bank").."', \ Adminlevel='"..getElementData(v,"Adminlevel").."', PlayedM='"..getElementData(v,"PlayedM").."', PlayedH='"..getElementData(v,"PlayedH").."', \ Wanted='"..getElementData(v,"Wanted").."', Jailtime='"..getElementData(v,"Jailtime").."', \ Slot1='"..getElementData(v,"Slot1").."', Slot2='"..getElementData(v,"Slot2").."', Slot3='"..getElementData(v,"Slot3").."', Slot4='"..getElementData(v,"Slot4").."', Slot5='"..getElementData(v,"Slot5").."', \ Slot6='"..getElementData(v,"Slot6").."', Slot7='"..getElementData(v,"Slot7").."', Slot8='"..getElementData(v,"Slot8").."', Slot9='"..getElementData(v,"Slot9").."', Slot10='"..getElementData(v,"Slot10").."', \ Housekey='255', Repair='"..getElementData(source,"Repair").."' WHERE Username='"..getElementData(v,"Username").."';") mysql_free_result( result ) end end end addEventHandler( "onResourceStop", getResourceRootElement(), onStop ) addCommandHandler("spawnchange", function (thePlayer, command, type) if type == "fraktion" then setElementData(thePlayer, "Spawn", 1) outputChatBox("Spawnpunkt zur Fraktion geändert!", thePlayer,0,255,0) elseif type == "faction" then setElementData(thePlayer, "Spawn", 1) outputChatBox("Spawnpunkt zur Fraktion geändert!", thePlayer,0,255,0) elseif type == "street" then setElementData(thePlayer, "Spawn", 0) outputChatBox("Spawnpunkt zum Supermarkt geändert!", thePlayer,0,255,0) else outputChatBox("Mögliche Spawns : fraktion, street", thePlayer,255,0,0) end end ) Can anybody help me? Greets Link to comment
Jaysds1 Posted May 19, 2012 Share Posted May 19, 2012 (edited) try this, Script: function repair1_Button (state) if state == "left" then if source == GUIEditor_Button[1] then local money = getElementData(localPlayer, "Money") local repair = getElementData(localPlayer, "Repair") if(money)then setElementData(localPlayer, "Money",money-50) end if(repair)then setElementData(localPlayer, "Repair",repair+1) end outputChatBox ("Du hast Dir ein Auto Repair gekauft!", 0, 255, 0 ) end end end addEventHandler("onClientGUIClick", guiRoot, repair1_Button,true) Edited May 20, 2012 by Guest Link to comment
FSXTim Posted May 20, 2012 Author Share Posted May 20, 2012 (edited) Thanks, but not working! Greets Edited May 21, 2012 by Guest Link to comment
FSXTim Posted May 20, 2012 Author Share Posted May 20, 2012 Did you change something in your first post? Greets Link to comment
FSXTim Posted May 21, 2012 Author Share Posted May 21, 2012 I tried, but 'Repair' in the database is still '0'! Link to comment
kaos057 Posted May 23, 2012 Share Posted May 23, 2012 check the repair field type in the database and make sure it is not set to int. If it is int it wont work because you are storing it as a string. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now