Forum

> > CS2D > Scripts > Script Request
Forums overviewCS2D overview Scripts overviewLog in to reply

English Script Request

14 replies
To the start Previous 1 Next To the start

old Script Request

Jarago
User Off Offline

Quote
hi all!
well im working on another map and i need simple script (i hope its simple)... well im not scripter and i dont like scripting so...

Script:
When player dies - Random Custom Death Sound will run (of 3)...
and also specific sound file will run.

Thx and sry for bad english

old Re: Script Request

Apache uwu
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
sounds={
	"player/die1.wav",
	"player/die2.wav",
	"player/die3.wav"
}

addhook("die","_die")

function _die(id)
	parse("sv_sound \""..sounds[math.random(#sounds)].."\"")
	parse("sv_sound \"another_sound.wav\"")
end

You can also change cs2d cmd sv_sound to cs2d cmd sv_sound2.

old Re: Script Request

Jarago
User Off Offline

Quote
thx
and is it possible to disable any other sounds when player dies? there are some sound loops in map...

old Re: Script Request

EP
User Off Offline

Quote
@user Jarago: I do not think so that is possible to disable the default sounds of the game. But if it's annoying to hear lots of sounds at same time (when playing with much users) you can use this script that just allows to sound to the players that are in a specific range.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sounds={
     "player/die1.wav",
     "player/die2.wav",
     "player/die3.wav"
}

distance = 300 

addhook("die","_die")
function _die(id)
	for _,pl in ipairs(player(0,"table")) do
		local x = (player(pl,"x") - player(id,"x"))^2
		local y = (player(pl,"y") - player(id,"y"))^2
		local dist = math.sqrt(x + y)
		if dist < distance then
			parse("sv_sound2 "..pl.." "..sounds[math.random(#sounds)])
			parse("sv_sound2 "..pl.." anothersound.wav")
		end
	end
end
You can change the distance (in pixels) if you want.

old Re: Script Request

Jarago
User Off Offline

Quote
i mean custom sounds added to map with env_sound...
its adventure map and while playing, env_sound song loop is running. And when player dies, this loop or any other env_sound in map will disable so player can hear only death sound + short death song...
but after death song, all env_sounds will be enabled again...

well... maybe it is not possible, ill add only death sounds then...
edited 1×, last 24.06.12 10:38:31 pm

old Re: Script Request

EP
User Off Offline

Quote
Yeah it is possible, but you have to trigger that sound (It has to have a name) via the CS2D Script.

old Re: Script Request

Apache uwu
User Off Offline

Quote
Maybe try to prevent death with the cs2d lua hook hit hook and then teleport the player and have some cs2d cmd effect to emu/sim the effect of respawning.

old Re: Script Request

Jarago
User Off Offline

Quote
ok, i used only death sounds for now, thx for script

Ok, i need one more script... when player enters target trigger_move, text shows up on screen "Boss" and his health. It disapears when boss is dead. Boss is currently one of NPC´s and i want to see his health when fighting him. Is it possible?
edited 1×, last 27.06.12 09:50:14 am

old Re: Script Request

Infinite Rain
Reviewer Off Offline

Quote
user Apache uwu has written
1
2
3
4
5
6
7
8
9
10
11
12
sounds={
	"player/die1.wav",
	"player/die2.wav",
	"player/die3.wav"
}

addhook("die","_die")

function _die(id)
	parse("sv_sound \""..sounds[math.random(#sounds)].."\"")
	parse("sv_sound \"another_sound.wav\"")
end

You can also change cs2d cmd sv_sound to cs2d cmd sv_sound2.

You didn't seed the random function, make it otherwise it wll be NOT random at all

old Re: Script Request

Apache uwu
User Off Offline

Quote
It's still random, it will just be the same on every start of the game--which no one will really care anyway, there are only 3 sound files.

old Re: Script Request

omg
User Off Offline

Quote
user Alistaire has written
It is not possible. You can't make a healthbar for a generic NPC.

lol yeah u can

1
2
3
4
object(0,"table")--table of all dynamic object id's, includes npcs
object(id,"typename")--has the value of "NPC" if its a default npc
object(id,"type")--the specific number for an npc (all zombies are type 30, etc)
object(id,"health")--the hp of the npc, of course
other:
object(id,"x"), object(id,"y"), object(id,"tilex"), and object(id,"tiley") can be used to locate the object, if u dont know its dynamic id (provided there arent other objects in range that the boss can be confused with)

then u only have to think about how to display the hp

this can be accomplished easily by using hudtxt2 with players in the boss area + with images which i dislike

old Re: Script Request

Alistaire
User Off Offline

Quote
user omg has written
user Alistaire has written
It is not possible. You can't make a healthbar for a generic NPC.

lol yeah u can

1
2
3
4
object(0,"table")--table of all dynamic object id's, includes npcs
object(id,"typename")--has the value of "NPC" if its a default npc
object(id,"type")--the specific number for an npc (all zombies are type 30, etc)
object(id,"health")--the hp of the npc, of course
other:
object(id,"x"), object(id,"y"), object(id,"tilex"), and object(id,"tiley") can be used to locate the object, if u dont know its dynamic id (provided there arent other objects in range that the boss can be confused with)

then u only have to think about how to display the hp

this can be accomplished easily by using hudtxt2 with players in the boss area + with images which i dislike


That only works for the entity, not for an individual one.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview