• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

getPosByAngle & rotatePos

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
I did this function when i am bored. I see some one on otserv wrold NEVER uses cos and sin function so i did 2 functions :p

The function rotatePos is VERRY good to use in some spells. You can rotate a position by an center and radius and a angle :p
if you do it:
for angle=1,360 do

you can draw a circle.
Like this: (made in lua funmction)

outq.png

(using luagd)
Lua:
require('gd')
im = gd.createTrueColor(500, 500)
	for ang=1,360 do
	local novo = rotatePos({x=250,y=250},100,ang)
	im:setPixel(math.floor(novo.x),math.floor(novo.y),im:colorAllocate(255, 0,0))
end
im:png("out.png")
os.execute("out.png")

And getPosByAngle, you can define a new posittion by an distance and angle. Like: Send a spell 30º at 5 SQMS of distance.

:thumbup:

Here the functions
Lua:
function getPosByAngle(pos,distance,ang) --By Mock the bear
	local ang = math.rad(ang)
	pos.x = (math.cos(ang)*pos.x)+distance
	pos.y = (math.sin(ang)*pos.y)+distance
	return pos
end

function rotatePos(center,radius,ang) --By Mock the bear
	ang = math.rad(ang)
	center.x = (radius * math.cos(ang) - radius * math.sin(ang))+center.x
	center.y = (radius * math.sin(ang) + radius * math.cos(ang))+center.y
	return center
end
 
With the second you can rotate an spell, and with the first function you can do this same spell out the circle form the tg
like:
Recta_tangente_circunferencia.png

(like you rotate a sword or a club and trow)
 
Yeah! useless for non-rpg servers like 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999x9 of Exp... xD

elf, IDEM!
 
But how to implement in OTS? There's only like 8 directions there.
 
@Cykotitan
use a bit your brain :p (not a insult)
you will rotate in º not in tibia dir.
if the dir to >> is 1 and ^^ is 3
the >/\ will be 2
in º it will be 0º, 45º and 90º

degrees-360.gif


And will you can use dirs like 60º
but you will need use math.floor in position because in some times you use angle 15º and 16º it will take pos like 10,3 and 10,5 xDD

And look the circle photo...
This is the same script but the sizes is 20x20, and circle radius is 6 and i used a for 1,16
out.png

Code:
require('gd')
im = gd.createTrueColor(20, 20)
	for ang=1,16 do
	local novo = rotatePos({x=10,y=10},6,ang*(360/16))
	im:setPixel(math.floor(novo.x),math.floor(novo.y),im:colorAllocate(255, 0,0))
end
im:png("out.png")
os.execute("out.png")
 
Important things:
for ang=1,16 do
local novo = rotatePos({x=10,y=10},6,ang*(360/16))
im:setPixel(math.floor(novo.x),math.floor(novo.y),im:colorAllocate(255, 0,0))
end
 
Mock speaks lua better than he speaks english. RUAN!!! :p
 
JDB: hes just lua abuser, I bet that he will release coffe making script soon...

@topic: I dont have any idea how I can use it in serv YET, but its nice
 
ftw...
look an example...

Lua:
function onCastSpell(cid)
     for ang=1,12 do
          local p = rotatePos(getPlayerPosition(cid),4,ang*30)
          doCombatAreaHealth(cid,p,[[Spell params]])
     end
end
and it will "draw" a circle.
And you can do something like tihs too:
Lua:
function onCastSpell(cid)
     local ang = math.random(0,360)
     for i=1,5 do
          local p = getPosByAngle(getCreaturePosition(cid),i,ang)
          doCombatAreaHealth(cid,p,[[Spell params]])
     end
end
 
Best be releasing useless codes.

I suppose a scripted fireball spell with a variable area of effect based on level that's a nice accurate sphere is useless. -.-

Nice to see you're still producing code Mock. =)
 
I suppose a scripted fireball spell with a variable area of effect based on level that's a nice accurate sphere is useless. -.-

Nice to see you're still producing code Mock. =)
thx but sphere use x,y,z and this function use only x,y, so its a circumference
 
thx but sphere use x,y,z and this function use only x,y, so its a circumference

That's true enough, but the physics is a sphere and to the character, in character, they would see a sphere. The player of course only sees a circle on the screen due to the limitations of the Tibia engine. Either way, 'circle' just seems an inappropriate word for an area-of-effect, so shall we agree on an 'accurate radius' as the term? =P
 
Back
Top