ID:2188539
 
(See the best response by Ter13.)
Code:


Problem description:
I need help with several things, there is no code to show currently.


The first thing is - how would I create an object (or anything that would work in the same fashion) that: spawns in front of the user, and simply goes forward until it hits a dense tile, a mob, or a certain time passes.

I would also like to know how I would make it so that, say, a fireball will also damage anything it comes _near_ as well.



The second thing is - how would I target a single user, and multiple users up to a certain number, within an amount of pixels in the direction the user is facing? So, within 128 pixels the user is facing, mob will be binded for X amount of time.



Thanks in advance for any help!

Best response
Give it a shot. You know I'll help you out where you struggle. You should try it first before asking for someone how to do it.

If you don't know where to start, you should start reading the guide or search the developer help forum.
In response to Ter13
I've just started, and I'm trying to spawn a new fireball and use it.

        Used(mob/user, free = 0)
..()
world << output("Test.","chat")
newProjectile(user.x, user.y, user.z, user.dir, /obj/projectiles/fireball)

proc
newProjectile(x, y, z, dir, obj/i)
new i
if(dir = EAST)
i.loc = locate(x + 1, y, z)
else
i.loc = locate(x - 1, y, z)


And this is resulting in an error,

runtime error: Cannot modify /obj/projectiles/fireball.loc.
proc name: newProjectile (/proc/newProjectile)
source file: Skills.dm,42
usr: Bubba5444 (/mob)
src: null
usr.loc: the turf (4,2,2) (/turf)
call stack:
newProjectile(4, 2, 2, 4, /obj/projectiles/fireball (/obj/projectiles/fireball))
Fire Style: Fireball (/skill/fireball): Used(Bubba5444 (/mob), 0)
Fire Style: Fireball (/skill/fireball): Use(Bubba5444 (/mob), 0, 0)
Bubba5444 (/mob): hotkey(1)
Bubba5444 (/mob): key down("1", Bubba5444 (/client))
Bubba5444 (/client): KeyDown("1")
Let's do some quick revision here.

obj/projectiles
var
mob/owner
New(atom/loc,mob/owner) //called when you invoke new on any type of projectile
src.owner = owner
dir = owner.dir


        Used(mob/user, free = 0)
..()
world << output("Test.","chat")
var/obj/projectiles/p = new/obj/projectiles/fireball(get_step(user,user.dir),user)


The runtime error was because new i creates a new type of i, but i is again a prototype, NOT an object instance.

When we create a new instance, we need to store a reference to it in order to modify its variables. This is the same mistake you ran into in the last thread.

Also, objects take a default argument to New() which lets you set the location where they will be created. We simply used get_step() to figure out where to put the projectile.

Also:

if(dir = EAST)


This isn't doing what you think it is.

if(dir = EAST) is actually doing:

set dir to EAST (4)
if dir is true


What you mean to be doing is:

if(dir==EAST)


if dir is equal to EAST (4)


== and = are different operators completely. == is the equality logical operator, and = is the assignment operator.
In response to Ter13
This doesn't seem to work properly - and is most likely caused by the fact that I'm using Forum_account's sidescroller library.

Using walk, to move the object, will work; but running into anything other than the front will cause you to locate to 0, 0, 0.

I'm not sure if you know anything about this; if not, I'll go see what could be causing this issue.

            var/obj/projectiles/p = new/obj/projectiles/fireball(get_step(user, user.dir), user)
walk(p, p.dir, 0, 4)
Yeah, I don't touch anything written by Forum_account.

Most of his stuff is nice in theory, but comes with major massive drawbacks in application.
In response to Bubba5444
You should try out the demos included in the library. Some of them include projectiles already.
In response to Ter13
Then I'm going to simply redo his library to both see what exactly is causing the problem, and to clean up the code a bit - in my opinion, it's rather ugly (though functional).