Forum

> > CS2D > Scripts > Object Destroy
Forums overviewCS2D overview Scripts overviewLog in to reply

English Object Destroy

20 replies
Page
To the start Previous 1 2 Next To the start

old Object Destroy

Jarates
User Off Offline

Quote
Does anyone knows how to destroy object with mouse pointer?

old Re: Object Destroy

Pseudon
User Off Offline

Quote
Well I think you can use cs2d lua hook clientdata and cs2d lua cmd reqcld to find the position of the mouse and then just do whatever you want after you have found the data. For example, check if a certain object is located in where the pointer is being held and then destroy it.

old Re: Object Destroy

Jarates
User Off Offline

Quote
I need the function that destroy the object.

function destroy()
if object(id,'exists') then
?? Destroy ???

old Re: Object Destroy

gamus
User Off Offline

Quote
@user Danilwra: tabbed and fixed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("serveraction","serveraction_")
addhook("clientdata","clientdata_")

function serveraction_(id,act)
	if act==3 then --this is where you made a mistake
		reqcld(id,2)
	end
end

function clientdata_(id,mode,x,y)
	if mode==2 then 
		parse("explosion "..x.." "..y.." 20 999999")
	end
end

old Re: Object Destroy

Jarates
User Off Offline

Quote
1
parse("explosion "..x.." "..y.." 20 999999")
I didn't ask the object to be removed by explosion LOL

old Re: Object Destroy

Apache uwu
User Off Offline

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

local mouses = {}

function _always()
    reqcld(0, 2)
end

function _clientdata(id, mode, data1, data2)
    if mode == 2 then
        mouses[id] = {data1, data2}
    end
end

function _serveraction(id, action)
    if (action == 2) then
        local objectID = objectat(math.floor(mouses[id][1] / 32 + 0.5), math.floor(mouses[id][2] / 32 + 0.5))
        if (objectID > 0) then
            parse("killobject " .. objectID)
        end
    end
end

old Re: Object Destroy

Apache uwu
User Off Offline

Quote
You're not checking if there is an object at [x,y]. Prepare for lots of console errors.

old Re: Object Destroy

Apache uwu
User Off Offline

Quote
Nevermind, I'm on my phone and didn't see that you're wrapping it with object. Anyways, there's no need to minus 16 and then round up/down.

old Re: Object Destroy

Apache uwu
User Off Offline

Quote
Yep there's no difference, so there's no reason to post the same code twice. The only difference is that you're calling request data once and I'm requesting it in always.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview