Rocketmod 
25 comments After the fireballmod, I now present you the new and better rocketmod! I used a more OOP approach to script this time.
Includes:
Multiple rockets for one person!
Detonate at a distance
Rockets cost money
Easy to edit constants
Install:
Extract everything in your cs2d folder
Usage:
Press F2 to launch a rocket, press F3 to make it explode.
Includes:




Install:

Usage:


Comments
25 commentsLog in!
You need to log in to be able to write comments!Log in
I modified your code a little bit - now the rocket follows your cursor and rotates accordingly (although there's a small problem there). Explode with attack (left click). I hope you dont mind that i changed it. Copy this to rocketmod.lua:

--[[Constants]]--
rpiconst = 180 / math.pi
imagepath = "sys/lua/rocketmod/Rocket.png" -- path to image
speed = 15 --speed of rocket
dmg = 100 --damage the rocket does
turnrate = 20 --@depricated turnrate of the rocket
tileconst =32 --width/height of tile
collisionradius = 200 -- the radius in which the rocket will do damage
money = 1000
--[[ Table setups! ]]--
ROCKETS = {} -- table to store all rockets
rocket = {}
rocket_mt = { __index = rocket}
rocketmod = {}
--[[ Hooks! ]]--
addhook("serveraction","rocketmod.serveraction")
function rocketmod.serveraction(id,action)
if action == 1 then
if(buyItem(id,money)) then
local fb = rocket:new(player(id,"x"),player(id,"y"),toRad(player(id,"rot")),player(id,"rot"),id)
table.insert(ROCKETS,fb)
fb.id = #ROCKETS
fb:draw() -- draw once to get an imageid
end
end
if action == 2 then
for _k,_v in ipairs(ROCKETS) do
if(id == _v.pid) then
_v:explode()
break
end
end
end
end
addhook("ms100","my_ms100")
function my_ms100()
for i,v in ipairs(ROCKETS) do
v:update()
end
end
--[[
Below here is the rocket class!
]]--
function rocket:new(x,y,dir,rot,playerid)
return setmetatable({x=x,y=y,dir=dir,rot=rot,id = nil,imageid = nil,pid = playerid},rocket_mt)
end
function rocket:draw()
self.imageid = image(imagepath,self.x,self.y,1)
imagepos(self.imageid,self.x,self.y,self.rot)
imagescale(self.imageid,0.6,0.6)
end
function rocket:explode()
parse(string.format("%s %i %i %i %i %i","explosion",self.x,self.y,collisionradius,dmg,self.pid))
self:destroy()
end
function rocket:update()
self.y = self.y - (math.cos(self.dir)*speed)
self.x = self.x + (math.sin(self.dir)*speed)
--Player collision
--[[for i,v in ipairs(player(0,"table")) do
if(i ~= self.pid) then
if(self:collision(i)) then
--parse("sethealth "..i.." "..(player(i,"health")-dmg))
parse("customkill "..self.pid.." rocketed "..i)
self:destroy()
end
end
end --]]
--Map boundaries collision
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
end
function rocket:destroy()
freeimage(self.imageid)
table.remove(ROCKETS,self.id)
for i,m in ipairs(ROCKETS) do
m.id = i
end
end
function rocket:collision(playerid)
if((self.x > player(playerid,"x") - collisionradius) and (self.x < player(playerid,"x") + collisionradius)) then
if((self.y > player(playerid,"y") - collisionradius) and (self.y < player(playerid,"y") + collisionradius)) then
return true
end
end
return false
end
function rocket:turn(rate)
self.dir = self.dir + toRad(rate)
self.rot = self.rot + rate
end
--[[ Additional functions ]]--
function buyItem(id,price)
cm = player(id,"money")
if(cm>=price) then
parse("setmoney "..id.." "..cm-price)
return true
else
msg2(id,"©255000000 You have insufficient funds!")
return false
end
end
function toRad(deg)
return (deg / rpiconst)
end
(xD)
rpiconst = 180 / math.pi
imagepath = "sys/lua/rocketmod/Rocket.png" -- path to image
speed = 15 --speed of rocket
dmg = 100 --damage the rocket does
turnrate = 20 --@depricated turnrate of the rocket
tileconst =32 --width/height of tile
collisionradius = 200 -- the radius in which the rocket will do damage
money = 1000
--[[ Table setups! ]]--
ROCKETS = {} -- table to store all rockets
rocket = {}
rocket_mt = { __index = rocket}
rocketmod = {}
--[[ Hooks! ]]--
addhook("serveraction","rocketmod.serveraction")
function rocketmod.serveraction(id,action)
if action == 1 then
if(buyItem(id,money)) then
local fb = rocket:new(player(id,"x"),player(id,"y"),toRad(player(id,"rot")),player(id,"rot"),id)
table.insert(ROCKETS,fb)
fb.id = #ROCKETS
fb:draw() -- draw once to get an imageid
end
end
if action == 2 then
for _k,_v in ipairs(ROCKETS) do
if(id == _v.pid) then
_v:explode()
break
end
end
end
end
addhook("ms100","my_ms100")
function my_ms100()
for i,v in ipairs(ROCKETS) do
v:update()
end
end
--[[
Below here is the rocket class!
]]--
function rocket:new(x,y,dir,rot,playerid)
return setmetatable({x=x,y=y,dir=dir,rot=rot,id = nil,imageid = nil,pid = playerid},rocket_mt)
end
function rocket:draw()
self.imageid = image(imagepath,self.x,self.y,1)
imagepos(self.imageid,self.x,self.y,self.rot)
imagescale(self.imageid,0.6,0.6)
end
function rocket:explode()
parse(string.format("%s %i %i %i %i %i","explosion",self.x,self.y,collisionradius,dmg,self.pid))
self:destroy()
end
function rocket:update()
self.y = self.y - (math.cos(self.dir)*speed)
self.x = self.x + (math.sin(self.dir)*speed)
--Player collision
--[[for i,v in ipairs(player(0,"table")) do
if(i ~= self.pid) then
if(self:collision(i)) then
--parse("sethealth "..i.." "..(player(i,"health")-dmg))
parse("customkill "..self.pid.." rocketed "..i)
self:destroy()
end
end
end --]]
--Map boundaries collision
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
end
function rocket:destroy()
freeimage(self.imageid)
table.remove(ROCKETS,self.id)
for i,m in ipairs(ROCKETS) do
m.id = i
end
end
function rocket:collision(playerid)
if((self.x > player(playerid,"x") - collisionradius) and (self.x < player(playerid,"x") + collisionradius)) then
if((self.y > player(playerid,"y") - collisionradius) and (self.y < player(playerid,"y") + collisionradius)) then
return true
end
end
return false
end
function rocket:turn(rate)
self.dir = self.dir + toRad(rate)
self.rot = self.rot + rate
end
--[[ Additional functions ]]--
function buyItem(id,price)
cm = player(id,"money")
if(cm>=price) then
parse("setmoney "..id.." "..cm-price)
return true
else
msg2(id,"©255000000 You have insufficient funds!")
return false
end
end
function toRad(deg)
return (deg / rpiconst)
end
(xD)
If other people want to see the Rocket, they must have the graphics installed! U can , for example, add it to your map so it will automaticalloy send to the player.