Forum

> > CS2D > Scripts > Throwing Machete Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Throwing Machete Script

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

old Re: Throwing Machete Script

JJ5x5
User Off Offline

Quote
BrahOrkah has written
My approach to it:

Spoiler >


copy and paste into server.lua
might edit and work with tween_move
when you say copy and paste it in server.lua do you mean the thing like dofile("sys/lua/SCRIPT.lua") like that or i paste the SCRIPT ITSELF to server.lua? ok sorry i know im stupid but i dont script that much so tell me what i have to put in or edit here to make this work and if it is possible in right click can you do it :X well thats up to you because you migt get pissed if u remake the script but anyway what do i put in?

old Re: Throwing Machete Script

BrahOrkah
BANNED Off Offline

Quote
MISTERpinoy has written
Brah0rkah it works fine but ithink he wants it on right click

ATTACK2


Problem is that machete doesn't have a second attack.. It wont fire the attack2 function when you right click, so there's no point in doing that. U can reskin the knive to a machete and then it will work if u replace attack with attack2. ( and change weapon id to knive_id)

Other guy:

you can:
1. copy paste it DIRECTLY into server.lua... ( delete everything else)

2.create a new script ( blabla.lua) and type in server.lua: dofile("sys/lua/blabla.lua") in case blabla is located in sys/lua.
edited 1×, last 13.04.11 05:52:32 pm

old Re: Throwing Machete Script

BrahOrkah
BANNED Off Offline

Quote
No that's not possible unfortunately.
Lua scripts are run on the server, and can't force clients to bind a key to something.

old Re: Throwing Machete Script

BrahOrkah
BANNED Off Offline

Quote
DannyDeth has written
bind rightclick? lol.
You could just use:
1
addhook("attack2","machete_throw")


No this is not gonna work because machete DOESN'T trigger attack2 ever.

old Re: Throwing Machete Script

BrahOrkah
BANNED Off Offline

Quote
MISTERpinoy has written
then just use knife?

wtf what a *****


Hey, I'm not gonna help you if you are badmouthing me.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--[[Constants]]--
rpiconst = 180/math.pi
imagepath = "gfx/weapons/machete.bmp" -- path to imagepath
speed = 25--speed of machete
rotation_speed = 60 -- rotation speed
tileconst = 32
collisionradius = 50

MACHETES = {}
machete = {}
machete_mt = {__index = machete}


function machete:new(x,y,dir,rot,playerid)
     return setmetatable({x=x,y=y,dir=dir,rot=rot,id =nil, imageid = nil, pid = playerid},machete_mt)
end

function machete:draw()
     self.imageid = image(imagepath,self.x,self.y,1)
end

function machete:update()
     self.y = self.y - (math.cos(self.dir)*speed)
     self.x = self.x + (math.sin(self.dir)*speed)

     self.rot = self.rot + rotation_speed
     if self.rot >= 360 then
          self.rot = 0
     end

     local t,x,y = self:wall_collision()

     if(t) then
          self:destroy()
          fall_x,fall_y = (x - round(math.sin(self.dir))),y + round(math.cos(self.dir))
          parse('spawnitem 69 '..fall_x..' '..fall_y)
     end


     if(self.x > (map("xsize")*tileconst) or self.x < 0 or self.y > (map("ysize")*tileconst) or self.y < 0) then
          self:destroy()
     else
          imagepos(self.imageid,self.x,self.y,self.rot)
     end

     self:player_collision()

end

function machete:wall_collision()
     local xt,yt = math.floor(self.x/tileconst),math.floor(self.y/tileconst)
return not tile(xt,yt,"walkable"),xt,yt
end

function machete:destroy()
     freeimage(self.imageid)
     table.remove(MACHETES,self.id)
     for i,m in ipairs(MACHETES) do
          m.id = i
     end
end

function machete:player_collision()
     local players = player(0,"tableliving")
     for i=1,#players,1 do
          if i ~= self.pid then
               local dis = (self.x - player(players[i],"x"))^2 + (self.y - player(players[i],"y"))^2
               if dis <= 400 then
                    parse('customkill '..self.pid..' "Throwing Machete" '..players[i])
                    self:destroy()

                    local x,y = math.floor(player(players[i],"x")/32),math.floor(player(players[i],"y")/32)
                    parse('spawnitem 69 '..x..' '..y)
                    return
               end
          end
     end
end


addhook("attack2","my_attack2")
function my_attack2(id,mode)
     if player(id,"weapontype") == 50 then

          parse('strip '..id..' 51')
          local m = machete:new(player(id,"x"),player(id,"y"),toRad(player(id,"rot")),0,id)
          table.insert(MACHETES,m)
          m.id = #MACHETES
          m:draw()
     end
end

addhook( "ms100","my_ms100")
function my_ms100()
     for i,v in ipairs(MACHETES) do
          v:update()
     end
end

function toRad(deg)
     return (deg / rpiconst)
end

function round(d)
     if d < 0 then return math.floor(d) else return math.ceil(d) end
end

old Re: Throwing Machete Script

DannyDeth
User Off Offline

Quote
@Brah:
Argh, I forgot that weapons that don't have an 'attack2' won't call the attack2 hook. I feel like a complete moron

old Re: Throwing Machete Script

JJ5x5
User Off Offline

Quote
user BrahOrkah has written
My approach to it:

Spoiler >


copy and paste into server.lua
might edit and work with tween_move
WOW THANKS IT WORKS! only a few problems the picture of the machete has pnk around it how do i stop that? and when i try to throw it trough an obstacle it dosent go trough and what is your usgn id oh yes and it team kills even if FF (freindly fire) is off if you can fix them thanks alot
edited 1×, last 22.04.11 07:22:50 am
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview