Forum

> > CS2D > General > Lua, About "walkover"
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Lua, About "walkover"

8 replies
To the start Previous 1 Next To the start

old Lua, About "walkover"

Flacko
User Off Offline

Quote
Hi, I'm working in a small mod in lua and I was wondering how can I let the players be able to pick up Flags, also, how do i use the "iid" parameter in the walkover hook?
I was trying to do something like this:
1
2
3
4
5
6
7
addhook("walkover","flacko.gg.walkover")
function flacko.gg.walkover(id,iid,type)
	if (iid == 71 or iid == 70) then
		return 0
        else return 1
	end
end
But it didn't work

old Re: Lua, About "walkover"

Lee
Moderator Off Offline

Quote
don't use iid since they are the unique ID, use type instead (if type == 71 or type == 70)

old Re: Lua, About "walkover"

Flacko
User Off Offline

Quote
Ohhh I see...
Now I have this:
1
2
3
4
5
6
7
8
9
addhook("walkover","flacko.gg.walkover")
function flacko.gg.walkover(id,iid,type)
	if (type == 71 or type == 70 or type >= 64 and type <= 68) then
		return 0
      else 
      return 1
      
	end
end
Now players can pick up flags, health and money
Thx lee!

EDIT: Now, i want to let the admin to set a player's level, for example, in console, the admin would write:
gg_setlevel [PLAYER ID] [LEVEL]
But I don't know how to make lua do this
edited 2×, last 05.04.09 07:25:06 pm

old Re: Lua, About "walkover"

Lee
Moderator Off Offline

Quote
you mean on my GunGame? I think the command is @gg_setlevel id level after you've logged into the user system

Here's my code for it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function gg.setlevel(p, level, b)
	if level > gg.maxlvl then
		level = gg.maxlvl
		msg("©128000255"..player(p, "name").." Is The Winner@C")
		parse("map "..game("nextmap"))
	end
	if level < gg.minlvl then level = gg.minlvl end

	gg.players[p].level = level
	gg.players[p].kills = 0

	strip(p, 0)
	parse("equip "..p.. " "..gg.wpnlvl[level].wpn_id)

	msg("Player \""..player(p, "name").."\" is now on level "..level)
end

old Re: Lua, About "walkover"

Flacko
User Off Offline

Quote
Well, actually, I'm making my own gungame, and I want the thing to get the numbers I input on console commands.
For example, my gungame accepts this two commands:

1
2
3
4
5
6
7
8
9
10
11
12
addhook("parse","flacko.gg.parse")
function flacko.gg.parse(cmd)
   if(cmd=="gg_levelup-") then
           flacko.gg.killstolevelup=flacko.gg.killstolevelup-1
           print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
           return 2 end

   if(cmd=="gg_levelup+") then
           flacko.gg.killstolevelup=flacko.gg.killstolevelup+1
           print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
           return 2 end
end

so, I have to write in console "gg_levelup+" or "gg_levelup-" to adjust the number of kills needed to level up.
And I want to, somehow, be able to write in console "gg_levelup 5" to set the number of kills needed to level up to 5

old Re: Lua, About "walkover"

Lee
Moderator Off Offline

Quote
Flacko has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("parse","flacko.gg.parse")
function flacko.gg.parse(cmd)
	if(cmd=="gg_levelup-") then
		flacko.gg.killstolevelup=flacko.gg.killstolevelup-1
		print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
		return 2 
	end

	if(cmd=="gg_levelup+") then
		flacko.gg.killstolevelup=flacko.gg.killstolevelup+1
		print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
		return 2 
	end
end

And I want to, somehow, be able to write in console "gg_levelup 5" to set the number of kills needed to level up to 5


For this, I will introduce a pseudo split function (which can either split on spaces, magic characters, or any delimitor passed in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function split(t, b)
	return toTable(t, b)
end

function toTable(t, b)
	local cmd = {}
	local match = "[^%s]+"
	if b then
		match = "%w+"
	end
	if type(b) == "string" then match = "[^"..b.."]+" end
	if not t then return invalid() end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

so here's let's make it a bit easier for us.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("parse","flacko.gg.parse")
function flacko.gg.parse(cmd)
	local str = split(cmd)
	local cmdtype = str[1]
	
	if (cmdtype=="gg_levelup-") then
		flacko.gg.killstolevelup=flacko.gg.killstolevelup-1
		print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
		return 2
	end

	if (cmdtype=="gg_levelup+") then
		flacko.gg.killstolevelup=flacko.gg.killstolevelup+1
		print("©255255000 Kills to level up = "..(flacko.gg.killstolevelup))
			return 2
	end
	
	if cmdtype == "gg_levelup" then
		flacko.gg.killstolevelup = tonumber(str[2])
	end
end

So here's the changes I made

1
2
3
4
5
6
7
8
local str = split(cmd)
	local cmdtype = str[1]

	---------------------------

	if cmdtype == "gg_levelup" then
		flacko.gg.killstolevelup = tonumber(str[2])
	end
here, if you parse "gg_levelup 5", the function will proceed as follows:
1) It'll create a new table called str from the split cmd, which splits the string based on the spaces, so you'll get a table with:
1
{"gg_levelup", "5"}
-^- Note: The 5 is a string, not a number here.
2) It'll create a new string called cmdtype that takes the first element of the table str, so cmdtype == "gg_levelup"
3) Since cmdtype does equal "gg_levelup", we go to the code
1
flacko.gg.killstolevelup = tonumber(str[2])
, which makes the number flacko.gg.killstolevelup = to the number version of the second element of the table str, so in this case, 5.

Hope this helps

old Re: Lua, About "walkover"

Flacko
User Off Offline

Quote
cool!
It works 10/10!

I've also added this command:

1
2
3
4
if (cmdtype == "gg_setlevel") then
          flacko.gg.level[tonumber(str[2])] = tonumber(str[3])
          return 2
     end

To set someone's level
edited 1×, last 06.04.09 01:54:31 am

old Re: Lua, About "walkover"

Flacko
User Off Offline

Quote
Zune5 has written
Didn't you want someone just to pick up a flag or something?


Yes, i did, but I didn't wanted to make another thread, so I edited my 2nd post in this thread.
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview