R.y.c.k Posted July 14, 2012 Posted July 14, 2012 How to create command /lu - 'Lucky ! """"""" how to add this feature ? example: Ern€st: /lu AnTO_on and in chat see Ern€st #5dacd1 say: Lucky AnTO_on ! function luck(player, cmd) if (not restriction[player]) then restriction[player] = {} end if not restriction[player][cmd] then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) else outputChatBox("#FF0000You must wait #FFFFFF5 seconds#FF0000 to write this command again.", player, 255, 255, 255, true) end end addCommandHandler("lu", luck)
Vision Posted July 14, 2012 Posted July 14, 2012 (edited) restriction = {} function luck(player, cmd, who) if (not restriction[player]) then restriction[player] = {} end if not restriction[player][cmd] then local target = getPlayerFromName ( who ) if target ~= false then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky "..getPlayerName(target).."!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FF0000You must wait #FFFFFF5 seconds#FF0000 to write this command again.", player, 255, 255, 255, true) end end addCommandHandler("lu", luck) Edited July 14, 2012 by Guest
R.y.c.k Posted July 14, 2012 Author Posted July 14, 2012 hmm problem in line 2 attempt to index global 'restriction' a nil vaule
Guest Guest4401 Posted July 14, 2012 Posted July 14, 2012 Add this in the very first line of your script local restriction = {}
R.y.c.k Posted July 14, 2012 Author Posted July 14, 2012 I write and nothing ..... i must write fully name also hex code ?
Guest Guest4401 Posted July 14, 2012 Posted July 14, 2012 6: Bad argument @ 'getPlayerFromName' You should type /lu But you typed /lu or The script is clientsided, but it should be serversided.
MIKI785 Posted July 14, 2012 Posted July 14, 2012 The easiest solution is that you stop using someone else's scripts and you start to learn Lua properly.
R.y.c.k Posted July 14, 2012 Author Posted July 14, 2012 This is my script ... and i dont know how to write players name ...
R.y.c.k Posted July 14, 2012 Author Posted July 14, 2012 I have script in server side i write /lu -[sAM]-R.y.c.k and nothing
Cadu12 Posted July 14, 2012 Posted July 14, 2012 (edited) restriction = {} function luck(player, cmd, who) if (not restriction[player]) then restriction[player] = {} end if not restriction[player][cmd] then if tostring(who) then local target = getPlayerFromName ( who ) if target then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky "..getPlayerName(target).."!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FF0000You must wait #FFFFFF5 seconds#FF0000 to write this command again.", player, 255, 255, 255, true) end end addCommandHandler("lu", luck) Nick with colors wont work, you have to make your own getPlayerFromName. Edited July 14, 2012 by Guest
R.y.c.k Posted July 14, 2012 Author Posted July 14, 2012 <meta> <info description="Commnads" author="unknown" type="script" version="1.0.0"/> <script src="commands.lua" type="server" /> </meta>
Vision Posted July 14, 2012 Posted July 14, 2012 try this restriction = {} function luck(player, cmd, who) if (not restriction[player]) then restriction[player] = {} end if not restriction[player][cmd] then local target = getPlayerFromName ( who ) if target ~= false then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky "..getPlayerName(target).."!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) elseif not target then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FF0000You must wait #FFFFFF5 seconds#FF0000 to write this command again.", player, 255, 255, 255, true) end end addCommandHandler("lu", luck)
Cadu12 Posted July 14, 2012 Posted July 14, 2012 restriction = {} function findPlayer(namepart) for i, player in ipairs(getElementsByType("player")) do local name = getPlayerName(player) local name2 = string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "") if string.find(name:lower(), namepart:lower(), 1, true) then return player, name elseif string.find(name2:lower(), namepart:lower(), 1, true) then return player, name end end return false end function luck(player, cmd, who) if (not restriction[player]) then restriction[player] = {} end if not restriction[player][cmd] then if who then local target = findPlayer ( who ) if target then outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky "..getPlayerName(target).."!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FFFFFF".. getPlayerName(player) .."#5DACD1 say: Lucky!", root, 255, 255, 255, true) restriction[player][cmd] = true setTimer(function () restriction[player][cmd] = false end, 5000, 1) end else outputChatBox("#FF0000You must wait #FFFFFF5 seconds#FF0000 to write this command again.", player, 255, 255, 255, true) end end addCommandHandler("lu", luck)
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