Forum

> > CS2D > Scripts > Weapon type
Forums overviewCS2D overview Scripts overviewLog in to reply

English Weapon type

4 replies
To the start Previous 1 Next To the start

old Weapon type

KenVo
User Off Offline

Quote
How did weiwen make explosion weapon type = 251?
You can see
1
2
3
if weapon == 251 then
		dmg = math.ceil(2500/math.random(80,120))
wpnName = 'rune'

in:
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
addhook("hit","EXPhit")
function EXPhit(id,source,weapon,hpdmg,apdmg)
	local HP, dmg, wpnName, name = player(id, "health")
	if hpdmg <= 0 or source == 0 then
		PLAYERS[id].HP = HP-hpdmg
		return
	end
	if type(source) == "table" then
		if gettile(PLAYERS[id].x, PLAYERS[id].y).SAFE or gettile(PLAYERS[id].x, PLAYERS[id].y).NOMONSTERS then return 1 end
		dmg =  math.ceil(math.random(10,20)*hpdmg*source.atk/PLAYERS[id].tmp.def/15)
		source, wpnName = 0, source.name
		--print(wpnName .. " deals " .. dmg .. " damage to " .. player(id, "name") .. ".")
	elseif player(source, 'health') > 0 then
		if id == source then return 1 end
		if inarray({400, 401, 402, 403, 404}, PLAYERS[source].Equipment[7]) then message(source, "You may not attack on a horse.") return 1 end
		if gettile(PLAYERS[id].x, PLAYERS[id].y).SAFE or gettile(PLAYERS[source].x, PLAYERS[source].y).SAFE or gettile(PLAYERS[id].x, PLAYERS[id].y).NOPVP or gettile(PLAYERS[source].x, PLAYERS[source].y).NOPVP then message(source, "You may not attack someone in a SAFE or PVP disabled area.") return 1 end
		if not PLAYERS[id].Tutorial.hit then
			message(id, "A player is attacking you! You can fight back by swinging your weapon at him.", "255128000")
			PLAYERS[id].Tutorial.hit = true
		end
		local atk = PLAYERS[source].tmp.atk
		local def = PLAYERS[id].tmp.def
		if weapon == 251 then
			dmg = math.ceil(2500/math.random(80,120))
			wpnName = 'rune'
		elseif weapon == 46 then
			dmg = math.ceil(500/math.random(80,120))
			wpnName = 'firewave'
		else
			local dmgMul = ((PLAYERS[id].Level+50)*atk/def)/math.random(60,140)
			dmg = math.ceil(20*dmgMul)
			wpnName = PLAYERS[source].Equipment[3] and ITEMS[PLAYERS[source].Equipment[3]].name or 'dagger'
		end
		--print(player(source, "name") .. " deals " .. dmg .. " damage to " .. player(id, "name") .. ".")
	end
	local resultHP = HP-dmg
	if resultHP > 0 then
		sethealth(id,resultHP)
		parse('effect "colorsmoke" ' .. player(id, "x") .. ' ' .. player(id, "y") .. ' 0 0 192 0 0')
	else
		parse('customkill ' .. source .. ' "' .. wpnName .. '" ' .. id)
	end
	PLAYERS[id].HP = resultHP
	return 1
end

old Re: Weapon type

EngiN33R
Moderator Off Offline

Quote
Well, it's all scripted, and not just in that one small bit. You could script it yourself, with the cs2d cmd explosion command and all that.

old Re: Weapon type

KenVo
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
function trapexplosion(x, y, size, damage, id)
	for _, victim in ipairs(player(0, 'table')) do
		if math.sqrt((player(victim, 'x')-x)^2)+((player(victim, 'y')-y)^2) <= size then
			message(victim,"You got hurt by ".. id)
		end
	end
	local pos = x .. " " .. y
	parse("effect \"colorsmoke\" " .. pos .. " 75 64 255 0 0")
	--parse("explosion " .. x .. " " .. y .. " " .. size .. " " .. damage .. " " .. id)
end

I tried something like this and it didn't work. The victim won't get the message after the trap explode. However, when i remove the loop thing and only use parse(explosion..) it works, but I don't want to use explosion and want to make my own explosion function.

old Re: Weapon type

EngiN33R
Moderator Off Offline

Quote
Well the code you provided won't work, the distance calculation is incorrect, it has an extra bracket. This should, in theory, work:
1
math.sqrt((player(victim,'x')-x)^2+(player(victim,'y')-y)^2)

old Re: Weapon type

DC
Admin Off Offline

Quote
Quote
How did weiwen make explosion weapon type = 251?

simple answer: he didn't. that's part of the game. damage dealt by buildings (turret, barbed wire, team gate) and explosions or NPCs have the weapon types 255 and lower. they are no real weapons but they still need a weapon id for the kill message stuff. so that's why high ids are used for them.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview