ID:180650
 
Im trying to implement a catapult.
the catapult is a turf with a density of 0

what I want is a "Launch" verb fr it.
when you click "Launch" any obj or mob currently standing on top of the catapult are launchhe dirrection it is facing. (i want them to fly about 20 tiles)
any number of objects should be placable on it, and all should be flung at once.

also i want the verbs "Rotate Left" and "Rotate Right"
how do i check the catapults current direction and rotate it?
On 4/18/01 8:14 pm Mloren wrote:
Im trying to implement a catapult.

A tad difficult, but definitely doable.

the catapult is a turf with a density of 0

what I want is a "Launch" verb fr it.
when you click "Launch" any obj or mob currently standing on top of the catapult are launchhe dirrection it is facing. (i want them to fly about 20 tiles)
any number of objects should be placable on it, and all should be flung at once.

You could try making some sort of loop;

proc/CatapultFling(O, dir, length=20)
if(length)
O:loc = get_step(O, dir)
spawn(3) CatapultFling(O,dir,--length)
else //landing!
if(ismob(O) && !istype(O:loc,/turf/pillow)) //hee hee =)
O:Damage(rand(5,10))

This loop continues until length is zero, at which point it would quit. I've given an example of the landing. You can do whatever you want, though.

Then you would make the verb to call CatapultFling() on everything in the space.

turf/catapult
density = 0
var/direction = NORTH //see below

verb/Launch()
set src = oview(1) //implicit source
for(var/mob/M in src) //fling all mobs
CatapultFling(M, src.direction, rand(18,22))
for(var/obj/O in src) //fling all objs
CatapultFling(O, src.direction, rand(18,22))


also i want the verbs "Rotate Left" and "Rotate Right"
how do i check the catapults current direction and rotate it?

Two things; first, turfs don't have dir variables, so you need to specify some sort of variable. Like the one I did in the Launch() example above. So use that. =)

Assuming you are, here's the rotate clockwise and anti-clockwise verbs. Which, in turn, use the turn() proc. Hee hee. Just remember that positive angles are counterclockwise.


verb/Rotate_Counterclockwise()
src.direction = turn(src.direction,45) //the turn proc!

verb/Rotate_Clockwise()
src.direction = turn(src.direction,-45)
In response to Spuzzum
Thanks :)
that all works wonderfuly... except... :)
with the rotate verbs, it doesnt rotate the icon.
if its pointing north and i rotate it one then fire it, sure the objects fly in the new direction but visualy, tcon hasnt changed.

the turf catapult.dmi contains 4 directions (all in the same icon state)
In response to Mloren
On 4/19/01 2:14 am Mloren wrote:
Thanks :)
that all works wonderfuly... except... :)
with the rotate verbs, it doesnt rotate the icon.
if its pointing north and i rotate it one then fire it, sure the objects fly in the new direction but visualy, tcon hasnt changed.

the turf catapult.dmi contains 4 directions (all in the same icon state)

Like I said, turfs don't have a dir variable. Thus, they won't automatically rotate at all.

You'd need to make the catapult.dmi have 4 (or 8) separate icon states, and then set each icon state's name to the following:

NORTH = 1
SOUTH = 2
EAST = 4
WEST = 8

That is, you'd have four states, "1", "2", "4", and "8"

(if you have eight)
NORTHEAST = 5
NORTHWEST = 9
SOUTHEAST = 6
SOUTHWEST = 10

Those states would be "5", "6", "9", and "10".


In other words, put your north state in the icon state labelled "1", your south state in the icon state labelled "2", your east state in the state labelled "4", and the west in the one labelled "8".

Then when you change the direction of the catapult, do

src.direction = turn(src.direction, -45)
src.icon_state = num2text(src.direction)


Or, if you're feeling risky, look at using the turn() proc on the icon itself (yes!)! It rotates the icon, but only top-down.
In response to Spuzzum
Like I said, turfs don't have a dir variable.

Spuzzum! Whenever you tell a lie, it makes Chretien cry. Shame on you!
In response to Gughunter
On 4/19/01 11:37 am Gughunter wrote:
Like I said, turfs don't have a dir variable.

Spuzzum! Whenever you tell a lie, it makes Chretien cry. Shame on you!

They do?! Eep, sorry! Mloren, you should search/replace all of the src.direction stuff to src.dir, then! And get rid of the var/direction = NORTH line too.

Whoops. But why do turfs have a dir variable, anyway? Does that make sense? How can ground (or walls) be facing a particular direction?
In response to Spuzzum
Whoops. But why do turfs have a dir variable, anyway? Does that make sense? How can ground (or walls) be facing a particular direction?

Well, I'd guess it's for cases just like this--where the actual terrain is not as important as a fixed feature on it. I can even imagine it making sense for walls or roads, if you had different icon states for them.
In response to Gughunter
Well, I'd guess it's for cases just like this--where the actual terrain is not as important as a fixed feature on it. I can even imagine it making sense for walls or roads, if you had different icon states for them.

I would have the catapult as an object ;>
In response to Gughunter
On 4/20/01 5:25 am Gughunter wrote:
Whoops. But why do turfs have a dir variable, anyway? Does that make sense? How can ground (or walls) be facing a particular direction?

Well, I'd guess it's for cases just like this--where the actual terrain is not as important as a fixed feature on it. I can even imagine it making sense for walls or roads, if you had different icon states for them.


well icon dirs do make sence for roads and tile.. and rocks.. ok say you have 4 dirs for your road... its not the fact that the road needs to change the dir its faceing but the fact that it makes a simple way to have an icon change.. like if a bomb is placed on the road and gos off the you would make you dir change to north.. (witch is rubble mind you) well just thinking of it as another way to change how your icon looks.... also could i get a copy of your catipult code? it would be killer to put in my game.. (oh great now i have 2 games that have about 300 PAGES of code to make.... this will be fun...) NOTE: jobe is only writing all of this babble that makes no since and dose not seem to have any single topic becase he just got his computer back ( GOD DAMN LUNIX FOR WINDOWS AND ALL ITS FALTY PARTITIONS!!!!) ok im done now....... OH YEAH! I have a group that is working along with Ultimate Gameing World... and i need GREAT coders to help me.. i have 1 RPG that i made the entire RP system for (paper pen RPG) and i need help codeing it.. (it will be the biggest RPG so far and i have a GREAT game that has over 300 pages of C code to go with it... i want to port that also... ( IT INCLUDES THE TEXT COURDINATE SPACE SYSTEM!! ANYONE WHO HELPS ME CODE IT WILL GET THE CODE TO PUT IT IN ANY GAME THEY WISH!) well i really need coders... like spuzzum.. and Gughunter and dan and tom and whoevery knows everything byond can do.. PLEASE HELP ME! if you want to join then just email me at [email protected] thatnks!
In response to Spuzzum
On 4/18/01 8:55 pm Spuzzum wrote:
On 4/18/01 8:14 pm Mloren wrote:
Im trying to implement a catapult.

A tad difficult, but definitely doable.

the catapult is a turf with a density of 0

what I want is a "Launch" verb fr it.
when you click "Launch" any obj or mob currently standing on top of the catapult are launchhe dirrection it is facing. (i want them to fly about 20 tiles)
any number of objects should be placable on it, and all should be flung at once.

You could try making some sort of loop;

proc/CatapultFling(O, dir, length=20)
if(length)
O:loc = get_step(O, dir)
spawn(3) CatapultFling(O,dir,--length)
else //landing!
if(ismob(O) && !istype(O:loc,/turf/pillow)) //hee hee =)
O:Damage(rand(5,10))

This loop continues until length is zero, at which point it would quit. I've given an example of the landing. You can do whatever you want, though.

Then you would make the verb to call CatapultFling() on everything in the space.

turf/catapult
density = 0
var/direction = NORTH //see below

verb/Launch()
set src = oview(1) //implicit source
for(var/mob/M in src) //fling all mobs
CatapultFling(M, src.direction, rand(18,22))
for(var/obj/O in src) //fling all objs
CatapultFling(O, src.direction, rand(18,22))


also i want the verbs "Rotate Left" and "Rotate Right"
how do i check the catapults current direction and rotate it?

Two things; first, turfs don't have dir variables, so you need to specify some sort of variable. Like the one I did in the Launch() example above. So use that. =)

Assuming you are, here's the rotate clockwise and anti-clockwise verbs. Which, in turn, use the turn() proc. Hee hee. Just remember that positive angles are counterclockwise.


verb/Rotate_Counterclockwise()
src.direction = turn(src.direction,45) //the turn proc!

verb/Rotate_Clockwise()
src.direction = turn(src.direction,-45)


ok i also put this is my game (hope noone minds) but now i have another problem.. i need an item.. this item will blow up a 4x4 area if it bumps into anything.. (or lands) how would i do this? i would need it to distroy walls (and put a rubble turf down where a wall was (but not water.. it would have to fizzle out if it hit water.. (and any mobs hitting water would have to die (drown). ok so maybie i dont do much on my own.. oh well.. if anyone cold help it would be great.. (i did change the catipult to an item) and the damedge thing given here dose not work.. nor dose the turn thing.. well some help? i am still learning BYOND but i like to learn from messing with others code.. (more fun)
In response to Jobey
What a long and impressive paragraph! Uh, yeah. =)

ok i also put this is my game (hope noone minds)

No one would mind, I think. Well, since I posted the code, I have the rights to it anyway, and I don't care one way or the other. =)

but now i have another problem.. i need an item.. this item will blow up a 4x4 area if it bumps into anything.. (or lands)

You need to look at the proc/CatapultFling() proc that I made. (In your case, I would replace O:loc = get_step(O, dir) with O.Move(get_step(O,dir)), so it can bump into things.)

A better method than the way I first presented would be to make a global atomic proc called Land().

atom/proc/Land()
return

Then in the CatapultFling() proc, whenever something lands it does something.


proc/CatapultFling(O, dir, length=20)
if(length)
O:Move(get_step(O, dir))
spawn(3) CatapultFling(O,dir,--length)
else //landing!
O:Land()



Then for something that you want to do a task when it lands, just add stuff to its Land() proc. Whenever the thing lands, it will do whatever is in the Land() proc. A couple examples;

mob/Land()
if(!istype(src.loc,/turf/water))
src.Damage(rand(5,10))
else
src << "Sploosh! You drown."
del(src)

obj/bomb/Land()
if(!istype(src.loc,/turf/water))
src.Explode()
else
del(src)

obj/fireball/Land()
new /obj/fire(src.loc)
del(src)


So, since I've defined a /obj/bomb that you can fling around, if the bomb lands, it will Explode(). Thus, you can set the /obj/bomb to Explode() whenever it Bump()s something also.

obj/bomb
density = 1
Bump()
src.Explode()

i would need it to distroy walls (and put a rubble turf down where a wall was (but not water.. it would have to fizzle out if it hit water.. (and any mobs hitting water would have to die (drown). ok so maybie i dont do much on my own.. oh well..

I've given you the leeway to make the Explode() proc yourself. See if you can do that part! =)

I'll give you a hint; turfs can be replaced simply by making a new turf on top of the old one;

proc/ExampleTransform()
//changes the turf at 3,3,1 to grass
var/turf/T = locate(3,3,1)
T = new /turf/grass

And you can override /obj/Del() when something is deleted to do something besides just vanish... but be sure to call ..() at the end, or the obj won't ever be deleted!

obj/wall/Del()
new /obj/rubble(src.loc) //make some rubble
..() //finish the job


So if you blow up a turf, you would change the turf that was affected into a rubble turf. (Not in Del(), mind you, but in a different proc.)

And if you blow up an obj, just change Del() to drop some rubble before the obj vanishes.


So you'd need to check for all turfs within a radius of the bomb, and then transform them to rubble if they are walls. Or if you're working with obj walls, just delete them and the rubble will follow.


if anyone cold help it would be great.. (i did change the catipult to an item) and the damedge thing given here dose not work.. nor dose the turn thing..

Like I said deeper into the other post, you need to replace all cases of 'direction' with 'dir', and to get rid of the 'var/direction' line.

As for the Damage() proc, that's assuming you actually HAVE a Damage() proc. If you don't, here's the basic version.

mob/proc/Damage(num)
src.HP -= num
if(src.HP <= 0)
src.Death()

mob/proc/Death()
//DO DEATH STUFF HERE


well some help? i am still learning BYOND but i like to learn from messing with others code.. (more fun)

Yeah, it's a great start, but there's nothing that makes you feel more like a pro than building your own world from scratch! =)
In response to Spuzzum
MAN! too meany peaple are too much help! i mean i ask for code and they give me a bunch of examples... not only that but examples that you have to CODE! i am trying to learn.. but now it looks like i am going to be forced to! .... what ever happened to the mindless giving of compleat answers that stut learning but bring faster results?... oh well... thanks...
In response to Spuzzum
On 4/23/01 5:48 pm Spuzzum wrote:
What a long and impressive paragraph! Uh, yeah. =)

ok i also put this is my game (hope noone minds)

No one would mind, I think. Well, since I posted the code, I have the rights to it anyway, and I don't care one way or the other. =)

but now i have another problem.. i need an item.. this item will blow up a 4x4 area if it bumps into anything.. (or lands)

You need to look at the proc/CatapultFling() proc that I made. (In your case, I would replace O:loc = get_step(O, dir) with O.Move(get_step(O,dir)), so it can bump into things.)

A better method than the way I first presented would be to make a global atomic proc called Land().

atom/proc/Land()
return

Then in the CatapultFling() proc, whenever something lands it does something.


proc/CatapultFling(O, dir, length=20)
if(length)
O:Move(get_step(O, dir))
spawn(3) CatapultFling(O,dir,--length)
else //landing!
O:Land()



Then for something that you want to do a task when it lands, just add stuff to its Land() proc. Whenever the thing lands, it will do whatever is in the Land() proc. A couple examples;

mob/Land()
if(!istype(src.loc,/turf/water))
src.Damage(rand(5,10))
else
src << "Sploosh! You drown."
del(src)

obj/bomb/Land()
if(!istype(src.loc,/turf/water))
src.Explode()
else
del(src)

obj/fireball/Land()
new /obj/fire(src.loc)
del(src)


So, since I've defined a /obj/bomb that you can fling around, if the bomb lands, it will Explode(). Thus, you can set the /obj/bomb to Explode() whenever it Bump()s something also.

obj/bomb
density = 1
Bump()
src.Explode()

i would need it to distroy walls (and put a rubble turf down where a wall was (but not water.. it would have to fizzle out if it hit water.. (and any mobs hitting water would have to die (drown). ok so maybie i dont do much on my own.. oh well..

I've given you the leeway to make the Explode() proc yourself. See if you can do that part! =)

I'll give you a hint; turfs can be replaced simply by making a new turf on top of the old one;

proc/ExampleTransform()
//changes the turf at 3,3,1 to grass
var/turf/T = locate(3,3,1)
T = new /turf/grass

And you can override /obj/Del() when something is deleted to do something besides just vanish... but be sure to call ..() at the end, or the obj won't ever be deleted!

obj/wall/Del()
new /obj/rubble(src.loc) //make some rubble
..() //finish the job


So if you blow up a turf, you would change the turf that was affected into a rubble turf. (Not in Del(), mind you, but in a different proc.)

And if you blow up an obj, just change Del() to drop some rubble before the obj vanishes.


So you'd need to check for all turfs within a radius of the bomb, and then transform them to rubble if they are walls. Or if you're working with obj walls, just delete them and the rubble will follow.


if anyone cold help it would be great.. (i did change the catipult to an item) and the damedge thing given here dose not work.. nor dose the turn thing..

Like I said deeper into the other post, you need to replace all cases of 'direction' with 'dir', and to get rid of the 'var/direction' line.

As for the Damage() proc, that's assuming you actually HAVE a Damage() proc. If you don't, here's the basic version.

mob/proc/Damage(num)
src.HP -= num
if(src.HP <= 0)
src.Death()

mob/proc/Death()
//DO DEATH STUFF HERE


well some help? i am still learning BYOND but i like to learn from messing with others code.. (more fun)

Yeah, it's a great start, but there's nothing that makes you feel more like a pro than building your own world from scratch! =)




ok ive got problems... i was just going to try the land proc... well i have an undefined proc of mob/Land() and a bad proc for O:land

ok if you could help... it would be cool.. thanks.. i dont know what i did wrong..
In response to Jobey
ok ive got problems... i was just going to try the land proc... well i have an undefined proc of mob/Land() and a bad proc for O:land

ok if you could help... it would be cool.. thanks.. i dont know what i did wrong..

You did add the /atom/proc/Land() line right?

Also, there were a couple problems with the /atom thing not being there in the latest download (i.e. for some reason, Dream Maker didn't quite update.). Deadron knows more about that than I do, and I don't think he knows much about it. =)
In response to Kaidorin
On 4/21/01 6:50 pm Kaidorin wrote:
Well, I'd guess it's for cases just like this--where the actual terrain is not as important as a fixed feature on it. I can even imagine it making sense for walls or roads, if you had different icon states for them.

I would have the catapult as an object ;>

i tryed makeing it an obj but it dose not work with the same code