Chaos Posted August 22, 2014 Share Posted August 22, 2014 hey, i'm creating team system but i'm wondering how can i make invite command like when i invite player then he will got you have been invite to gang type /agree to join and when he typed agree will got output you joined function invite( player, cmd, target) local target = getPlayerFromNamePart ( target ) if target then outputChatBox("you have invited to red team type /agree to join !",target) end end function getPlayerFromNamePart(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 Link to comment
Anubhav Posted August 22, 2014 Share Posted August 22, 2014 function invite( player, cmd, target) local target = getPlayerFromNamePart ( target ) if target then outputChatBox("You have been invited to: "..getElementData( player, "gangData" ).. ", use /agree to accept. You have 15 seconds!",target) -- please replace gangData with the group of player. 'Element data' which you use to get player group. setElementData(target, "latestInvite", getElementData( player, "gangData" ) ) addCommandHandler("agree", agree) setTimer(removeElementData, 15000, 1, target, "gangData") end end function agree(source, commandName) local data = getElementData(source, 'lastestInvite') if data then setPlayerGroup(source, data) end end function getPlayerFromNamePart(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 Link to comment
Chaos Posted August 22, 2014 Author Share Posted August 22, 2014 It worked thanks but i got another problem when player created team and when he quit other players can create same team name and by the way i used setaccountdata and getaccountdata to save team on account. is there a way to fix that ? Link to comment
Anubhav Posted August 22, 2014 Share Posted August 22, 2014 No problem. Whenever you create a group it should go in database like SQL or MySQL. Then when someone else creates you can just check. Some guide tho: con = dbConnect("sql", "group.db") -- It will create group.db automatically and you will be connected to the file. addEventHandler("onResourceStart", root, function() dbExec(con, "CREATE TABLE IF NOT EXISTS groupTable(group TEXT)") -- This will create a table if t doesn't exist with column GROUP which contains TEXT only. end ) dbExec(con, "INSERT INTO groupTable group=? VALUES(?)", "some group name") -- This will insert "some group name" to a table named groupTable. You can edit the first dbExec which was creating table. Just add more columns. Google for database types! Then you should put columnName=? VALUES(?,?,?). In VALUES you'll question marks which means how many columns are there in the table. dbExec(con, "UPDATE groupTable SET group=? ", "myGroupNameChanged!") -- this will update the column group and change its value to "myGroupNameChanged!". local query = dbQuery(con, "SELECT * FROM groupTable") -- This will select every column from groupTable. * means every column. You can make it one column too. Don't use dbExec for this thing please. dbPoll(query, 0) -- We want the result now, and it should be instead. Don't use -1 because it will freeze the server. You can just use these functions and account data, it will make it SO EASY! Link to comment
Chaos Posted August 23, 2014 Author Share Posted August 23, 2014 I want easy way than using mysql and sqlite because i never worked on these functions Before Link to comment
Chaos Posted August 23, 2014 Author Share Posted August 23, 2014 i need simple example table for this part function createTm(player, commandName, teamName) local acc = getPlayerAccount(player) if isGuestAccount ( acc ) then outputChatBox("You must login first !",player,255,0,0) end if getAccountData(acc,"histeam") then outputChatBox("You already have team !",player,255,0,0) end if not teamName then outputChatBox("Please Write valid name usage /ct teamname !",player,255,0,0) end if acc and not isGuestAccount ( acc ) and not getAccountData(acc,"histeam") and teamName then Team = createTeam(teamName) if Team then outputChatBox("Team created successfully !",player,0,255,0) setAccountData(acc,"histeam",getTeamName ( Team )) setPlayerTeam(player,Team) else outputChatBox("Failed to create team !",player,255,0,0) end end end addCommandHandler("ct",createTm) Link to comment
Anubhav Posted August 23, 2014 Share Posted August 23, 2014 tableName = {} function createTm(player, commandName, teamName) local acc = getPlayerAccount(player) if isGuestAccount ( acc ) then outputChatBox("You must login first !",player,255,0,0) return end if getAccountData(acc,"histeam") then outputChatBox("You already have team !",player,255,0,0) return end for k,v in ipairs(tableName) do if v == teamName then outputChatBox("Team exists.", player, 255, 0, 0) return end end if not teamName then outputChatBox("Please Write valid name usage /ct teamname !",player,255,0,0) return end if acc and not isGuestAccount ( acc ) and not getAccountData(acc,"histeam") and teamName then Team = createTeam(teamName) if Team then outputChatBox("Team created successfully !",player,0,255,0) table.insert(tableName, teamName) setAccountData(acc,"histeam",getTeamName ( Team )) setPlayerTeam(player,Team) else outputChatBox("Failed to create team !",player,255,0,0) end end end addCommandHandler("ct",createTm) Link to comment
Chaos Posted August 23, 2014 Author Share Posted August 23, 2014 Thank you but i don think table will save teams when i restart resource Link to comment
Anubhav Posted August 23, 2014 Share Posted August 23, 2014 I know. Thats why I told MySQL/SQL. Link to comment
Chaos Posted August 23, 2014 Author Share Posted August 23, 2014 But how castillo did it with gang system with out these functions Link to comment
Anubhav Posted August 23, 2014 Share Posted August 23, 2014 He must use account-date in a proper way.. I am not sure contact him. Link to comment
Castillo Posted August 23, 2014 Share Posted August 23, 2014 No, I used 100% SQLite on my released gang system. Link to comment
Chaos Posted August 23, 2014 Author Share Posted August 23, 2014 Only this way can do that? Link to comment
Castillo Posted August 23, 2014 Share Posted August 23, 2014 Use a table to store the invitations. Link to comment
Anubhav Posted August 23, 2014 Share Posted August 23, 2014 Only this way can do that? Just add me on skype, anubhav.agarwal87. I'll make you learn SQLite, 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