ID:149975
 
Im trin to make a rador obj for my game so a pointer points to the nearest person how can that be done are can it o_O
Rollerc wrote:
Im trin to make a rador obj for my game so a pointer points to the nearest person how can that be done are can it o_O

First step: Learn to spell RADAR.

Lummox JR
First, start with a compassy thing.

obj/compassy_thing
var/direction = "NORTH"
icon = "compass"
New()
..()
start
for(var/mob/M in range(30))
break
if(M.y > src.y) src.direction = "NORTH"
else src.direction = "SOUTH"
UpdateState()
spawn(1) goto start
proc/UpdateState()
if(src.direction = "NORTH") icon_state = "north"
else iconstate = "south"


This compassy thing switches it's needle north or south depending on whether the nearest mob within 30 squares is north or south of you. If you added it to a user's contents, it would show them if the nearest person was north or south. Expand on this compassy thing idea, and you'll soon be running a successful radar station!
In response to Lord of Water
Thank u water and Lummox just becasue i have a typo doesnt mean u can say that kind of things to me k so please dont be rude
In response to Lord of Water
Lord of Water wrote:
if(M.y > src.y) src.direction = "NORTH"
else src.direction = "SOUTH"
UpdateState()
spawn(1) goto start
proc/UpdateState()
if(src.direction = "NORTH") icon_state = "north"
else iconstate = "south"

This isn't really necessary, if the icons are made directional to begin with. If you just set src.dir, the icon will face the appropriate direction.

You could also use something like Spuzzum's s_pixel library to show a full radar screen. The code you posted will be good for tracking one target, but not multiples.

Lummox JR
In response to Rollerc
Rollerc wrote:
Thank u water and Lummox just becasue i have a typo doesnt mean u can say that kind of things to me k so please dont be rude

A typo would be a single misspelling not repeated elsewhere; twice is a spelling error. Pointing that out isn't necessarily rude.

Lummox JR
Okay, here's an idea for some radar code--completely untested. It uses concepts found in the newest betas.
obj/radar
mob/owner // point to the player
var/rrange=10
icon='radar.dmi'
screen_loc="SOUTHEAST" // southeast corner of screen

New(mob/M)
owner=M
if(M.client) M.client.screen+=src

proc/Update() // call this via an event loop
var/icon/ic=new /icon('radar.dmi',"")
if(rrange)
for(mob/M in orange(rrange,owner))
var/dx=round((M.x-x)*10/rrange,1)
var/dy=round((M.y-y)*10/rrange,1)
var/icon/pix=new /icon('radar.dmi',"pixel")
pix.Shift(EAST,dx)
pix.Shift(NORTH,dy)
ic.Blend(pix,ICON_OVERLAY)
icon=ic

Now, in radar.dmi, create two icons: One should have a 21x21 square, probably with a border around it, and crosshairs through the middle and all that. This is the main state--leave its state name blank. Name the second icon "pixel"; leave it transparent except for a dot (red, green, whatever color you want) right at the center of where the crosshairs would be in the other icon. The radar will draw itself whenever you call radar.Update() (I suspect there may be a bug in b24 preventing this, so if nothing changes it's a bug), and you can make this loop as complex as you wish. It could even be extended easily enough to put in different colored icons for different teams, or for types of targets.

I may decide to try a BYONDscape article along these lines in the near future, but in more detail.

Lummox JR
In response to Lummox JR
I tried fixxing the bugs but dome how i made it worse lol heres the errors i got when i first put it in


loading Zoids.dme
Zoids.dm:88:error:screen_loc:bad var
Zoids.dm:91:error:owner:bad var
Zoids.dm:92:error:M.client.screen:bad var
Zoids.dm:95:error:/icon:bad path
Zoids.dm:97:error:mob:bad var
Zoids.dm:97:error:M:bad var
Zoids.dm:97:error:owner:bad var
Zoids.dm:98:error:M.x:bad var
Zoids.dm:99:error:M.y:bad var
Zoids.dm:100:error:/icon:bad path
Zoids.dm:101:error:pix.Shift:undefined type: pix.Shift
Zoids.dm:102:error:pix.Shift:undefined type: pix.Shift
Zoids.dm:103:error:pix:undefined type: pix
Zoids.dm:103:error:ICON_OVERLAY:bad var
Zoids.dm:103:error:ic.Blend:undefined type: ic.Blend
Zoids.dm:104:error:ic:undefined type: ic
Zoids.dm:97:/ :warning: statement has no effect
Zoids.dm:97:error::bad assignment
Zoids.dm:95:ic :warning: variable defined but not used
Zoids.dm:100:pix :warning: variable defined but not used

Zoids.dmb - 17 errors, 3 warnings (double-click on an error to jump to it)

and no its not a zoids game i was just testing it on that code
In response to Rollerc
Rollerc wrote:
loading Zoids.dme
Zoids.dm:88:error:screen_loc:bad var
...
Zoids.dm:92:error:M.client.screen:bad var
Zoids.dm:95:error:/icon:bad path

As I said, these need the newer beta versions to work.

Zoids.dm:91:error:owner:bad var

This one's my fault. I put in mob/owner instead of var/mob/owner.

Lummox JR
In response to Lummox JR
ok now here are the newwer errors that came up when i dowloaded the newer byond


loading New Gundam Game.dme
obj.dm:46:error:mob:undefined var
obj.dm:46:error:M:undefined var
obj.dm:47:error:M.x:undefined var
obj.dm:48:error:M.y:undefined var
obj.dm:46:/ :warning: statement has no effect
obj.dm:46:error::bad assignment

In response to Rollerc
Rollerc wrote:
ok now here are the newwer errors that came up when i dowloaded the newer byond


loading New Gundam Game.dme
obj.dm:46:error:mob:undefined var
obj.dm:46:error:M:undefined var
obj.dm:47:error:M.x:undefined var
obj.dm:48:error:M.y:undefined var
obj.dm:46:/ :warning: statement has no effect
obj.dm:46:error::bad assignment

This one's my problem again; I again forgot the var/ in front of a variable:
for(mob/M in orange(rrange,owner))

That should be:
for(var/mob/M in orange(rrange,owner))

Lummox JR
In response to Lummox JR
Lummox JR wrote:
pix.Shift(EAST,dx)

Man I'm slow...I hadn't thought of using shift to allow drawing with single pixels...
In response to Deadron
Deadron wrote:
Man I'm slow...I hadn't thought of using shift to allow drawing with single pixels...

I hope eventually there's an icon.SetPixel(color,x,y) function, or icon.Rectangle(color,x,y,w=1,h=1) (same thing but extensible), but I'm not greedy. For now, shifting is the easiest way to do that.

Lummox JR
In response to Lummox JR
IT WORKED!!!!

tho i keep getting a proc error when i tri puting the verb in ><i put
verb<br/> start
usr<< "U start your radoar up."
Update()




anything rong thare ??


In response to Lummox JR
Lummox JR wrote:
Deadron wrote:
Man I'm slow...I hadn't thought of using shift to allow drawing with single pixels...

I hope eventually there's an icon.SetPixel(color,x,y) function, or icon.Rectangle(color,x,y,w=1,h=1) (same thing but extensible), but I'm not greedy. For now, shifting is the easiest way to do that.

Yeah I imagine those will happen...meantime, of course, one of us could create a library to do just that!

I nominate you, myself...
In response to Rollerc
Rollerc wrote:
IT WORKED!!!!

tho i keep getting a proc error when i tri puting the verb in ><i put
verb
start
usr<< "U start your radoar up."
Update()




anything rong thare ??

Don't forget the parens!

verb
start()

In response to Skysaw
im lossing it -_- forgot about that thats the last time i stay up tell mid nigt to wach cowboy bebob will now we got new errors

obj/radar
var/owner // point to the player
var/rrange=10
icon='radar.dmi'
screen_loc="SOUTHEAST" // southeast corner of screen

New(mob/M)
owner=M
if(M.client) M.client.screen+=src

verb
start()
set src in oview(0)
view(5,usr) << "[usr.name] gets a [src.name]."
Update()


thats the obj
heres the error


obj.dm:57: Inconsistent indentation.
In response to Rollerc
Rollerc wrote:
IT WORKED!!!!

tho i keep getting a proc error when i tri puting the verb in ><i put
verb
start
usr<< "U start your radoar up."
Update()




anything rong thare ??


Like Skysaw said, dont forget the parens. Also, its spelled R-A-D-A-R :]

-Rcet
In response to Rollerc
I would advise against putting verbs in that same object, when isn't meant to be like a regular obj you pick up. Instead, change my obj/radar to obj/radar_screen and make obj/radar the item in your game. Then do this:
obj/radar
icon='items.dmi' // pick whatever icon you want
icon_state="radar"
var/running=0
var/obj/radar_screen/screen=null

verb/Radar()
set src in usr
if(running)
usr << "You turn off the radar."
if(screen) del(screen)
running=0
else
usr << "You turn on the radar."
running=1
screen=new(usr)
// do something here to add this to the events list
// so Update() is called

Move(newloc)
.=..()
// turn off radar screen if dropped or moved
if(running)
running=0
if(loc!=screen.owner)
del(screen)

proc/Update()
if(screen) screen.Update()

obj/radar_screen
// all the other code for the obj I showed you

Lummox JR
In response to Lummox JR
will thare was so errors at all and the radar verb works and all and the screen comes up nut thares no dot on the screen when a nother person joined i looked and all my icon states are right an all



obj/radar
icon='radar.dmi' // pick whatever icon you want
icon_state="radar"
var/running=0
var/obj/radar_screen/screen=null

verb/Radar()
set src in usr
if(running)
usr << "You turn off the radar."
if(screen) del(screen)
running=0
else
usr << "You turn on the radar."
running=1
screen=new(usr)
// do something here to add this to the events list
// so Update() is called

Move(newloc)
.=..()
// turn off radar screen if dropped or moved
if(running)
running=0
if(loc!=screen.owner)
del(screen)

proc/Update()
if(screen) screen.Update()



obj/radar_screen
var/owner // point to the player
var/rrange=30
icon='radar.dmi'
screen_loc="SOUTHEAST" // southeast corner of screen

New(mob/M)
owner=M
if(M.client) M.client.screen+=src




proc/Update() // call this via an event loop
var/icon/ic=new /icon('radar.dmi',"")
if(rrange)
for(var/mob/M in orange(rrange,owner))
var/dx=round((M.x-x)*10/rrange,1)
var/dy=round((M.y-y)*10/rrange,1)
var/icon/pix=new /icon('radar.dmi',"pixel")
pix.Shift(EAST,dx)
pix.Shift(NORTH,dy)
ic.Blend(pix,ICON_OVERLAY)
icon=ic

Page: 1 2 3