Forum

> > CS2D > Scripts > Easy script for someone to make
Forums overviewCS2D overview Scripts overviewLog in to reply

English Easy script for someone to make

17 replies
To the start Previous 1 Next To the start

old Easy script for someone to make

SuomiSotilas
User Off Offline

Quote
Hey all, first of all i suck at scripts Dont even know what it means lol..
So trying to find help to do this one easy script! I would like to have a sound coming when they either lose or win the round. Not the ''Counter terrorists win!'' Or vice versa~ I mean one for the losing team and one for winning team. Would be better & appreciate if u could have couple sounds for losers and couple for winners. Going in a random order? Well ill put MAIN which have to be on and if possible add the other too! NO LOOP! ~

And something more. When i press a button, could it mixteams? or if it could be added on the same script by saying like @mixteams. But i like more only pressing a button and it would mixteams!
I use Tlex, just informing if it would cause any problems?

(All on sfx/) If u need this; For losing team sound called cheater.ogg <--MAIN , no.ogg and For winning team feelgood.wav , thatstheway.wav <-- MAIN , this is sparta.wav ... Would appreciate if someone would postthe script here & Where to put it

EDIT:-----------------------------------
Ive found something like this:

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
addhook("endround", "end_of_round")

function ctwin()
     a = math.random(1,6)
parse(string.format("sv_sound \"misc/win%d.ogg\"", a))
end

function twin()
     a = math.random(1,6)
parse(string.format("sv_sound \"misc/win%d.ogg\"", a))
end

function end_of_round(mode)
     if mode==1 then --Regular T win
          twin()
     elseif mode==2 then --Regular CT win
          ctwin()
     elseif mode==3 then --Round draw
     elseif mode==4 then --Game commencing
     elseif mode==10 then --VIP assassinated; T win
          twin()
     elseif mode==11 then --VIP escaped; CT win
          ctwin()
     elseif mode==12 then --VIP did not escape; T win
          twin()
     elseif mode==20 then --Bomb exploded; T win
          twin()
     elseif mode==21 then --Bomb defused; CT win
          ctwin()
     elseif mode==22 then --Failed to plant the bomb in specified time; CT win
          ctwin()
     elseif mode==30 then --Failed to rescue hostages in specified time; T win
          twin()
     elseif mode==31 then --All hostages rescued; CT win
          ctwin()
     elseif mode==40 then --Blue flag captured; T win
          twin()
     elseif mode==41 then --Red flag captured; CT win
          ctwin()
     elseif mode==50 then --All points dominated; T win
          twin()
     elseif mode==51 then --All points dominated; CT win
          ctwin()
     elseif mode==60 then --All humans infested; Zombies win
     elseif mode==61 then --Humans survived; Humans win
     end
end

Whats wrong with that? It doesnt work for me. Ive choosed that lua for my server already and stuff but its the script.
parse(string.format("sv_sound \"misc/win%d.ogg\"", a)) Is it in that? Do i have to change it to C:/TheSoundFile.ogg\"", a)) ? What does that sv_sound mean in there? And why is the "", a)) in there? Can i took it off? Well enough questions. Now i need answers
edited 1×, last 19.05.12 02:11:36 pm

old Re: Easy script for someone to make

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
23
24
25
26
27
28
29
30
31
32
function winteam(m) --calculates the winning team when supplied endround mode
	if m-39==1 or m-39==2 then return m-39 end
	if m-49==1 or m-49==2 then return m-49 end
	if m-29==2 then return m-29 end
	if m-9==2 then return m-9 end
	return m
end

music = {
	win = {
		"thatstheway.wav",
		"feelgood.wav",
		"this is sparta.wav"
	},
	lose = {
		"cheater.ogg",
		"no.ogg"
	}
}

addhook("endround","playendmusic")
function playendmusic(mode)
	local wteam=winteam(mode)
	if wteam==1 or wteam==2 then
		for _,i in pairs(player(0,"team"..(3-wteam))) do
			parse("sv_sound2 "..i.." \""..music.lose[math.random(1,#music.lose)].."\"")
		end
		for _,i in pairs(player(0,"team"..wteam)) do
			parse("sv_sound2 "..i.." \""..music.win[math.random(1,#music.win)].."\"")
		end
	end
end
The code for the music. If you have any questions about any part of this script - go ahead and ask.
edited 1×, last 19.05.12 02:40:32 pm

old Re: Easy script for someone to make

SuomiSotilas
User Off Offline

Quote
user EngiN33R has written
Spoiler >

The code for the music. If you have any questions about any part of this script - go ahead and ask.


Thanks! Well can i just copy & paste to the end of this script a bit from another lua? example:
Spoiler >

Will it work?
& do i just write under the other sound files if i want to put another one? Like:
1
2
3
4
"thatstheway.wav",
		"feelgood.wav",
		"this is sparta.wav"
		"somesoundfile.ogg"
edited 2×, last 20.05.12 10:54:34 am

old Re: Easy script for someone to make

Cure Pikachu
User Off Offline

Quote
Only if the other parts of the script is error-free. The example code you gave us won't work due to a missing end.

As for mix teams, this is what I can think of.
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
29
30
31
32
33
34
35
buttonx = 50 -- X coordinate of button in tiles
buttony = 50 -- Y coordinate of button in tiles

multi = 3/4 -- Multiplier (Set it between 0 and 1, 1 inclusive). This determines how many players per team will be switched to the other team

addhook("use","mixteams")
function mixteams(id,event,data,x,y)
	if event == 100 then
		if x = buttonx and y = buttony then
			local tlimit = player(0,"team1")
			local ctlimit = player(0,"team2")
			local multifix = multi
			if multifix <= 0 then
				multifix = 1/4
			end
			if multifix > 1 then
				multifix = 1
			end
			local tnum = math.floor(#tlimit*multifix)
			local ctnum = math.floor(#ctlimit*multifix)
			if tnum > 0 then
				for a = 1, tnum do
					local b = math.random(1,#tlimit)
					parse("makect "..tlimit[b])
				end
			end
			if ctnum > 0 then
				for c = 1, ctnum do 
					local d = math.random(1,#ctlimit)
					parse("maket "..ctlimit[d])
				end
			end
		end
	end
end

old Re: Easy script for someone to make

SuomiSotilas
User Off Offline

Quote
user Cure Pikachu has written
Only if the other parts of the script is error-free. The example code you gave us won't work due to a missing end.

As for mix teams, this is what I can think of.
Spoiler >


Ok thanks alot! One thing i dont understand:
1
multi = 3/4 -- Multiplier (Set it between 0 and 1, 1 inclusive). This determines how many players per team will be switched to the other team
What and how do i change that if i want 2players switched from both teams?

old Re: Easy script for someone to make

Cure Pikachu
User Off Offline

Quote
It's a multiplier, after all. So the code needs to be re-written. This one's the "constant" version.
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
buttonx = 50 -- X coordinate of button in tiles
buttony = 50 -- Y coordinate of button in tiles

constant = 2 -- How many players per team will be switched to the other

addhook("use","mixteams")
function mixteams(id,event,data,x,y)
	if event == 100 then
		if x == buttonx and y == buttony then
			local tlimit = player(0,"team1")
			local ctlimit = player(0,"team2")
			if #tlimit >= constant then
				for a = 1, constant do
					local b = math.random(1,#tlimit)
					parse("makect "..tlimit[b])
				end
			end
			if #ctlimit >= constant then
				for c = 1, constant do 
					local d = math.random(1,#ctlimit)
					parse("maket "..ctlimit[d])
				end
			end
		end
	end
end

old Re: Easy script for someone to make

EngiN33R
Moderator Off Offline

Quote
user SuomiSotilas has written
& do i just write under the other sound files if i want to put another one? Like:
1
2
3
4
"thatstheway.wav",
		"feelgood.wav",
		"this is sparta.wav"
		"somesoundfile.ogg"


Yes, you do that. It's made so that you could easily add other sounds.

old Thanks

SuomiSotilas
User Off Offline

Quote
user Cure Pikachu has written
It's a multiplier, after all. So the code needs to be re-written. This one's the "constant" version.
Spoiler >


Ok thanks. I dont understand anything about these, even the simpliest thing is totally strange to me

user EngiN33R has written
Yes, you do that. It's made so that you could easily add other sounds.


Great job! √
PS: Think my map is ready. Thank you all who helped me! I will upload it soon

old Re: Easy script for someone to make

omg
User Off Offline

Quote
the info.txt in ur lua folder is a great reference if u need help figuring out how to do something (in cs2d, i mean. its only supposed to include stuff thats specific to cs2d only) (twas awesome when i found the player(id,"value") functions finally found those...)

the only stuff thats not included is how to use general lua stuff like variables, logic statements (if, else, for...), and the functions that come standard with lua

the only other thing u need is logic

also, i would ask people to help u with coding if u dont already have some experience with it because it wont immediately be intuitive the first time learning it unless u have some previous reference (like knowing java )

try doing some related practice scripts like coding fastbuild or maybe coding ur own broadcast script for a harder challenge (this will cover many good elements) (no pasting from somebody else, try to figure out as much as u can by urself before requesting help as that is usually the best way to learn)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview