Forum

> > CS2D > Scripts > Add killcount with saycommands
Forums overviewCS2D overview Scripts overviewLog in to reply

English Add killcount with saycommands

25 replies
Page
To the start Previous 1 2 Next To the start

old Add killcount with saycommands

Alistaire
User Off Offline

Quote
How can I make a script like;

1
2
3
4
5
6
7
8
addhook("say","MM.commands")
function MM.commands(id,message)
	if player(usgn)=adminlist then
		if MM.commands(message)="!kc "..id.." "..kcplus.."" then
			player(id,killcount)=kcplus
		end
	end
end

I mean like:

If the name is on the adminlist, check what the message is. If the message is something like "!killcount *id* *ammount*" then give *id* *ammount* killcount.

Is that possible / do you have a better solution?

old Re: Add killcount with saycommands

Alistaire
User Off Offline

Quote
Only the killcount. I have a script for the killcount.

----

Atm I'm this far:

1
2
3
4
5
addhook("say","MM.commands")
function MM.commands(id,message)
	if player(id,"usgn")==21737 then
		if (txt=="
		return 1;

old Re: Add killcount with saycommands

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
addhook("say","MM.commands")
function MM.commands(id,message)
    for _,u in pairs(adminlist) do
        if player(usgn)==u then
            if message:sub(1,2)=="!kc" then
                if player(tonumber(message:sub(4,5)),"exists") then
                    killcount[tonumber(message:sub(4,5))]=killcount[tonumber(message:sub(4,5))]+tonumber(message:sub(6))
                end
            end
        end
    end
end

Now, when you say !kc 1 50, 50 points will be added to player #1's killcount. Change the names of the killcount and the admin list and whatnot, but I hope you get the general idea. Also, the script is untabbed. Sorry.

old Re: Add killcount with saycommands

Alistaire
User Off Offline

Quote
And another thing;

I've added a killcount for every single class, so I can add a killcount meter later on.

How do I change the script to different killcounts; like

"!rc id killcount killcountnmbr"

?

old Re: Add killcount with saycommands

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function initArray2(f,v)
local array={}
for c=1,f do
array[c]=v
end
return array
end

killcount=initArray2(32,initArray2(9,0))

addhook("say","MM.commands")
function MM.commands(id,message)
for _,u in pairs(adminlist) do
if player(usgn)==u then
if message:sub(1,2)=="!kc" then
if player(tonumber(message:sub(4,5)),"exists") then
killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]=killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]+tonumber(message:sub(9))
end
end
end
end
end

If I got that right. So now, killcount[id][classid] is the killcount. !kc id class number - is the command now.

old Re: Add killcount with saycommands

Alistaire
User Off Offline

Quote
It's like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("kill","MM.killcount")
function MM.killcount(id)
	if MM.class[id]==1 then
		fragcount1[id]=fragcount1[id]+1
	elseif MM.class[id]==2 then
		fragcount2[id]=fragcount2[id]+1
	elseif MM.class[id]==3 then
		fragcount3[id]=fragcount3[id]+1	
	elseif MM.class[id]==4 then
		fragcount4[id]=fragcount4[id]+1	
	elseif MM.class[id]==5 then
		fragcount5[id]=fragcount5[id]+1	
	elseif MM.class[id]==6 then
		fragcount6[id]=fragcount6[id]+1
	elseif MM.class[id]==7 then
		fragcount7[id]=fragcount7[id]+1	
	end
end

I meant fragcount..

----

It has to be like !kc "id" "fragcount" "fragcountnumber"

!kc 1 50 1

(Add 50 fragcount for cavalry class to ID 1)

----

Sry sry sry if you didn't understand *-*

old Re: Add killcount with saycommands

EngiN33R
Moderator Off Offline

Quote
user Alistaire has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("kill","MM.killcount")
function MM.killcount(id)
	if MM.class[id]==1 then
		fragcount1[id]=fragcount1[id]+1
	elseif MM.class[id]==2 then
		fragcount2[id]=fragcount2[id]+1
	elseif MM.class[id]==3 then
		fragcount3[id]=fragcount3[id]+1	
	elseif MM.class[id]==4 then
		fragcount4[id]=fragcount4[id]+1	
	elseif MM.class[id]==5 then
		fragcount5[id]=fragcount5[id]+1	
	elseif MM.class[id]==6 then
		fragcount6[id]=fragcount6[id]+1
	elseif MM.class[id]==7 then
		fragcount7[id]=fragcount7[id]+1	
	end
end


This code is horrendous.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function initArray2(f,v)
local array={}
for c=1,f do
array[c]=v
end
return array
end

adminlist={1,21737}
fragcount=initArray2(32,initArray2(7,0))

addhook("kill","MM.killcount")
function MM.killcount(id)
	fragcount[id][MM.class[id]]=fragcount[id][MM.class[id]]+1
end

addhook("say","MM.commands")
function MM.commands(id,message)
	for _,u in pairs(adminlist) do
		if player(usgn)==u then
			if message:sub(1,2)=="!kc" then
				if player(tonumber(message:sub(4,5)),"exists") then
					killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]=killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]+tonumber(message:sub(9))
				end
			end
		end
	end
end

That part of the code, fully done (in my mind).

old Re: Add killcount with saycommands

Alistaire
User Off Offline

Quote
user EngiN33R has written
Did you replace your existing hooks with the hooks I gave?


Lua Error has written
[16:27:28] LUA ERROR: sys/lua/medieval modEngy.lua:463: bad argument #1 to 'player' (number expected, got nil)
[16:27:28] [H.H]Cuchulainn: !kc 1 1 50


1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","MM.commands")
 function MM.commands(id,message)
      for _,u in pairs(adminlist) do
--Line 463
           if player(usgn)==u then
                if message:sub(1,2)=="!kc" then
                     if player(tonumber(message:sub(4,5)),"exists") then
                          killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]=killcount[tonumber(message:sub(4,5))][tonumber(message:sub(6,8))]+tonumber(message:sub(9))
                     end
                end
           end
      end
 end

old Re: Add killcount with saycommands

Alistaire
User Off Offline

Quote
Another thing;

1
2
3
4
function MM.killcount(id)
--Line 47
	fragcount[id][MM.class[id]]=fragcount[id][MM.class[id]]+1
end

has an error:

Lua Error has written
[16:49:18] LUA ERROR: sys/lua/medieval modEngy.lua:47: attempt to perform arithmetic on field '?' (a nil value)

old Re: Add killcount with saycommands

EngiN33R
Moderator Off Offline

Quote
Change the line
1
if message:sub(1,2)=="!kc" then
to
1
if message:sub(1,3)=="!kc" then

I was stupid. Let's see if that fixes the problem.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview