Forum

> > CS2D > Scripts > Spwn Protiction
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spwn Protiction

8 replies
To the start Previous 1 Next To the start

old Spwn Protiction

maninja
User Off Offline

Quote
Hello guys ,

today I brought you a new topic and I hope you will help me Let us move on to the subject

I need protiction spwn I'll explain it to you For example When you die and live The player begins to have protection for twenty seconds
And you have a sign indicating that protection in the form of armor or something like that Please help

old Re: Spwn Protiction

DC
Admin Off Offline

Quote
There is a built-in spawn protection. Not sure right now if it was possible to change the duration but it's like 3 seconds or something and enabled in deathmatch/team deathmatch I think.

If you want to add your own custom protection you can do it like this:

∗ In cs2d lua hook spawn hook
• set a flag (in a table, per player) to enable the protection
• create an cs2d lua cmd image at the player (mode: 200+player id) to display the protection
• and also create a cs2d lua cmd timer which will disable the protection after a awhile

∗ In cs2d lua hook hit hook
• Check if the flag is enabled for that player, if yes return 1 so the player does not receive any damage (othrwise don't do anything or return 0)

∗ In the function called by the timer
• Remove the protection image you created (for that you have to store its ID in a table per player as well when creating it)
• Disable the flag variable so the hit-hook won't return 1 anymore and the player receives damage again

You might need some little additions to make it stable in edge cases e.g. when the player dies even while the protection is still enabled (this is possible when switching teams etc.). So you probably also need to clean up timers and check if a protection image already exists.

old Re: Spwn Protiction

Rainoth
Moderator Off Offline

Quote
@user DC: This guy is creating multiple threads for same problems and every single one of them is asking for handouts. He hasn't shown a single fraction of effort.

At least it seems like you stopped using translation tools.

old Re: Spwn Protiction

Talented Doge
User Off Offline

Quote
It's time you learn.

Lua is extremely easy. And for CS2D's basic purpose, it is easier than learning almost anything in High School Course.

old Re: Spwn Protiction

cs2d_is_a_Gem
User 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end

spawnprotection = initArray(32)
spawninvincible = initArray(32)
spawnnotice = initArray(32)

print("loading ...")
addhook("spawn","ej_spawn_p")	       -- Set / Gives Spawn Protection
addhook("ms100","ej_spawn_p_set")      -- Spawn Protection
addhook("second","ej_spawn_p_time")    -- Spawn Protection Timer
addhook("hit","ej_spawn_p_dmg")        -- Can't Get Dmg with Spawn Protection On ( Fixed Lazers )

addhook("hit","ej_spawn_p_atk")	       -- Spawn Protection Notices

function ej_spawn_p(id)
spawnprotection[id] = 15
	if (spawnprotection[id] > 0) then
		msg2(id,"©000255000You have Spawn Protection.@C")
		local i = image('gfx/serverlove.foromx.net/1212132.png', 1, 1, 100+id)
        tween_alpha(i, 17000, 0)
		spawninvincible[id] = 1
	end
end



function ej_spawn_p_set()
	for p = 1,32 do
		if (spawninvincible[p] == 1) then
      parse("setmaxhealth "..p.." 250")
			parse("sethealth "..p.." 250")
			if (spawnprotection[p] == 0) or (spawnprotection[p] <= 0) then
				msg2(p,"©255000000Your Spawn Protection is now off.@C")
				spawninvincible[p] = 0
        parse("setmaxhealth "..p.." 100")
        parse("sethealth "..p.." 100")
			end
		end
	end
end



function ej_spawn_p_dmg(id,source)
	if (spawninvincible[id] == 1) or (spawninvincible[source] == 1) then
		return 1
else
	return 0
	end
end
	

function ej_spawn_p_time()
	for p = 1,32 do
		if (spawninvincible[p] == 1) then
			spawnprotection[p] = spawnprotection[p] - 1
		end
	end
end


function ej_spawn_p_atk(id,source)
	if ( spawnnotice[source] == 1 ) then
		if ( spawninvincible[id] == 1 ) then
			msg2(source,"©235235235"..player(id,"name").." has Spawn Protection for "..spawnprotection[id].." seconds.")
		end
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview