Jump to content

findPlayer


Bleidex

Recommended Posts

Hello, i'm making new script, but im disturbed by problem, that i can't fix :S

ERROR: line 4 attempt to call global 'findPlayer' (a nil value)

Command I use: /warn Figa test

I was testing it on player which nicks was #0080FFFiga. Tried on others too but returned same problem. ;/

function warnPlayer ( theClient, command, target, reason) 
  if ( hasObjectPermissionTo ( theClient, "function.warnPlayer" ) ) then 
    local warnedPlayer = getPlayerFromNick ( target ) 
        local targetPlayer = findPlayer ( target ) 
    local playerAccount = getPlayerAccount ( targetPlayer ) 
    local playerWarns = getAccountData ( playerAccount, "Warns" ) or 0 
    if ( playerWarns == 0 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF0000 has been warned for " ..reason.. ".", getRootElement(), 255, 0, 0, true ) 
        outputChatBox ( "You have been warned for " ..reason.. ". Now you have " ..playerWarns.. " of 3.", targetPlayer, 255, 0, 0, false ) 
    elseif ( playerWarns == 1 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF000 has been warned for " ..reason.. ".", getRootElement(), 255, 0, 0, true ) 
        outputChatBox ( "You have been warned for " ..reason.. ". Now you have " ..playerWarns.. " of 3.", targetPlayer, 255, 0, 0, false ) 
    elseif ( playerWarns == 2 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF000 has been warned for " ..reason.. ". It was his last moment in this server...", getRootElement(), 255, 0, 0, true ) 
        banPlayer ( targetPlayer, Console, "You got 3 warning of 3." ) 
    end 
  else 
    outputChatBox ( "Warn: you don't have enough permissions.", theClient, 255, 255, 0, false ) 
  end 
end 

Link to comment

Sounds like the script is not yours, else, you should have the 'findPlayer' function ;)

function warnPlayer ( theClient, command, target, reason) 
  if ( hasObjectPermissionTo ( theClient, "function.warnPlayer" ) ) then 
    local targetPlayer = getPlayerFromName ( target ) 
    local playerAccount = getPlayerAccount ( targetPlayer ) 
    local playerWarns = getAccountData ( playerAccount, "Warns" ) or 0 
    if ( playerWarns == 0 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF0000 has been warned for " ..reason.. ".", getRootElement(), 255, 0, 0, true ) 
        outputChatBox ( "You have been warned for " ..reason.. ". Now you have " ..playerWarns.. " of 3.", targetPlayer, 255, 0, 0, false ) 
    elseif ( playerWarns == 1 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF000 has been warned for " ..reason.. ".", getRootElement(), 255, 0, 0, true ) 
        outputChatBox ( "You have been warned for " ..reason.. ". Now you have " ..playerWarns.. " of 3.", targetPlayer, 255, 0, 0, false ) 
    elseif ( playerWarns == 2 ) then 
        setAccountData ( playerAccount, "Warns", tonumber(playerWarns) + 1 ) 
        outputChatBox ( warnedPlayer.. "#FF000 has been warned for " ..reason.. ". It was his last moment in this server...", getRootElement(), 255, 0, 0, true ) 
        banPlayer ( targetPlayer, Console, "You got 3 warning of 3." ) 
    end 
  else 
    outputChatBox ( "Warn: you don't have enough permissions.", theClient, 255, 255, 0, false ) 
  end 
end 

Link to comment

returns false if more then 1 player found, player, if 1 found, nil, if none found

  
function findPlayer(nickpart) 
  local players=getElementsByType("player") 
  local matches={} 
  for _,v in pairs(players) do 
    if string.find(string.lower(getPlayerName(v)),string.lower(nickpart)) then 
      table.insert(matches,v) 
    end 
 end 
 if #mathces>1 then 
   return false 
 else  
   return mathces[1] 
 end 
end 
  

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