Forum

> > CS2D > Scripts > [Request]Instauild-button
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Request]Instauild-button

8 replies
To the start Previous 1 Next To the start

old [Request]Instauild-button

Flametail
User Off Offline

Quote
Hi! this might sound like a weird request, but I'm looking for a script where a player pressess a button on their keyboard, and a "Wall 1" is placed at their cursor position. And if they press another key, any "Wall 1" under their cursor just disappears.


Kinda like a speed-build for fortress making?

old Re: [Request]Instauild-button

Jynxxx
User Off Offline

Quote
well you can use a server action to build thew wall but i don't know how to make it appear on the cursor position.

old Re: [Request]Instauild-button

EP
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
function Array(s,v)
local array = {}
	for i = 1,s do
	array[i] = v
	end
	return array
end

wall = Array(32,false) addhook("join","lol") function lol(id) wall[id] = false end

addhook("clientdata","asd")
function asd(id,mode,x,y)
	if mode == 2 then
		if wall[id] == true then
			parse("spawnobject 3 "..(x/32).." "..(y/32).." "..player(id,"rot").." 0 "..player(id,"team").." "..id)
			wall[id] = false
		end
	end
end
addhook("use","a")
function a(id)
	if player(id,"health") > 0 then
		wall[id] = true
		reqcld(id,2)
	end
end
the delete thingy is a bit difficult, but im trying to make it

old Re: [Request]Instauild-button

Apache uwu
User Off Offline

Quote
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
addhook("serveraction","_serveraction")
addhook("always","_always")
addhook("clientdata","_clientdata")

function _serveraction(id,action)
	local objid=objectid(mouse[id][1],mouse[id][2])
	if objid and action==2 then
		if object(objid,"type")==3 then
			parse("killobject "..objid)
		end
	elseif not objid and action==1 then
		parse("spawnobject 3 "..mouse[id][1].." "..mouse[id][2].." 0 0 "..player(id,"team").." "..id)
	end
end

function _always()
	reqcld(0,2)
end

function _clientdata(id,mode,x,y)
	mouse=mouse or {}
	if mode==2 then
		mouse[id]={math.floor(x/32),math.floor(y/32)}
	end
end

function objectid(x,y)
	for _,id in pairs(object(0,"table")) do
		if object(id,"tilex")==x and object(id,"tiley")==y then
			return id
		end
	end
	return false
end

F2: Build 'Wall I' under cursor
F3: Delete 'Wall I' under cursor

old Re: [Request]Instauild-button

EP
User Off Offline

Quote
instead of using hook always you can just call the reqcld when pressing the serveraction and so get the values:
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
addhook("serveraction","_serveraction")
addhook("clientdata","_clientdata")

function _serveraction(id,action)
	reqcld(0,2)
     local objid=objectid(mouse[id][1],mouse[id][2])
     if objid and action==2 then
          if object(objid,"type")==3 then
               parse("killobject "..objid)
          end
     elseif not objid and action==1 then
          parse("spawnobject 3 "..mouse[id][1].." "..mouse[id][2].." 0 0 "..player(id,"team").." "..id)
     end
end


function _clientdata(id,mode,x,y)
     mouse=mouse or {}
     if mode==2 then
          mouse[id]={math.floor(x/32),math.floor(y/32)}
     end
end

function objectid(x,y)
     for _,id in pairs(object(0,"table")) do
          if object(id,"tilex")==x and object(id,"tiley")==y then
               return id
          end
     end
     return false
end

old Re: [Request]Instauild-button

Apache uwu
User Off Offline

Quote
I used to host servers, from my experience I can say that your method is less server extensive; but slower.

People with say 200+ ping will have their mouse position taken from seconds after the button is pressed. By saving their mouse positions every frame -- fastest as possible, it's saving time.

It's really how you balance server power and speed. I've not noticed any difference in bandwidth usage or connection rates. However I have seen a difference in speed. Thus, I have chosen to use my method simply for that reason.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview