tim260 Posted January 7, 2012 Share Posted January 7, 2012 first off this script is a mess i know because i dont understand. What im trying to do is creating a table with roles defined to each user and output them in the dxscoreboard. But i cant let it work and if someone has time is there an way to do like : /addrole tim260 role, and when you do that it writes it in the table. this is what i got ( doesnt work and doesnt create table it sucks ) call(getResourceFromName("dxscoreboard"), "addScoreboardColumn", "Role", getRootElement(), 8, 0.07)function getan() local players = getElementsByType ( "player" ) executeSQLCreateTable("Roles-test", "Role TEXT,Username TEXT" ) result = executeSQLSelect ( "Roles-test", "Role" ) setElementData ( thePlayer, "Role", "ddd" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), getan ) Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 You're using account names or player names? if player names, then that's really useless, because most of the players keeps changing their nick constantly. Link to comment
tim260 Posted January 7, 2012 Author Share Posted January 7, 2012 You're using account names or player names? if player names, then that's really useless, because most of the players keeps changing their nick constantly. account names ofc EDIT: but like i sad i dont understand the sql functions and events Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 function getan() call(getResourceFromName("dxscoreboard"), "addScoreboardColumn", "Role", getRootElement(), 8, 0.07) executeSQLCreateTable("Roles", "Username STRING, Role STRING" ) end addEventHandler ( "onResourceStart", resourceRoot, getan ) function addUserIfNotExists(username, role) local checkUser = executeSQLSelect ( "Roles", "Username", "Username = '" .. tostring(username) .. "'" ) if ( type( checkUser ) == "table" and #checkUser == 0 or not checkUser ) then return executeSQLInsert ( "Roles", "'".. tostring(username) .."','".. tostring(role) .."'" ) end end function getAccountRole(username) local checkUser = executeSQLSelect ( "Roles", "*", "Username = '" .. tostring(username) .. "'" ) if ( type( checkUser ) == "table" and #checkUser == 0 or not checkUser ) then return "None" else return tostring(checkUser[1]["Role"]) end end addCommandHandler("addrole", function (thePlayer, cmd, username, role) if addUserIfNotExists(username, role) then outputChatBox("/addrole : Added Username: ".. tostring(username) ..", Role: ".. tostring(role) ..".",thePlayer,0,255,0) end end) addEventHandler("onPlayerLogin",root, function (_,account) local accountName = getAccountName(account) local role = getAccountRole(accountName) setElementData(source,"Role",role) end) The table couldn't be created because of the "-" in it's name. Link to comment
tim260 Posted January 7, 2012 Author Share Posted January 7, 2012 function getan() call(getResourceFromName("dxscoreboard"), "addScoreboardColumn", "Role", getRootElement(), 8, 0.07) executeSQLCreateTable("Roles", "Username STRING, Role STRING" ) end addEventHandler ( "onResourceStart", resourceRoot, getan ) function addUserIfNotExists(username, role) local checkUser = executeSQLSelect ( "Roles", "Username", "Username = '" .. tostring(username) .. "'" ) if ( type( checkUser ) == "table" and #checkUser == 0 or not checkUser ) then return executeSQLInsert ( "Roles", "'".. tostring(username) .."','".. tostring(role) .."'" ) end end function getAccountRole(username) local checkUser = executeSQLSelect ( "Roles", "*", "Username = '" .. tostring(username) .. "'" ) if ( type( checkUser ) == "table" and #checkUser == 0 or not checkUser ) then return "None" else return tostring(checkUser[1]["Role"]) end end addCommandHandler("addrole", function (thePlayer, cmd, username, role) if addUserIfNotExists(username, role) then outputChatBox("/addrole : Added Username: ".. tostring(username) ..", Role: ".. tostring(role) ..".",thePlayer,0,255,0) end end) addEventHandler("onPlayerLogin",root, function (_,account) local accountName = getAccountName(account) local role = getAccountRole(accountName) setElementData(source,"Role",role) end) The table couldn't be created because of the "-" in it's name. thanks but one more thing how can i make the with higher because when i type something long i cant read the whole thing EDIT : SOLVED EDIT 2 : is it true you can only edit the role once ? Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 What do you mean by edit the role once? you can query as many times as you want. P.S: That script will just ADD a new value to the table, it won't update an already existing value. 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