ID:141668
 
Code:
turf/Click()
if(usr.oktothrow==1&&!usr.inthrowing)
if(usr.inthrowing)
return
var/obj/Weapon/C= new()
C.loc=usr.loc
C.str=usr.str
usr.inthrowing=1
C.Move_Delay=1
walk_towards(C,src)
sleep(5)
usr.inthrowing=0

Problem description:

I want to make a system that, when you click on the map, the char throws the weapon. I tried the above code, but it's not working, so, if you guys could help me.
Thanks a lot,
Tntgsh.
My assumption is that you're trying to create a obj/Weapon but there actually is no obj/Weapon, maybe you meant like, obj/Weapon/Knife ?

Also, you can use the new() proc's argument to set the location of the object being created.
In response to Andre-g1
No, unfortunately, the problem is not as simple as that. The obj/Weapon is just something I used to post here.

Still not working here. =[
In response to Tntgsh
    if(usr.oktothrow==1&&!usr.inthrowing)
if(usr.inthrowing)
return


Are you sure your oktothrow is set to 1 and inthrowing is set to 0 when you try to fire ? Also, you should use atom/Click(), so if you click a mob, it'll throw at the mob too.
In response to Andre-g1
I put this code in everything you can click on...
And, yes, the vars are right.

How would you do a code like this?
In response to Tntgsh
Tntgsh wrote:
I put this code in everything you can click on...

You could just put it under atom/Click() to simplify.

How would you do a code like this?

atom/Click()
..() // incase you made another override
if(!usr.throwing)
usr.throwing = 1
var/obj/weapon/knife/P = new(usr.loc)
walk_towards(P,src)
spawn(20) usr.throwing = 0
In response to Andre-g1
It's working now, thanks a lot =D
I've tried a new things and another doubt came to my mind...
Is it possible to do something like this?
turf/Click()
if(usr.oktothrow==1&&!usr.inthrowing)
if(usr.inthrowing)
return
var/obj/Weapon/C= new()
C.loc=usr.loc
C.str=usr.str
usr.inthrowing=1
C.Move_Delay=1
walk_towards(C,src.y-2) //Take a look in this line, on the y-2
sleep(5)
usr.inthrowing=0


I tested it but it's not working, so I don't know what to do to get the same effect. Any help would be very usefull.
Thanks a lot,
Tntgsh.
In response to Tntgsh
var/atom/A = locate(src.x,src.y-2,src.z)
if(A) walk_towards(C,A)


You need to specify an atom for it to walk_towards. AFAIK, locs don't work on walk_towards.
In response to Andre-g1
Uh, thanks a lot, working now.
In response to Andre-g1
Andre-g1 wrote:
AFAIK, locs don't work on walk_towards.

Uhm, and by that you mean? Looks like you're a little confused, since if you can't use locations (which all atoms are), what are you going to use? Typecasting the var as /atom will also make no difference if you may have thought it would, as that definition has no bearing on runtime, locate() will still return a turf all the same, etc.
In response to Kaioken
To be clear here: src.y is just a number. src.y-2 is still just a number.

walk_towards() has no clue what to do with, say, the number 24.

There are no 'location' type references. src.loc refers to an /atom, and walk_towards() accepts an atom as a reference (which it then reads x, y and z coordinates off).
In response to Alathon
I get what he was trying to say. "Locs" wasn't really a suitable term though, as he was talking about coordinates/numbers. >_>

Alathon wrote:
There are no 'location' type references.

Yeah, there's no actual object/data type like that. Just atom types are locations.