trajik Posted August 11, 2010 Share Posted August 11, 2010 Hi, I began talking about this on a previous thread so I decided to post a new one. Thanks to Uniqu3 I have the idea and I believe I am heading in the right direction....here's what I have so far... playerState = 0 function changeTheButton(theUser) if( not connect_mysql ) then outputChatBox( no_connect_sql_message ) else local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) if( query )> 2 then playerState = 1 ---Theres a character created else playerState = 0 ---The player is new end if (playerState == 1) then triggerEvent("spawnTheCharacter", getRootElement(), theUser) ---spawn the character previously created elseif (playerstate == 0) then triggerClientEvent("move1", getRootElement()) ---move the camera to the character creation section end end end I have tried it and it doesn't work...however I am also begining to question my "spawnTheCharacter" function as well that is function spawnTheCharacter(theUser) local playerName = getPlayerName (theUser) local spawnChar = mysql_query(connect_mysql, "SELECT * FROM `players` WHERE `saveX`, `saveY`, `saveZ` WHERE `charName`='"..playerName.."'") if (spawnChar) == nil then outputChatBox("error") else spawnPlayer (theUser, spawnChar) end end If someone could help me out I'd really appreciate it. Thanks Everyone Link to comment
Remp Posted August 11, 2010 Share Posted August 11, 2010 your query isn't going to be returning a plain integer, so you cant just compare it with 2 you probably want to use this to count the rows first: https://wiki.multitheftauto.com/wiki/Modules/MTA- ... l_num_rows local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) if mysql_num_rows(query) > 2 then ... i would also suggest you make playerState local, it wont cause any real problems being global but it isnt very neat Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 still doesn't work....I added some outputDebugString and still can't find an error Link to comment
Remp Posted August 11, 2010 Share Posted August 11, 2010 what do you debug outputs tell you? where is it having trouble? post your new code and what it outputs when you run it Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 playerState = 0 function changeTheButton(theUser) if( not connect_mysql ) then outputChatBox( no_connect_sql_message ) else local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) if mysql_num_rows(query) > 2 then playerState = 1 ---Theres a character created outputDebugString ("theres a created character") else playerState = 0 ---The player is new outputDebugString ("no user data") end if (playerState == 1) then triggerEvent("spawnTheCharacter", getRootElement(), theUser) outputDebugString ("the data is loaded") elseif (playerstate == 0) then triggerClientEvent("move1", getRootElement()) outputDebugString ("move to create a char") end end end addEvent ("changeTheButton", true) addEventHandler ("changeTheButton", getRootElement(), changeTheButton) it tells me "no user data" which is treating me like I am a new player.....but in the MySQL db all my account information is properly logged in there so it shouldn't be treating me as if I just created an account. It doesn't even send me to the character creation page either (move1). I have been stumped for hours now. Link to comment
The_Ex Posted August 11, 2010 Share Posted August 11, 2010 Shouldn't it be if mysql_num_rows(query)== 1 then ? Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 I've tried that and other configurations but it still doesn't change that the script thinks my character is nonexistent.... Just tried it with if mysql_num_rows(query)== 1 then still gives the same error Link to comment
Remp Posted August 11, 2010 Share Posted August 11, 2010 try outputting tostring(mysql_num_rows(query)) to see what it is Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 isn't that what I did when using "theres a character created"? If not how would I set that up? perhaps... local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) if mysql_num_rows(query)== 1 outputDebugString {"blah blah blah") then playerState = 1 ---Theres a character created outputDebugString ("theres a created character") else playerState = 0 ---The player is new outputDebugString ("no user data") end Link to comment
Remp Posted August 11, 2010 Share Posted August 11, 2010 i mean to output the exact value, not just see if it equals something: local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) outputDebugString("Result: "..tostring(mysql_num_rows(query))) if mysql_num_rows(query) > 2 then ... Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 thank you and Result: 0 so this means nothings coming back at all... Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 okay im going to break it down... the client side function to call my serverside function function button() triggerServerEvent("changeTheButton", getRootElement(), getLocalPlayer()) end triggered by gui click current code playerState = 0 function changeTheButton(theUser) if( not connect_mysql ) then outputChatBox( no_connect_sql_message ) else local query = mysql_query( connect_mysql, "SELECT * FROM `players` WHERE charName='" .. getPlayerName( theUser ) .. "'" ) outputDebugString("Result: "..tostring(mysql_num_rows(query))) if mysql_num_rows(query)== 1 then playerState = 1 ---Theres a character created outputDebugString ("theres a created character") else playerState = 0 ---The player is new outputDebugString ("no user data") end if (playerState == 1) then triggerEvent("spawnTheCharacter", getRootElement(), theUser) outputDebugString ("the data is loaded") elseif (playerstate == 0) then triggerClientEvent("move1", getRootElement()) outputDebugString ("move to create a char") end end end addEvent ("changeTheButton", true) addEventHandler ("changeTheButton", getRootElement(), changeTheButton) should be working don't know why it isn't Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 anyone? sorry if i appear to be annoying but this is driving me crazy lol Link to comment
Remp Posted August 11, 2010 Share Posted August 11, 2010 if mysql_num_rows(query) is 0 then there is something wrong with your query id guess there is no character with that name (even if your table had no other data it should still return 1 row with the charName in) are you sure 'theUser' is a player? if it is, try using an sql viewer to look at the database Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 ohhhh I see the problem..."theUser" is the local player so it would give the account name so right now when my function is called it is giving the account name rather than the char name....if that makes sence I will try to fix it now and post my resaults Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 yeah that was my problem...I needed to search for the account not the players name lol so simple....but now it doesn't spawn me which brings me back to my spawn script ^^ edit wait no never mind now if they register it says they have a character created without acually making one....an account and a character are different Link to comment
trajik Posted August 11, 2010 Author Share Posted August 11, 2010 should I be using this instead? table mysql_fetch_field ( MySQLResult result ) Link to comment
The_Ex Posted August 12, 2010 Share Posted August 12, 2010 Why bother using that playerState variable? if mysql_num_rows(query)== 1 then triggerEvent("spawnTheCharacter", getRootElement(), theUser) outputDebugString ("the data is loaded") else triggerClientEvent("move1", getRootElement()) outputDebugString ("move to create a char") end Link to comment
trajik Posted August 12, 2010 Author Share Posted August 12, 2010 that's not the issue though... In my database I have it set up like this: mySQL database Roleplayer: Players: account - password - charName - ect.... now I have it set up so it looks at the account and retrieves the charName table to check if the account has a character. Am i doing it right or do I need a whole new code? That's my problem thanks in advance Link to comment
trajik Posted August 12, 2010 Author Share Posted August 12, 2010 bump cant anyone help me? Link to comment
50p Posted August 13, 2010 Share Posted August 13, 2010 ...mySQL database Roleplayer: Players: account - password - charName - ect.... ... What's this? Link to comment
dzek (varez) Posted August 13, 2010 Share Posted August 13, 2010 looks like weird "dump" of db structure. Link to comment
trajik Posted August 13, 2010 Author Share Posted August 13, 2010 That's just the basic structure of my db...the one used in the usersystem resource EDIT: I basically need a script that looks at one table getting the local players name then checking if it's in the database and if it is then it looks back into the database for a character...if the account has a character then it spawns it If not it sends the player to the character creation screen..so how could this be done what steps do I take? NOTE from 50p: Is it so hard to hit edit button? Link to comment
50p Posted August 13, 2010 Share Posted August 13, 2010 Check if your query with ' instead of ` will work. 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