Forum

> > CS2D > Scripts > Table class, message to team, array explanation
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Table class, message to team, array explanation

10 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Table class, message to team, array explanation

Ace Howl
User Off Offline

Zitieren
Hi there.

How do I:

1. group weapon as weapon class (I need explanation)
1
2
3
4
5
6
7
8
9
10
weapon.primary = {10,11,20,..,24,30,..,49,90,91}
weapon.secondary = {1,..6}

function hitplayer(id,weapon,source)
	if source == weapon.primary then
		parse("flashplayer "..id.." 10")
	elseif source == weapon.secondary then
		parse("flashplayer "..id.." 5")
	end
end

2. proceed if in the list
1
2
3
4
5
usgn.list = {66153,109296,44801}

if usgn.list then
	proceed()
end

3. temporarily slowed upon hit
1
2
3
4
5
6
7
8
9
function hitplayer2(id,weapon)
	if weapon == weapon.primary then
		parse("speedmod "..id.." -10")
		timer(100,.. ? ..)
	elseif weapon == weapon.secondary then
		parse("speedmod "..id.." -5")
		timer (200,.. ? ..)
	end
end

4. message visible to a team only
1
msg(team1,"You must kill Counter-Terrorists.")

5. Array explanation (sorry, I forgot it although was told understood)
1
2
3
4
5
6
7
function initArray(m)	-- what is m?
	local array = {}
	for i = 1, m do 	-- what is i? does it related to (m)?
		array[i]=0	-- ??
	end
	return array		-- what?
end

Note: Question 1 and 3 are same thing, but separated. This is to ease you for solution findings.

That's the only questions I want to ask, for now.

alt Re: Table class, message to team, array explanation

Cure Pikachu
User Off Offline

Zitieren
Q1 >

Q2 >

Q3 >

Q4 >

5. It creates a table with m entries, each with 0 as their values. So
1
2
test = initArray(5)
-- is the same as test = {0,0,0,0,0}
And if you search deep enough, you find this too:
user ohaz, thread cs2d Lua Scripts/Questions/Help hat geschrieben
it creates an array with 'm' zeros.
so that you can create a 0 for every player on the server!
if now a player joins he has 0, you can now assign him another number. (like the class he choses)
1× editiert, zuletzt 23.01.16 11:13:04

alt Re: Table class, message to team, array explanation

Dousea
User Off Offline

Zitieren
For question 2, I suggest you to use ipairs since it iterates over numerical indexes orderly, which means faster, but the speed will not be noticed anyway. And a fix for user Cure Pikachu's answer.
1
2
3
4
5
6
7
local usgnlist = {66153, 109296, 44801}

for index, usgn in ipairs(usgnlist) do
	if (player(id,"usgn") == usgn) then
		-- Proceed here!
	end
end

For question 3, a better method of user Cure Pikachu's answer, by using local.
1
2
3
4
5
6
7
8
9
10
11
function hitplayer2(id, source, weapon)
	local speedmod = player(id, "speedmod") -- Get their original speed first
	
	if (itemtype(weapon, "slot") == 1) then
		parse("speedmod " .. id .. " -10")
		timer (100, "parse", "speedmod " .. id .. " " .. speedmod)
	elseif (itemtype(weapon, "slot") == 2) then
		parse("speedmod " .. id .. " -5")
		timer (200, "parse", "speedmod " .. id .. " " .. speedmod)
	end
end

For question 4, here is the code. It's not error-safe.
1
2
3
4
5
6
7
function msg3(team, message, living)
	local string = "team" .. team .. (living and "living" or "")
	
	for index, id in ipairs(player(0, string)) do
		msg2(id, message)
	end
end

alt Re: Table class, message to team, array explanation

Bowlinghead
User Off Offline

Zitieren
If you modify the speed of the player twice in a row then the script will reset the 2nd change on the 1st timer event.

I think this should fix it. You can stack the slow down effects with it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function hitplayer2(id, source, weapon)
     local speedmod
     
     if (itemtype(weapon, "slot") == 1) then
          parse("speedmod " .. id .. " -10")
	     speedmod = player(id, "speedmod")
          timer (100, "parse", "speedmod " .. id .. " " ..speemod+10) -- "speedmod" ~= speedmod

     elseif (itemtype(weapon, "slot") == 2) then
          parse("speedmod " .. id .. " -5")
	     speedmod = player(id, "speedmod")
          timer (200, "parse", "speedmod " .. id .. " " .. speedmod+5) -- "speedmod" ~= speedmod
     end
end
1× editiert, zuletzt 23.01.16 13:04:39

alt Re: Table class, message to team, array explanation

Ace Howl
User Off Offline

Zitieren
Big cheers @user Cure Pikachu for solving most of the questions. That's nice @user Dousea, improvising his codes.

About array, does that have the same function as this? If not, what differs them?
1
2
3
4
classtype = {}
for id = 1,32 do
	classtype[id] = 0
end

About Question 1 and 3, how for specific table content?
1
2
3
item.StealthAssassin = {85,84,52}
item.ISIS = {47,48,89,77}
item.Engineer = {10,4,74}



EDIT:
@user Yates: Why did you think it was bugged?
@user Bowlinghead: Great idea! But, I don't prefer stacked though. It makes the victim look like stuck from tight hole :ugly .

alt Re: Table class, message to team, array explanation

Cure Pikachu
User Off Offline

Zitieren
@user Ace Howl: Yeah the initArray function and your code do the same thing.
For specific items, the same technique used to answer your Q2 applies here:
1
2
3
4
5
6
7
8
function hitplayer(id,source,weapon)
	for _, wpn in ipairs(tab) do -- where tab is the table name
		if weapon == wpn then
			parse("flashplayer "..id.." 10")
			break -- Here you can safely break out of the loop
		end
	end
end
Again, item.StealthAssassin is the same as item["StealthAssassin"], so you'll need to call item = {} first. But cs2d lua cmd item is already a CS2D function, so I wouldn't use that namespace if I were you.

The speedmod code is bugged because of what user Bowlinghead mentioned:
user Bowlinghead hat geschrieben
If you modify the speed of the player twice in a row then the script will reset the 2nd change on the timer event.

And the code he provided won't theoretically let you hit targets to a screeching halt, so don't worry about that.
2× editiert, zuletzt 23.01.16 13:02:24

alt Solved

Ace Howl
User Off Offline

Zitieren
Oh I see! The duration difference from victim result in diversed output.

Thanks user Cure Pikachu. I would be in darkness if I have not known all of those especially the array one. Shorter one is convenient compared to initArray stuff . break function, I didn't see that from most script.

alt Re: Table class, message to team, array explanation

Cure Pikachu
User Off Offline

Zitieren
Actually the initArray function used in the samples isn't complete.
user Lee, thread cs2d Lua Scripts/Questions/Help hat geschrieben
This is a simplified version to create a table with 'm' number of elements in there, and each of them will have a 0. This was originally a sample I submitted to DC, a revised version is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function initArray(i,x,d)
	local array = {}
	if type(i) == "table" then
		array = i
		i = x
		x = d
	end
	if (x == nil) then x = 0 end
	for m = 1 , i do
		if (array[m] == nil) then
			array[m] = x
		end
	end
	return array
end
Use as follows:
1
2
3
4
5
6
7
old_table = initArray(4,1)

-- old_table now = {1,1,1,1}

old_table = initArray(old_table,10)

-- old_table now = {1,1,1,1,0,0,0,0,0,0}

alt Re: Table class, message to team, array explanation

omg
User Off Offline

Zitieren
the badly written "slow on hit" code is making me facepalm. every single version of it will result in unwanted behavior. you either have to assume everyone starts at speedmod 0 or only let hits slow u by -10. though in my opinion this shouldnt stack because at speedmod -20 u basically stop moving unless u have a knife out
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht