Mann56 Posted May 28, 2015 Share Posted May 28, 2015 Hey guys here i am making my first resource and i need help i am stuck at a line 3 function addGroup (thePlayer,cmd,groupByName) if thePlayer then local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?)", "'" .. tostring(gangName) .. "'" ) dbPoll (qh,0) outputChatBox("Group System : You successfully created group : " "".. tostring(groupByName) .."" ,client,255,255,0) setElementData(root,"groupName", ..tostring(groupByName).. ) else outputChatBox("Invalid syntax. Syntax is /creategroup ",255,255,0) end end it says in debugscript that loading script failed ')' expected at """ Please help Link to comment
ALw7sH Posted May 28, 2015 Share Posted May 28, 2015 To be honest it's like you get random lines from random scripts or something and put them in one script function addGroup (thePlayer,cmd,groupByName) if thePlayer then local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?)",tostring(gangName)) dbPoll (qh,0) outputChatBox("Group System : You successfully created group : " "".. tostring(groupByName) .."" ,thePlayer,255,255,0) setElementData(thePlayer,"groupName", tostring(groupByName) ) else outputChatBox("Invalid syntax. Syntax is /creategroup ",thePlayer,255,255,0) end end Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 it says in debugscript that loading script failed ')' expected at """ Please help Use dbExec instead of dbQuery Link to comment
Mann56 Posted May 28, 2015 Author Share Posted May 28, 2015 To be honest it's like you get random lines from random scripts or something and put them in one script I found that sqlite line from dayz group panel . I was making sqlite for first time so didn't want to mess up :< it says in debugscript that loading script failed ')' expected at """ Please help Use dbExec instead of dbQuery What is the difference between them? Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 What is the difference between them? if you don't know nothing about db functions i recommend you to read this dbConnect dbExec dbQuery dbPoll dbFree Link to comment
Mann56 Posted May 28, 2015 Author Share Posted May 28, 2015 I read them. I saw executeSQLQuery but it didn't go with custom Db's So i used dbQuery instead . You mean dbExec executes the query? Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 I read them. I saw executeSQLQuery but it didn't go with custom Db's So i used dbQuery instead . You mean dbExec executes the query? Post full code here Link to comment
Mann56 Posted May 28, 2015 Author Share Posted May 28, 2015 Well it's in three files here group_commands[server] -- Create a Gang function addGroup (thePlayer,cmd,groupByName) local player = isPedInVehicle(thePlayer) if player then outputChatBox("Can't make a group inside a vehicle!",client,255,255,0) elseif groupByName then local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?)", "'" .. tostring(gangName) .. "'" ) dbPoll (qh,0) outputChatBox("Group System : You successfully created group : " "".. tostring(groupByName) .."" ,client,255,255,0) setElementData(root,"groupName", ..tostring(groupByName).. ) else outputChatBox("Invalid syntax. Syntax is /creategroup ",255,255,0) end end groups.lua [server] connect = dbConnect("sqlite","groups.db") if connect then outputDebugString("connectionn Success") end c_groups.lua [client] -- The main gui and the client core of the resource local groupName = getElementData(localPlayer,"groupName") tab = {} scrollpane = {} combo = {} scroll = {} window = {} grid = {} button = {} edit = {} label = {} memo = {} addEventHandler("onClientResourceStart", resourceRoot, function() window.Group = guiCreateWindow(0.25, 0.15, 0.50, 0.65, "Group System", true) guiWindowSetMovable(window.Group, false) guiWindowSetSizable(window.Group, false) tabPanel = guiCreateTabPanel(0.05, 0.22, 0.91, 0.74, true, window.Group) tab.Tab = guiCreateTab("Group Info", tabPanel) label.groupName = guiCreateLabel(0.05, 0.04, 0.88, 0.18,"" .. tostring(groupName) .. "", true, tab.Tab) guiSetFont(label.groupName, "sa-header") guiLabelSetHorizontalAlign(label.groupName, "center", false) guiLabelSetVerticalAlign(label.groupName, "center") label.MembersInfo = guiCreateLabel(0.07, 0.28, 0.42, 0.13, "Members : ", true, tab.Tab) guiSetFont(label.MembersInfo, "clear-normal") guiLabelSetHorizontalAlign(label.MembersInfo, "center", false) guiLabelSetVerticalAlign(label.MembersInfo, "center") label.MoneyInfo = guiCreateLabel(0.51, 0.29, 0.37, 0.12, "Money : ", true, tab.Tab) guiSetFont(label.MoneyInfo, "clear-normal") guiLabelSetHorizontalAlign(label.MoneyInfo, "center", false) guiLabelSetVerticalAlign(label.MoneyInfo, "center") label.BaseInfo = guiCreateLabel(0.08, 0.82, 0.83, 0.13, "Base : ", true, tab.Tab) guiSetFont(label.BaseInfo, "clear-normal") guiLabelSetHorizontalAlign(label.BaseInfo, "center", false) guiLabelSetVerticalAlign(label.BaseInfo, "center") button.setMotdInfo = guiCreateButton(0.34, 0.72, 0.30, 0.07, "Set MOTD", true, tab.Tab) guiSetProperty(button.setMotdInfo, "NormalTextColour", "FFAAAAAA") label.MotdInfo = guiCreateLabel(0.19, 0.45, 0.57, 0.04, "Message of the Day (MOTD)", true, tab.Tab) guiLabelSetHorizontalAlign(label.MotdInfo, "center", false) guiLabelSetVerticalAlign(label.MotdInfo, "center") memo.motd = guiCreateMemo(0.13, 0.53, 0.70, 0.16, "", true, tab.Tab) tab.Members = guiCreateTab("Members", tabPanel) scrollpane.getOnlinePlayers = guiCreateScrollPane(0.56, 0.02, 0.41, 0.80, true, tab.Members) grid.onlinePlayers = guiCreateGridList(0.00, 0.00, 1.00, 1.00, true, scrollpane.getOnlinePlayers) guiGridListAddColumn(grid.onlinePlayers, "Name", 0.9) scroll.onlinePlayers = guiCreateScrollBar(0.88, 0.12, 0.06, 0.83, false, true, grid.onlinePlayers) button.Invite = guiCreateButton(0.59, 0.87, 0.34, 0.08, "Invite Player", true, tab.Members) guiSetProperty(button.Invite, "NormalTextColour", "FFAAAAAA") scrollpane.members = guiCreateScrollPane(11, 7, 303, 276, false, tab.Members) grid.membersGroup = guiCreateGridList(0.00, 0.00, 1.00, 1.00, true, scrollpane.members) guiGridListAddColumn(grid.membersGroup, "Name", 0.5) guiGridListAddColumn(grid.membersGroup, "Rank", 0.5) scroll.mem = guiCreateScrollBar(0.88, 0.10, 0.07, 0.82, false, true, grid.membersGroup) label.setRank = guiCreateLabel(0.03, 0.88, 0.18, 0.06, "Set Member Rank : ", true, tab.Members) combo.setRank = guiCreateComboBox(0.23, 0.87, 0.11, 0.09, "", true, tab.Members) guiComboBoxAddItem(combo.setRank, "1") guiComboBoxAddItem(combo.setRank, "2") guiComboBoxAddItem(combo.setRank, "3") guiComboBoxAddItem(combo.setRank, "4") guiComboBoxAddItem(combo.setRank, "5") tab.rules = guiCreateTab("Rules", tabPanel) memo.rules = guiCreateMemo(0.02, 0.02, 0.96, 0.86, "", true, tab.rules) button.editRules = guiCreateButton(0.36, 0.89, 0.28, 0.08, "Edit Rules", true, tab.rules) guiSetProperty(button.editRules, "NormalTextColour", "FFAAAAAA") tab.settings = guiCreateTab("Settings", tabPanel) label.warn = guiCreateLabel(0.08, 0.04, 0.87, 0.05, "Note : Only the set group skin is available for group members the rest settings are for leader only!", true, tab.settings) guiLabelSetHorizontalAlign(label.warn, "center", false) guiLabelSetVerticalAlign(label.warn, "center") button.setskin = guiCreateButton(0.35, 0.14, 0.30, 0.10, "Set Group Skin", true, tab.settings) guiSetProperty(button.setskin, "NormalTextColour", "FFAAAAAA") label.playerMotdRank = guiCreateLabel(0.09, 0.32, 0.32, 0.06, "Player rank required to edit MOTD :", true, tab.settings) combo.setMotd = guiCreateComboBox(0.41, 0.30, 0.09, 0.07, "", true, tab.settings) guiComboBoxAddItem(combo.setMotd, "1") guiComboBoxAddItem(combo.setMotd, "2") guiComboBoxAddItem(combo.setMotd, "3") guiComboBoxAddItem(combo.setMotd, "4") guiComboBoxAddItem(combo.setMotd, "5") label.setPlayerAddMoneyRank = guiCreateLabel(0.09, 0.40, 0.40, 0.04, "Player rank required to add money in group :", true, tab.settings) combo.AddMoneyRank = guiCreateComboBox(0.49, 0.40, 0.09, 0.06, "", true, tab.settings) guiComboBoxAddItem(combo.AddMoneyRank, "1") guiComboBoxAddItem(combo.AddMoneyRank, "2") guiComboBoxAddItem(combo.AddMoneyRank, "3") guiComboBoxAddItem(combo.AddMoneyRank, "4") guiComboBoxAddItem(combo.AddMoneyRank, "5") label.takeMoney = guiCreateLabel(0.09, 0.51, 0.47, 0.04, "Player rank required to withdraw money from group : ", true, tab.settings) combo.takeMoney = guiCreateComboBox(0.57, 0.50, 0.09, 0.07, "", true, tab.settings) guiComboBoxAddItem(combo.takeMoney, "1") guiComboBoxAddItem(combo.takeMoney, "2") guiComboBoxAddItem(combo.takeMoney, "3") guiComboBoxAddItem(combo.takeMoney, "4") guiComboBoxAddItem(combo.takeMoney, "5") button.leaveGroup = guiCreateButton(0.37, 0.67, 0.29, 0.12, "Leave Group", true, tab.settings) guiSetProperty(button.leaveGroup, "NormalTextColour", "FFAAAAAA") button.deleteGroup = guiCreateButton(0.37, 0.84, 0.29, 0.12, "Delete Group", true, tab.settings) guiSetProperty(button.deleteGroup, "NormalTextColour", "FFAAAAAA") tab.money = guiCreateTab("Money", tabPanel) label.groupMoney = guiCreateLabel(0.31, 0.02, 0.34, 0.10, "Group Money", true, tab.money) guiLabelSetHorizontalAlign(label.groupMoney, "center", false) guiLabelSetVerticalAlign(label.groupMoney, "center") label.showMoney = guiCreateLabel(131, 49, 340, 109, "", false, tab.money) edit.addMoney = guiCreateEdit(0.06, 0.76, 0.28, 0.09, "", true, tab.money) button.addMoney = guiCreateButton(0.06, 0.89, 0.28, 0.07, "Add Money", true, tab.money) guiSetProperty(button.addMoney, "NormalTextColour", "FFAAAAAA") edit.takeMoney = guiCreateEdit(0.68, 0.76, 0.28, 0.10, "", true, tab.money) button.takeMoney = guiCreateButton(0.68, 0.88, 0.28, 0.07, "Withdraw Money", true, tab.money) guiSetProperty(button.takeMoney, "NormalTextColour", "FFAAAAAA") label.MainName = guiCreateLabel(0.05, 0.06, 0.91, 0.15,"" .. tostring(groupName) .."" , true, window.Group) guiSetFont(label.MainName, "sa-header") guiLabelSetHorizontalAlign(label.MainName, "center", false) guiLabelSetVerticalAlign(label.MainName, "center") end ) addEventHandler("onCLientResourceStart",resourceRoot, function () triggerServerEvent("createGroup",source) end ) -- This will spawn when someone decides to leave thwe group! button = {} window = {} label = {} addEventHandler("onClientResourceStart", resourceRoot, function() window.leaveGroup = guiCreateWindow(0.30, 0.21, 0.40, 0.48, "", true) guiWindowSetMovable(window.leaveGroup, false) guiWindowSetSizable(window.leaveGroup, false) guiSetAlpha(window.leaveGroup, 0.82) label.leaveGroup = guiCreateLabel(0.04, 0.10, 0.92, 0.10, "Are you sure you want to leave the group?", true, window.leaveGroup) guiLabelSetHorizontalAlign(label.leaveGroup, "center", false) button.leaveGroup = guiCreateButton(0.26, 0.33, 0.50, 0.19, "Yes", true, window.leaveGroup) guiSetProperty(button.leaveGroup, "NormalTextColour", "FFAAAAAA") button.stay = guiCreateButton(0.26, 0.63, 0.50, 0.16, "No", true, window.leaveGroup) guiSetProperty(button.stay, "NormalTextColour", "FFAAAAAA") end ) -- THis will give warning when deleting group button = {} window = {} label = {} addEventHandler("onClientResourceStart", resourceRoot, function() window.deleteGroup = guiCreateWindow(0.33, 0.28, 0.36, 0.39, "", true) guiWindowSetMovable(window.deleteGroup, false) guiWindowSetSizable(window.deleteGroup, false) label.deleteGroup = guiCreateLabel(0.02, 0.09, 0.96, 0.14, "Are you sure you want to delete the group!!!", true, window.deleteGroup) guiLabelSetHorizontalAlign(label.deleteGroup, "center", false) guiLabelSetVerticalAlign(label.deleteGroup, "center") button.deleteGroup = guiCreateButton(0.29, 0.36, 0.42, 0.17, "Yes", true, window.deleteGroup) guiSetProperty(button.deleteGroup, "NormalTextColour", "FFAAAAAA") button.donotDelete = guiCreateButton(0.30, 0.63, 0.41, 0.18, "No", true, window.deleteGroup) guiSetProperty(button.donotDelete, "NormalTextColour", "FFAAAAAA") end ) I have just started with the resource. Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 First of all You need to create the table like this Example on resource start function YourFunction() dbExec(connection, "CREATE TABLE IF NOT EXISTS YourTableName (column1 TEXT, column2 TEXT, etc .....)") end addEventHandler("onResourceStart", resourceRoot, YourFunction) Link to comment
Mann56 Posted May 28, 2015 Author Share Posted May 28, 2015 First of all You need to create the table like this Example on resource start function YourFunction() dbExec(connection, "CREATE TABLE IF NOT EXISTS YourTableName (column1 TEXT, column2 TEXT, etc .....)") end addEventHandler("onResourceStart", resourceRoot, YourFunction) Ah thanks so i must create a table before executing query But... is anything wrong in this line? local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?)", "'" .. tostring(groupByName) .. "'" ) Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?)", "'" .. tostring(groupByName) .. "'" ) yep it should be like this local check = dbPoll(dbQuery(connection, "SELECT * FROM YourTableName WHERE ExampleGangName = ?",tostring(groupByName)), -1) if type(check) == "table" and #check == 0 or not check then dbExec(connection, "INSERT INTO YourTableName VALUES (?)",tostring(groupByName)) end Link to comment
Mann56 Posted May 28, 2015 Author Share Posted May 28, 2015 Thanks dude but why to freeze server everytime it executes the query? Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 Thanks dude but why to freeze server everytime it executes the query? try to use the The LIMIT keyword like this local check = dbPoll(dbQuery(connection, "SELECT * FROM YourTableName WHERE ExampleGangName =' ?' LIMIT 1" ,tostring(groupByName)), -1) The LIMIT keyword in a SQL query let you specify how much rows you want to get at most. 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