Jump to content

Warn players [help]


zzx

Recommended Posts

addCommandHandler ("warn", 
function (player, cmd, playername) 
if playername then 
who = getPlayerFromName(playername) 
outputChatBox ("WARN: You have been warned", who, 255, 0, 0) 
else 
outputChatBox ("info: write - warn playername in f8", player, 255, 255, 0) 
end 
end) 
Link to comment
Stop this Sam.

I don't even know who you are.

Learn to respect others, I was going to help you but my opinions changed. I didn't start anything which I should stop but you don't know how to respect others. Saying things like "Fix it for me", this shows that you are commanding us and I'm not a kind of person who would say "OK boss, I fixed it. No problem". :|

Link to comment

I highly suggest you read a few tutorials about how scripting works. You have a ton of errors in your code.

This should work;

function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function warnPlayer_CMD(thePlayer, theCMD, theTarget, ...) 
    if(theTarget ~= nil) then 
        local theTargetElement = getPlayerFromNamePart(theTarget) 
        if(getElementType(theTargetElement) == "player") then 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            outputChatBox("[WARN]: "..getPlayerName(thePlayer).."#FF0000 has warned "..getPlayerName(theTargetElement).."#FF0000!", getRootElement(), 255, 0, 0, true) 
            outputChatBox("[WARN]: Reason: #FF2626("..tostring(theReason)..")", getRootElement(), 255, 0, 0, true) 
        else 
            outputChatBox("[WARN]: Invalid target! Syntax: /warn [Player] [Reason]", thePlayer, 255, 0, 0, true) 
        end 
    end 
end 
addCommandHandler("warn", warnPlayer_CMD, false) 

Link to comment
How to make the accessible to the command only for staff, moderators, admins, supermoderators and consoles guys? :|

You can either check for every group with this

if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then 

or you can simply use

if (hasObjectPermissionTo(source, "function.kickPlayer", false)) then 

Link to comment

I'm very sorry Sam.

If someone is ready to apologize then I've nothing against him anymore. I apologize for getting little bit harsh there.

Use:

  
function getPlayerFromNamePart(name) 
  
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
  
    if name then 
  
        for _, player in ipairs(getElementsByType("player")) do 
  
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
  
            if name_:find(name, 1, true) then 
  
                return player 
  
            end 
  
        end 
  
    end 
  
end 
  
  
  
function warnPlayer_CMD(thePlayer, theCMD, theTarget, ...) 
 local accN = getAccountName ( getPlayerAccount (thePlayer) ) 
local groupName = "Admin" or "Moderator" or "SuperModerator" -- you can add more 
if groupName then 
    if theTarget ~= nil and isObjectInACLGroup ("user."..accN,aclGetGroup (groupName) then 
  
        local theTargetElement = getPlayerFromNamePart(theTarget) 
  
        if(getElementType(theTargetElement) == "player") then 
  
            local allArgs = {...} 
  
            local theReason = table.concat(allArgs, " ") 
  
            outputChatBox("[WARN]: "..getPlayerName(thePlayer).."#FF0000 has warned "..getPlayerName(theTargetElement).."#FF0000!", getRootElement(), 255, 0, 0, true) 
  
            outputChatBox("[WARN]: Reason: #FF2626("..tostring(theReason)..")", getRootElement(), 255, 0, 0, true) 
  
        else 
  
            outputChatBox("[WARN]: Invalid target! Syntax: /warn [Player] [Reason]", thePlayer, 255, 0, 0, true) 
              end 
        end 
  
    end 
  
end 
  
addCommandHandler("warn", warnPlayer_CMD, false) 

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