Jump to content

Command


TorNix~|nR

Recommended Posts

Hello guys, I want some help with this command code please, it won't work

like this: /kills 'accountname' 'amount'

function isPlayerInACL(thePlayer, acl)
    local account = getPlayerAccount(thePlayer)
    if (account) and not (isGuestAccount(account)) then
        local aclGroup = aclGetGroup(acl)
        if (aclGroup) then
            local accountName = getAccountName(account)
            return isObjectInACLGroup("user."..accountName, aclGroup)
        end
    end
    return false
end

addCommandHandler("kills",
function (thePlayer, _, account, amount)   
    if (isPlayerInACL(thePlayer, "Admin")) and (tonumber(amount)) then
		local account = getPlayerAccount(player)
    	local player = getAccountName(account)
    	if (player) then
			if (setElementData(player, "kills", tonumber(amount))) then
				if (account) then setAccountData(account,"kills", tonumber(amount)) end
				outputChatBox("done", thePlayer, 0, 0, 255)
			else
				outputChatBox("failed", thePlayer, 255, 0, 0)
			end
		else
			outputChatBox("account not found", thePlayer, 255, 0, 0)
    	end
    end
end) 

 

Edited by TorNix~|nR
Link to comment

I guess you want to make a function which sets the number of kills of an account you type in the command ?
 

addCommandHandler("kills",
function (thePlayer, _, account, amount)   
    if (isPlayerInACL(thePlayer, "Admin")) and (tonumber(amount)) then
        local targetAccount = getAccount(account)
        if (targetAccount) then
            if (account) then
                setAccountData(account,"kills", tonumber(amount)) end
                outputChatBox("done", thePlayer, 0, 0, 255)
            else
                outputChatBox("failed", thePlayer, 255, 0, 0)
            end
        else
            outputChatBox("account not found", thePlayer, 255, 0, 0)
        end
    end
end)

 

Edited by SpecT
Link to comment

Oops I made some mistakes ?
This should work:

addCommandHandler("kills",
function (thePlayer, _, account, amount)   
    if (isPlayerInACL(thePlayer, "Admin")) and (tonumber(amount)) then
        local targetAccount = getAccount(account)
        if (targetAccount) then
            if (setAccountData(targetAccount,"kills", tonumber(amount))) then
                outputChatBox("done", thePlayer, 0, 0, 255)
            else
                outputChatBox("failed", thePlayer, 255, 0, 0)
            end
        else
            outputChatBox("account not found", thePlayer, 255, 0, 0)
        end
    end
end)

 

  • Thanks 1
Link to comment

It depends how the player gets the kills count information.
If it's with getElementData then this should update it immediately.
 

addCommandHandler("kills",
function (thePlayer, _, account, amount)   
    if (isPlayerInACL(thePlayer, "Admin")) and (tonumber(amount)) then
        local targetAccount = getAccount(account)
        local targetPlayer = getAccountPlayer(targetAccount)
        if (targetAccount) then
            if (setAccountData(targetAccount,"kills", tonumber(amount))) then
                if targetPlayer then -- If there is a player logged into the account
                    setElementData(targetPlayer, "kills", tonumber(amount))
                end
                outputChatBox("done", thePlayer, 0, 0, 255)
            else
                outputChatBox("failed", thePlayer, 255, 0, 0)
            end
        else
            outputChatBox("account not found", thePlayer, 255, 0, 0)
        end
    end
end)

 

  • Thanks 1
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...