Jump to content

findPlayer


Bleidex

Recommended Posts

Posted

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 

Posted

I am not sure, because i am new, but I think findPlayer is not defined.

Or what should the "findPlayer" command do?

Currently working on gamemodes :

  • Reallife Script 70%
  • Breakout Script 10%
Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

proracer, he doesn't want that if i'm right, he just wanted it to warn the desired player.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I know him he is my friend, he wanted to use the partial name for a player.. I didn't said you're code is wrong, on the contrary it's good.

Like for example: /warn Sol - (instead of Solidsnake14) which must be used with getPlayerFromName

Posted

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 
  

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