English Object Destroy

20 replies
Goto Page
To the start Previous 1 2 Next To the start
14.08.15 12:25:11 pm
Up
Jarates
User
Offline Off
Does anyone knows how to destroy object with mouse pointer?
14.08.15 01:44:11 pm
Up
Pseudon
User
Offline Off
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.
*Empty*
14.08.15 01:48:38 pm
Up
Jarates
User
Offline Off
I need the function that destroy the object.

function destroy()
if object(id,'exists') then
?? Destroy ???
14.08.15 02:03:49 pm
Up
Pseudon
User
Offline Off
What about the console command cs2d cmd killobject?
And also you might make use of cs2d lua cmd object.
*Empty*
14.08.15 02:18:17 pm
Up
Jarates
User
Offline Off
I want when use F3 kill object at mouse pointer . Can you do that?
14.08.15 02:47:14 pm
Up
Fraizeraust
Moderator
Offline Off
Yes, you can do that by using cs2d lua hook serveraction hook.
14.08.15 04:49:37 pm
Up
Danbka
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("serveraction","serveraction_")
function serveraction_(id,act)
if act=2 then
reqcld(id,2)
end
end

addhook("clientdata","clientdata_")
function clientdata_(id,mode,x,y)
if mode==2 then 
parse("explosion "..x.." "..y.." 20 999999")
end
end
edited 1×, last 14.08.15 05:15:09 pm
14.08.15 04:54:20 pm
Up
gamus
User
Offline Off
@user Danbka: tabbed and fixed
Code:
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
14.08.15 04:54:35 pm
Up
Jarates
User
Offline Off
Code:
1
parse("explosion "..x.." "..y.." 20 999999")

I didn't ask the object to be removed by explosion LOL
14.08.15 04:58:24 pm
Up
gamus
User
Offline Off
Well you didn't mention that you don't want it either.
14.08.15 05:01:02 pm
Up
Jarates
User
Offline Off
@user gamus: are you stupid or what?
14.08.15 05:08:36 pm
Up
gamus
User
Offline Off
I suppose I am what
14.08.15 05:10:33 pm
Up
Danbka
User
Offline Off
@user Jarates: I think explosion would be better
14.08.15 05:16:40 pm
Up
PyKemis
User
Offline Off
Try this:

Code:
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
14.08.15 05:38:53 pm
Up
Danbka
User
Offline Off
Please:
Code:
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
addhook("clientdata","clientdata_hook")
function clientdata_hook(id,mode,x,y)
     if mode==2 then
          parse("killobject "..objectat(tile(x),tile(y)))
     end
end

addhook("serveraction","serveraction_hook")
function serveraction_hook(id,act)
     if act==2 then
           reqcld(id,2)
     end
end

--this code is ideal

function tile(pos)
     local tile=(pos-16)/(32)
     local floor_tile=math.floor((pos-16)/(32))
      if tile-floor_tile<=0.5 then
          return math.floor(tile)
     else
          return math.ceil(tile)+1-1
     end
end

--this code is ideal
14.08.15 06:00:15 pm
Up
PyKemis
User
Offline Off
You're not checking if there is an object at [x,y]. Prepare for lots of console errors.
14.08.15 06:06:18 pm
Up
Danbka
User
Offline Off
...
Code:
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
addhook("clientdata","clientdata_hook")
function clientdata_hook(id,mode,x,y)
if mode==2 then
if object(objectat(tile(x),tile(y)),"exists") then
parse("killobject "..objectat(tile(x),tile(y)))
end
end
end

addhook("serveraction","serveraction_hook")
function serveraction_hook(id,act)
if act==2 then
reqcld(id,2)
end
end

--this code is ideal

function tile(pos)
local tile=(pos-16)/(32)
local floor_tile=math.floor((pos-16)/(32))
if tile-floor_tile<=0.5 then
return math.floor(tile)
else
return math.ceil(tile)+1-1
end
end

--this code is ideal


...
14.08.15 06:14:42 pm
Up
PyKemis
User
Offline Off
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.
14.08.15 06:39:36 pm
Up
Danbka
User
Offline Off
@user PyKemis: really ? and you compare my and your , and see what difference
14.08.15 06:44:35 pm
Up
PyKemis
User
Offline Off
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