Forum

> > CS2D > Scripts > msg2 after admin check.. flood
Forums overviewCS2D overview Scripts overviewLog in to reply

English msg2 after admin check.. flood

13 replies
To the start Previous 1 Next To the start

old msg2 after admin check.. flood

The Camo
User Off Offline

Quote
Any idea why doesn't this work properly?
1
2
3
if (player(id,"usgn")==ha[hu])==false then
msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
end;

It has one "end" before it where all commands are working, this one does too though, but it floods the server .. lags for 1 secs and floods after that, as if it loads it 100 times ><.. any idea of what I did wrong or whats going on?

old Re: msg2 after admin check.. flood

Yasday
User Off Offline

Quote
1
2
3
4
5
local bl = false
if (player(id,"usgn")==ha[hu])==false and bl == false then
	msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
	bl = true
end

old Re: msg2 after admin check.. flood

EngiN33R
Moderator Off Offline

Quote
@Yasday,
Just a little tip, instead of
1
if (player(id,"usgn")==ha[hu])==false
use
1
if not (player(id,"usgn")==ha[hu])
or
1
if (player(id,"usgn")~=ha[hu])

old Re: msg2 after admin check.. flood

The Camo
User Off Offline

Quote
Nah, still the same thing, maybe my system is shi**y, it should have worked ether way, even without false/true check, it just bugs at that last part of the lua, well, I don't really need it that much now that I saw that my USGN doesn't work on online servers... only when I host the server over "new game"

Anyway, thanks for the help..

old Re: msg2 after admin check.. flood

The Camo
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
addhook ("say","sayscript")
function sayscript(id,txt)
 for i=1,32 do
  for hu = 1,10 do
  local ha = { 7235 }
   if player(id,"usgn")==ha[hu] then
   ...
   else
   ...
   end <-- After this end every command starts to flood.. (its latest info I can give after testing many variations)
   if player(id,"usgn")~=ha[hu] then
   msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!");end;end;end;end

old Re: msg2 after admin check.. flood

Yasday
User Off Offline

Quote
1
2
3
4
if player(id,"usgn")~=ha[hu] then
msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
break
end

old Re: msg2 after admin check.. flood

The Camo
User Off Offline

Quote
It still floods the chat, although it doesn't lag it when flooding, so I guess it helps a little.

Anyway, I figured out that when I have any of this samples/scripts(whit mine ofc) that it:
When I type anything it shows the msg as if it skips
1
if player(id,"usgn")~=ha[hu] then

But...
It checks ha[hu] and if false it will proceed with msg without thinking about other scripts... (I need to make the table of this admin commands[!kick !ban !slay !slap !freeze...etc.] so it works properly)

I made cmdtbl table for commands that are in my "arsenal" it helps more then I expected, I may still be able to live with flood, it also reduced amount of msgs flood did to "10" so far, for it to work perfectly I'd have to ask again, is there anything else I missed out, 10 msgs have to do with something I did..

Only code with 1,10 is:
1
for hu = 1,10 do

1
2
3
4
5
6
local cmdtbl= { "!kick","!ban","!slay","!slap","!freeze","!unfreeze" }
for b=1,6 do
if (txt==cmdtbl[b].." "..i) and player(id,"usgn")~=ha[hu] then
msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
break
end;end

Here is the new img of the rest of my problem..

P.s. for those that are wondering how I test this admin checking script: its simple, I just delete last character in my usgn name (So I get failed to log in)

Anyway thanks so much for answers so far
And sorry if I didn't explain my situation correctly, I didn't know what was going on..

old Re: msg2 after admin check.. flood

DannyDeth
User Off Offline

Quote
Here the problem lies with the fact that you have a couple for loops running amock in your code!

If you have a for loop within a for loop, it will loop through the thing the first times the second, in your case: 32 * 10, which means your code is looping through there 320 times!
Then you have the
1
local ha = { 7235 }
in that loop! This means that you are defining it 320 times!!

This is what will cause bad lag, also, using local from inside a function will mean only that function can see it, not the ones contained in it! So it will go on forever because of this! And lastly, They are all for NOTHING!!!

Here is the code I believe will work out your problem:
1
2
3
4
5
6
7
8
9
10
ha = { 7235 }
admin_cmds = { "!ban", "!INSERT_MORE!" }
addhook ("say","sayscript")
function sayscript(id,txt)
	if ha[player(id,"usgn")] and admin_cmds[txt] then
		...
	else
	msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
	end
end

EDIT: I am going to fix the rest for you quickly...

EDIT2:
1
2
3
4
5
6
7
8
9
10
ha = { 7235 }
admin_cmds = { "!ban", "!INSERT_MORE!" }
addhook ("say","sayscript")
function sayscript(id,txt)
	if ha[player(id,"usgn")] and admin_cmds[txt] then
		... --<O>-- Do your banning ( etc ) stuff here --<O>--
	else
		msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
	end
end
I do believe it is correct, however I cannot be 100% sure
edited 1×, last 24.01.11 02:23:52 pm

old Re: msg2 after admin check.. flood

Banaan
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
function contains(table,x)
	for _, v in pairs(table) do if v == x then return true end end
	return false
end

local cmdtbl= { "!kick","!ban","!slay","!slap","!freeze","!unfreeze" }
for b=1,6 do
if (txt:match(cmdtbl[b].." %d+") and ha:contains(player(id,"usgn"))==false then
msg2(id,"©150150150 You don't have Admin privileges therefore you cannot use Admin commands!")
break
end;end

old Re: msg2 after admin check.. flood

The Camo
User Off Offline

Quote
DannyDeth's solution worked the best,

While learning to script I did know I could make table out of the function, but I didn't know how (And couldn't find tut anywhere) so this helped a lot and will help me in the future,

Although I didn't copy all, I knew what was wrong with your help. I had too many stuff like..
for vu=1,30 do
for hu=1,10 do
for i=1,32 do
and too many local stuff in the script..

I only left "for i=1,32 do" since commands need to target players (well, most of them so far)

It also helps whole script to checks admins since now it checks them by ID's when they say the command,
The way I did it (Bugged way) I could only have 10 admins or/and 30 vips..

Thanks a lot, I really appreciate the feedback that you provided me.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview