Bleidex Posted May 21, 2011 Share Posted May 21, 2011 Hello, i'm making new script, but im disturbed by problem, that i can't fix 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
BriGhtx3 Posted May 21, 2011 Share Posted May 21, 2011 I am not sure, because i am new, but I think findPlayer is not defined. Or what should the "findPlayer" command do? Link to comment
Maccer. Posted May 21, 2011 Share Posted May 21, 2011 According to the error, the function findPlayer does not exist. Why are you trying to use it? Link to comment
Castillo Posted May 22, 2011 Share Posted May 22, 2011 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
proracer Posted May 22, 2011 Share Posted May 22, 2011 I know this script, its used to get partial name of a player... try briefly looking into ban/kick system.It has a partial name for target player afaik. Link to comment
Castillo Posted May 22, 2011 Share Posted May 22, 2011 proracer, he doesn't want that if i'm right, he just wanted it to warn the desired player. Link to comment
proracer Posted May 22, 2011 Share Posted May 22, 2011 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 Link to comment
karlis Posted May 22, 2011 Share Posted May 22, 2011 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now