Files

> > CS2D > Lua Scripts > Rocketmod
Files overviewCS2D overviewLua Scripts overview

English Rocketmod >

25 comments11 kb, 855 Downloads

old Rocketmod

YellowBanana
BANNED Off Offline

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.
Approved by GeoB99

Download Download

11 kb, 855 Downloads

Comments

25 comments
Page
To the start Previous 1 2 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old

JONY
User Off Offline

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:
Spoiler >

old

bestquit
User Off Offline

bad script very bad stars:1 maximum 5

old

DeD_Ha_Ta6yPeTke
User Off Offline

--[[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)
I like it!

old

RyceR
User Off Offline

@RedNarok Kamikaze is my mode
I like it!

old

RadNarok
User Off Offline

Nice Work Kamikaze XD.
I like it!

old

HaRe
User Off Offline

Or another way just add it to the servertransfer.cfg in your sys folder

old

YellowBanana
BANNED Off Offline

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.

old

Delta
User Off Offline

nice work
I like it!

old U made an oops D=

shokeh
User Off Offline

This would be 5/5 but 1 problem

Other ppl dont see the rocket or the explosion they think I use admin powers. D=
I like it!

old

Slater
User Off Offline

COOL VERY GOOOD!
I like it!

old

Jake-rus
User Off Offline

LOL
I like it!

old

Banaan
User Off Offline

great
I like it!

old

XiBaoZi
COMMUNITY BANNED Off Offline

nice script

old

DoP3
User Off Offline

LOL epic mod.
I like it!

old

Gucis
User Off Offline

Nice
I like it!

old

RyceR
User Off Offline

me too
I like it!

old

Mirash
User Off Offline

YEAH! good script! Im like it! KABOOOOOM!
I like it!

old

connor34
User Off Offline

yes crazyx i am with you
I like it!
To the start Previous 1 2 Next To the start