Jump to content

Warn players [help]


zzx

Recommended Posts

Posted

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) 
Posted
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". :|

Posted

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) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

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

Posted
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 

Posted (edited)

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
Posted

I did a type there at line 30. Just replace line 30 with this

  if theTarget ~= nil and isObjectInACLGroup ("user."..accN,aclGetGroup (groupName) ) then -- missing bracket  

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