MitnickP56 Posted February 7, 2016 Posted February 7, 2016 Hi I have code for alias player, When I type /pma -- doesn't work. addEventHandler("onResourceStart", resourceRoot, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS `players` (`serial` TEXT, `mute` TEXT, `alias` TEXT)") end ) addEventHandler("onPlayerJoin", root, function() local serial = getPlayerSerial(source) local name = getPlayerName(source) local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) if #r == 0 then executeSQLQuery("INSERT INTO `players` (`serial`,`mute`,`alias`) VALUES(?,?,?)", serial, "no", name) else if r[1]["mute"] == "yes" then setPlayerMuted(source, true) outputChatBox(name:gsub("#%x%x%x%x%x%x", "").." has been muted by Console!", root, 255, 0, 0, true) end end end ) addEventHandler("onPlayerQuit", root, function() if isPlayerMuted(source) then else end end ) addEventHandler("onPlayerJoin", root, function() setAlias(source) end ) addEventHandler("onPlayerChangeNick", root, function() setTimer(setAlias, 100, 1, source) end ) function setAlias(source) local find = true local name = getPlayerName(source) local serial = getPlayerSerial(source) local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) for i,v in ipairs(split(r[1]['alias'], 32)) do if v == name then find = false end end if find then executeSQLQuery("UPDATE `players` SET `mute`=?, `alias`=? WHERE `serial`=?", r[1]["mute"], r[1]["alias"].." "..name, serial) end end function findPlayer(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end local alias1 = "" local alias2 = 0 addCommandHandler("pma", function(p, _, t) local target = findPlayer(t) if target then local serial = getPlayerSerial(target) local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) local spl = split(r[1]["alias"], 32) for i, v in ipairs(spl) do if alias1 == "" then alias1 = v alias2 = alias2 + 1 else alias1 = alias1..", "..v alias2 = alias2 + 1 end if i == #spl then outputChatBox(alias1, p, 255, 255, 255, true) alias1 = "" alias2 = 0 end end end end ) Debugscript;
tosfera Posted February 8, 2016 Posted February 8, 2016 As stated on the wiki: Returns a table with the result of the query if it was a SELECT query, or false if otherwise. In case of a SELECT query the result table may be empty (if there are no result rows)..
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