Jump to content

invite


Chaos

Recommended Posts

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
  
  
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

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

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

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
  
    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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...