Forum

> > CS2D > Scripts > Building Health
Forums overviewCS2D overview Scripts overviewLog in to reply

English Building Health

19 replies
To the start Previous 1 Next To the start

old Building Health

_Vava_
User Off Offline

Quote
Hi all, I wanted to tell you that I am trying to make a script, and I need your help, I wanted to know if we can change the life of buildings by a script I think with Objectdamage Hook.
I try but I do not understand how
I give you some idea
Barricade with 300 HP
and if we aim with our point in the barricade it show the Barricade Health
Thx for all x)

old Re: Building Health

Mami Tomoe
User Off Offline

Quote
You can change the health but you can't change the percentage because in math the highest percentage is 100 of course...

old Re: Building Health

_Vava_
User Off Offline

Quote
Yeah i want juste a script to change health of building noot the percentage but if we aim it show the health of building ..... i don't know i think with a hudtxt Barricade health: 300 Left

old Re: Building Health

Masea
Super User Off Offline

Quote
It can be done with Lua but I'm so sure that will cause tons of lags. The indicator which is with percent is good anyway.

old Re: Building Health

Rainoth
Moderator Off Offline

Quote
Sure it's possible. I've done it before. Let me try digging my old cs2d folder, maybe I'll find something ^.o

// Refer to thread cs2d Dispenser infinite health for building health
For what you're asking, here's what I have. You'll have to butcher up this script to get what you need. It was never released but pretty much finished tho xd

The Code >
edited 2×, last 16.08.16 11:56:20 pm

old Re: Building Health

Masea
Super User Off Offline

Quote
I made something like when you hit the object, you will see the object's health in center of your screen and it will be remove in 3 seconds;
1
2
3
4
5
addhook("objectdamage","_ob")
function _ob(id,s,iid)
	parse('hudtxt2 '..iid..' 1 "HP of the object: '..object(id,"health")..'" 320 240 1')
	parse("hudtxtalphafade "..iid.." 1 3000 0")
end
I think this is exactly what he wanted from us.

old Re: Building Health

Rainoth
Moderator Off Offline

Quote
@user QuakeR:
Quote
Hi all, I wanted to tell you that I am trying to make a script, and I need your help, I wanted to know if we can change the life of buildings by a script I think with Objectdamage Hook.
I try but I do not understand how
I give you some idea
Barricade with 300 HP
and if we aim with our point in the barricade it show the Barricade Health
Thx for all x)

So basically
"Can I change life of buildings?" - √
"Can we see see building health if we point on the building?" - √

Both are possible.

@user Masea: He wants to be able to see it by moving cursor on building. So you'd need clientdata for that. Yours is also good method but wouldn't be practical all the time. Like for example if I could see health of buildings by hovering over them I could prioritize some. With hit you would find it only after you hit, which kinda defeats the whole "planning" part.

old Re: Building Health

Masea
Super User Off Offline

Quote
@user Rainoth: Oh yeah, I thought like what you said in my previous comment. As you can see I typed there; "it will cause tons of lags.". After that, I saw he did put "aim" word to his comment and I thought he want something like when we hit the object then we will able to see its health.

So, use the code of mine, the other one which is you want does lags.

old Re: Building Health

Rainoth
Moderator Off Offline

Quote
@user Masea: Doesn't lag though. I use ms100 pretty sure so I guess you could say "the text position updates 5 times less frequently than the actual game" but it's not that annoying. Doesn't really make that much lag.

old Re: Building Health

Masea
Super User Off Offline

Quote
@user Rainoth: You have to put the reqcld function in ms100 or always hook and it does lag.
@user QuakeR: What? I tested my code and it is working.

old Re: Building Health

Rainoth
Moderator Off Offline

Quote
@user Masea: I'm well aware. That's why I said you need clientdata for what he needs. It doesn't lag noticibly though. Even if the person had high ping (like say 500) it would still mean that the health appears after half a second. It's a big difference when you're playing compared to just hovering over things. That's why I said "doesn't really make that much lag".

old Re: Building Health

Masea
Super User Off Offline

Quote
@user Rainoth: I know only thing that is generating the reqcld function in every millisecond, does make lag and even can crash the server or make FPS drops. So, you're wrong little bit. I got my best fps drops or any problems when I start to use that function on ms100 or always hook. This is why user SQ didn't make "hover" system for menus in his latest project. So sorry, if I got you wrong.

old Re: Building Health

VADemon
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
objectHP = {}
objectHP.timerTick = 0
objectHP.hudid = 6	-- Internal ID of used HUDTXT. Change if you have problems with other scripts.

addhook("ms100", "objectHP.requestTimer")
addhook("clientdata", "objectHP.clientdata")

function objectHP.requestTimer()
	objectHP.timerTick = objectHP.timerTick + 1
	
	if objectHP.timerTick == 1 then -- every 1 ticks, which is every 100ms
		objectHP.requestClientdata()
		
		objectHP.timerTick = 0
	end
end

function objectHP.requestClientdata()
	local playerList = player(0,"table")
	for i = 1, #playerList do
		reqcld(playerList[i], 2)
	end
end

function objectHP.removeHudtxt(id)
	parse("hudtxt2 ".. id .. " ".. objectHP.hudid)
end

function objectHP.clientdata(id, mode, x, y)
	local tilex, tiley
	
	if mode==2 then -- absolute cursor pos on map
		tilex = math.ceil(tonumber(x / 32)) - 1
		tiley = math.ceil(tonumber(y / 32)) - 1
	else
		return
	end
	
	local objectID = objectat(tilex, tiley)
	
	if objectID ~= 0 then
		--msg("Object at ".. tilex .."|".. tiley)
		local typeID = object(objectID, "type")
		
		if (typeID > 0 and typeID < 15) or typeID == 30 then -- only for buildings and NPCs
			local team = object(objectID, "team")
			local color = (team == 1 and "©255025000") or ((team == 2 or team == 3) and "©050150255") or ""
			local text = color .. "HP: ".. object(objectID, "health")
			
			local mousex = (x - math.ceil(player(id,"x")) + 320) --screen cursor position
			local mousey = (y - math.ceil(player(id,"y")) + 240)
			parse("hudtxt2 ".. id .. " ".. objectHP.hudid .." \"".. text .."\" ".. mousex .." ".. mousey+56 .." 1")	-- change position if you need to
		else
			objectHP.removeHudtxt(id)
		end
	else
		--msg("Nothing at ".. tilex .."|".. tiley)
		objectHP.removeHudtxt(id)
	end
end
Tell me whether I should further improve and upload it.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview