Jump to content

What should be the problem?


Clydian

Recommended Posts

function givePlayerBadge(thePlayer, commandName, targetPlayer, ... ) 
    local badgeNumber = table.concat( { ... }, " " ) 
    badgeNumber = #badgeNumber > 0 and badgeNumber 
    local theTeam = getPlayerTeam(thePlayer) 
    local teamID = getElementData(theTeam, "id") 
     
    local badge = nil 
    local itemID = nil 
    local prefix = "" 
    for k, v in pairs(badges) do 
        for ka, va in pairs(v[3]) do 
            if ka == teamID then 
                badge = v 
                itemID = k 
                prefix = type(va) == "string" and ( va .. " " ) or "" 
            end 
        end 
    end 
    if not badge then return end 
     
    local leader = getElementData(thePlayer, "factionleader") 
     
    if not (tonumber(leader)==1) then 
        outputChatBox("You must be a faction leader to issue badges.", thePlayer, 255, 0, 0) 
    else 
        if not targetPlayer or not badgeNumber then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Player Partial Nick / ID] [badge Number]", thePlayer, 255, 194, 14) 
        else 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, targetPlayer) 
            if targetPlayer then 
                local targetPlayerName = targetPlayerName:gsub("_", " ") 
                local logged = getElementData(targetPlayer, "loggedin") 
                if (logged==0) then 
                    outputChatBox("Player is not logged in.", thePlayer, 255, 0, 0) 
                else 
                    local x, y, z = getElementPosition(thePlayer) 
                    local tx, ty, tz = getElementPosition(targetPlayer) 
                    if (getDistanceBetweenPoints3D(x, y, z, tx, ty, tz)>4) then 
                        outputChatBox("You are too far away to issue this player a badge.", thePlayer, 255, 0, 0) 
                    else 
                        exports.global:sendLocalMeAction(thePlayer, "issues "..targetPlayerName.." " .. badge[2] .. ", reading " .. badgeNumber .. ".") 
                        exports.global:giveItem(targetPlayer, itemID, prefix .. badgeNumber) 
                    end 
                end 
            end 
        end 
    end 
end 
addCommandHandler("issuebadge", givePlayerBadge, false, false) 

Has anybodey have any ideas why this doesnt work?

Edited by Guest
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...