Action Plastic Bomb

Colex

print("LUA Scripter")
Joined
Jun 14, 2007
Messages
7
Best answers
0
Reaction score
0
PLASTIC BOMB BY COLEX

How does it work?

The player does use in a Plastic Bomb (I use the item 4825), and he will be unmoveable for a certain time(default is 5 seconds) setting the bomb up, after the bomb has been set up the player will be able to move and the bomb will take a determinated time to explode (default 5 seconds). the explosion will take place in a 3x3 area where the player who is in the middle of the explosion will always take the highest demage possible and the players around will take a random demage between the highest and the lowest demage (the demages are defined in the script in MAX_HIT and MIN_HIT).


1st Step: in the directory data/actions/scripts create a new file named bomb.lua and insert the following script into it:
Code:
----------Plastic Bomb by Colex-----------

local PLANTING_DELAY = 5 --seconds
local EXPLOSION_DELAY = 5000 --milliseconds
local MAX_HIT = 500
local MIN_HIT = 100

local PVP = true -- true for PVP, false for Non-PVP


local PLAYERS = {}

function isInArray(table, valor)
  for i,j in pairs(table) do
    if (j == valor) then
      return i
    end
  end
  return 0
end

function explosion(info)
   area = {
		{0,0,0,0,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,1,1,1,0}, 
		{0,0,0,0,0},
	   }
	hitpos = {x=info.pos.x, y=info.pos.y, z=info.pos.z, stackpos=253}
        center = {}
        center.y = math.floor(table.getn(area)/2)+1
	for i in ipairs(area) do
          center.x = math.floor(table.getn(area[i])/2)+1
          for j, v in ipairs(area[i]) do
            if (v == 1) then
	      hitpos.x = info.pos.x + (j - center.x)
	      hitpos.y = info.pos.y + (i - center.y)
	      if (getTilePzInfo(hitpos) == 0) then   
	        victim = getThingfromPos(hitpos)
		effect = 4
		if ((j == center.x) and (i == center.y)) then
		  doSendAnimatedText(hitpos,"KABOOOOOM",TEXTCOLOR_RED)
		  hitpoints = MAX_HIT
		  effect = 5
		else
		  hitpoints = math.random(MIN_HIT,MAX_HIT)
		end
                if (isPlayer(victim.uid) == 1) then
		  if (PVP == true) then
                     doPlayerSendTextMessage(victim.uid,20,"You have lost "..hitpoints.." hitpoints by "..getPlayerName(info.player).."'s plastic bomb") 
                  else
                    hitpoints = 0
                  end
                end
		if (isCreature(victim.uid) == 1) then
		  doPlayerAddHealth(victim.uid,-hitpoints)
                end
	        doSendMagicEffect(hitpos,effect)
              end
            end
	  end
	end
  PLAYERS[isInArray(PLAYERS, info.player)] = 0
  mayNotLogout(info.player, 0)
  return 1
end

function planting(info)
  if info.num == PLANTING_DELAY then
	doPlayerSendTextMessage(info.player,22,"Plastic Bomb successfully planted!")
	mayNotMove(info.player,0)
	addEvent(explosion,EXPLOSION_DELAY,info)
  else
	info.num = info.num + 1
	doPlayerSendTextMessage(info.player,22,info.num.."...")
	addEvent(planting,1000,info)
  end
  return 1
end

function onUse(cid, item, frompos, item2, topos) 
  position = getThingPos(item.uid)
  if (getTilePzInfo(position) == 0) then
   	if (isInArray(PLAYERS, cid) == 0) then	
		table.insert(PLAYERS, cid)	
		doSendMagicEffect(frompos,3) 
		info = {player = cid, pos = position, num = 1} 
		doPlayerSendTextMessage(cid,22,"Planting the bomb...")
		doPlayerSendTextMessage(cid,22,"1...")
		mayNotMove(cid,1)
		mayNotLogout(cid, 1)
		doRemoveItem(item.uid,1)
		addEvent(planting,1000,info)
	else
		doPlayerSendCancel(cid,"You can only plant one bomb at the same time.")
	end
  else
	doPlayerSendCancel(cid,"You can not plant this bomb in a PZ!")
  end	
  return 1
end

2º Step: open teh folder data/actions and add the following line into actions.xml:
Code:
<action itemid="4852" script="bomb.lua"  />
That's it! You Plastic Bomb should be working now...

(if your ot doesn't have the functions mayNotMove and mayNotLogout, just remove them from the script)

It was only tested in the version 8.0

Yours,
Colex
 
Last edited:

JayBeee

Retired Global Mod
Joined
Jun 2, 2007
Messages
5,225
Best answers
0
Reaction score
13
Location
Sweden
Nice piece of code! I'm sure lots of people will use it. Rep+
 

Mokerhamer

Retired Global Mod
Joined
Aug 6, 2007
Messages
1,766
Best answers
0
Reaction score
35
OW it looks nice it's an good idea to place "Mines" in the wild and if someone steps on it boem! xD
 

kennyeni

New Member
Joined
Jun 2, 2007
Messages
73
Best answers
0
Reaction score
0
MMM it doesnt do damge :S i use TFS 2.6
 

DiegoSkate

Eu tiro é onda.
Joined
Jul 7, 2007
Messages
127
Best answers
0
Reaction score
0
Location
Brazil
uhuhuh good job Colex, i remember you of xtibia forum ;x


Cya!
 
Last edited:

STiX

Intermediate OT User
Joined
Aug 22, 2007
Messages
437
Best answers
0
Reaction score
105
Location
Western Australia
As I said before on ******, nice scripting. You really took your time on this one and its appreciated.
 
Last edited:

scriptha

On a distinguished road
Joined
Jul 21, 2007
Messages
125
Best answers
0
Reaction score
0
Location
/etc/pr0n
If you make 2 bombs a few seconds after each other, you only have to wait for the first one to finish, and you can walk again before the second one finishes
 
OP
Colex

Colex

print("LUA Scripter")
Joined
Jun 14, 2007
Messages
7
Best answers
0
Reaction score
0
@scriptha
Thank you for reporting the bug!

SCRIPT UPDATED
*Hits any creature
*Can only use one bomb at the same time (bugfix)
*New area structure (now it's easier to make your own explosion area):
area = {
{0,0,0,0,0},
{0,1,1,1,0},
{0,1,1,1,0},
{0,1,1,1,0},
{0,0,0,0,0},
}
Yours,
Colex
 
Last edited:

4Play

New Member
Joined
Jul 2, 2007
Messages
89
Best answers
0
Reaction score
0
sounds fun ^^
it can be useful to some wars or some PVP server,kind of implant the bomb in the enemy base,
the bomb can be desactivated?
 
OP
Colex

Colex

print("LUA Scripter")
Joined
Jun 14, 2007
Messages
7
Best answers
0
Reaction score
0
sounds fun ^^
it can be useful to some wars or some PVP server,kind of implant the bomb in the enemy base,
the bomb can be desactivated?

No, maybe in a next update I can add it =P
Thanks for the idea!

Yours,
Colex
 

Nostradamus

New Member
Joined
Jun 2, 2007
Messages
219
Best answers
0
Reaction score
4
Code:
function isInArray(table, valor)
  for i,j in pairs(table) do
    if (j == valor) then
      return i
    end
  end
  return 0
end
You don't need to add that, since OpenTibia already have this function built-in.
 
OP
Colex

Colex

print("LUA Scripter")
Joined
Jun 14, 2007
Messages
7
Best answers
0
Reaction score
0
@Nostradamus_

Yes you need to add that.

a least in the OTServ I use, the IsInArray returns 0 or 1. my function "isInArray" returns where in the array some value is...
take a look in the returns

Yours,
Colex
 

GH057

New Member
Joined
Oct 11, 2007
Messages
54
Best answers
0
Reaction score
0
Location
Brazil
Nice, but i don't think that its good for tibia, plastic bombs does not exist in medieval...
 
Top