Castillo Posted July 25, 2010 Share Posted July 25, 2010 (edited) hey there, im trying to make that if i type /reac it will just output a random word like LaRz2 and save it somewhere then when i type in chat that word it should output a message that i won... but dunno why dosnt work, here is my code so far, Edited August 9, 2010 by Guest Link to comment
50p Posted July 25, 2010 Share Posted July 25, 2010 Why do you expect it to generate string with 5 characters if you only want it to generate string with 1 or 2 characters? Make a separate function for generating string. Also, is the string going to be the same for everyone? If so, why don't you make a global variable? function generateRandomString( charsCount ) local str = ""; for i = 1, charsCount do local c = string.char( math.random( 100, 122 ) ); if i % 2 == 1 then c = string.upper( c ); end str = str .. c; end return str; end addCommandHandler( "reac", function( _, _, count ) WIN_WORD = generateRandomString( tonumber( count ) or 5 ); -- eg. "/reac 6" to generate 6 characters string outputChatBox("Reaction: Type '".. WIN_WORD .."' if u want to win $10000",getRootElement(),0,255,0); end, true -- restricted for admins only (you'll need to update ACL to restrict it) ); addEventHandler( "onPlayerChat", getRootElement(), function( msg, msgType ) if msgType == 0 then if WIN_WORD and msg == WIN_WORD then WIN_WORD = nil; outputChatBox( getPlayerName( source ) .. " has won $10000 for quick reflex!", getRootElement(), 0, 255, 0 ); givePlayerMoney( source, 10000 ); end end end ) Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 all works fine like i wanted, thanks. just one problem that dosnt matter cause worked when i deleted somthing, this dosnt works like that O_o addCommandHandler( "reac", function( _, _, count ) WIN_WORD = generateRandomString( tonumber( count ) or 5 ); -- eg. "/reac 6" to generate 6 characters string outputChatBox("Reaction: Type '".. WIN_WORD .."' if u want to win $10000",getRootElement(),0,255,0); end, true -- restricted for admins only (you'll need to update ACL to restrict it) ); but works like this, addCommandHandler( "reac", function( _, _, count ) WIN_WORD = generateRandomString( tonumber( count ) or 5 ); -- eg. "/reac 6" to generate 6 characters string outputChatBox("Reaction: Type '".. WIN_WORD .."' if u want to win $10000",getRootElement(),0,255,0); end ); Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 Do you think I'd put a comment on that line without any reason? Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 Do you think I'd put a comment on that line without any reason? what i did its added the resource to acl group admins... Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 Do you think I'd put a comment on that line without any reason? what i did its added the resource to acl group admins... Why resource if it's player who is using this command? Check ACL again and see how other commands are blocked in "Default" and unblocked in "Admin". Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 (edited) Do you think I'd put a comment on that line without any reason? what i did its added the resource to acl group admins... Why resource if it's player who is using this command? Check ACL again and see how other commands are blocked in "Default" and unblocked in "Admin". actually ive done that too.. Edit: nevermind i suposed this would work with the new acl group i added, sorry. Edited July 26, 2010 by Guest Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 ...actually ive done that too.. But this is not all. Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 ...actually ive done that too.. But this is not all. sorry, i logged as acl group admin and worked, problem was that i added a new acl group which has different powers. Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 (edited) . Edited August 9, 2010 by Guest Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 Because your setTimer is set to repeat itself over and over again until you stop it (killTimer). Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 (edited) . Edited August 9, 2010 by Guest Link to comment
Castillo Posted July 26, 2010 Author Share Posted July 26, 2010 Why don't you test? actually i did it but it works just once the timer. Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 Why don't you test? actually i did it but it works just once the timer. "once the timer" what? You made your life so complicated... You have so many different variables from setTimer's... What's the point if you need only 1 timer at a time? Line 3: Why do you still have that timer set to repeat over and over again if you kill it later in the script? Line 3: Why do you assign new value to start if you have function with the same name? It overrides your function which disables your script after first call. Line 16: What's the point for _, _, in the parameters list if you don't attach this function to a command like I did before? BTW, 5 mins is not 500000ms... calculate it again and think over your script again. You made your life much harder. 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