ID:147980
 
Hello!
Using part of Wall04's selection demo, my own coding, and some help from others I put this together:

client
MouseDown(A,B)
src.Draw_Grid(A,A) // if nothing is selected.. draw the grid
return ..()
Click(A,B)
for(var/mob/Unit/M in Select)
if(M.player == usr.name)
if(length(Select)>1)
walk_to(M,B,1,3)
M.Attack()
else
walk_to(M,B,0,3)
Select -= M
for(var/I in src.imageslist)
del(I)
..()

mob/proc/Attack()
var/list/L = new
var/mob/K=locate() in oview(1,src)
if(K)
for(K in oview(1))
L+=K
var/mob/M = pick(L)
if(M.colour != usr.colour)
var/damage = usr.Attack - M.Defence
if(damage<=1)
M.Health -= 1
damage = 1
else
M.Health -= damage
view(6)<<"[usr] attack [M] for [damage] damage!"
var/damage2 = M.Attack - usr.Defence
if(damage2<=1)
M.Health -= 1
damage2 = 1
else
M.Health -= damage2
view(6)<<"[M] attack [usr] for [damage2] damage!"
Death()
Death()

mob/proc/Death()
if(src.Health <= 0)
if(!src.client)
view(6)<<"[src] has been killed!"
(src.player)<<"You have lost [src]!"
del(src)
else
src<<"You have been defeated!"
src<<"All your building are now destroyed!"
src<<"And all your men lay dead!"
for(var/mob/M in world)
if(M.player == src.name)
spawn()
del(M)
for(var/obj/O in world)
if(O.name != "Town Center")
if(O.player == src.name)
spawn()
del(O)
world<<"[src] has been defeated!"
alert("Please Wait!")
sleep(170)
src.Health = 1000
src.MaxHealth = 1000
src.Attack = 25
src.Defence = 25
src.Mesatta = 1500
src.Wood = 1200
src.Player = 1
world<<"[src] has started again!"
src<<"<B>You are back</B>!"


The selecting, and moving works fine, but the Attack bit doesn't!

If I want the Attack proc to "activate" I have to click on the mob I want to attack, then the mob I want to attack with, then I get this error:

runtime error: list index out of bounds
proc name: Attack (/mob/proc/Attack)
usr: Goku (/mob)
src: Peasant (/mob/Unit/Peasant)
call stack:
Peasant (/mob/Unit/Peasant): Attack()
Romkabant (/client): Click(Peasant (/mob/Unit/Peasant), Grass (46,16,1) (/turf/Grass))

So how can I get it so than once I have selected my men, and clicked on the thing I want to attack, they Attack it? And preferably until either they, or it die!

~GokuSS4Neo~

P.s. Sorry for the long post, and thank you for your time!
Your Attack() and Death() procs aren't usr-safe. When you use view() like that, it takes usr as a default, so you need to use view(6,src) instead of view(6).

Lummox JR
In response to Lummox JR
Now it uses me as the attacking thing, not my unit. And things can't die!

Here is my code, as chanegd for Lummox's post :
mob/proc/Attack()
var/list/L = new
var/mob/K=locate() in oview(1,src)
if(K)
for(K in oview(1,src))
L+=K
var/mob/M = pick(L)
if(M.colour != usr.colour)
var/damage = usr.Attack - M.Defence
if(damage<=1)
M.Health -= 1
damage = 1
else
M.Health -= damage
view(6,src)<<"[usr] attack [M] for [damage] damage!"
var/damage2 = M.Attack - usr.Defence
if(damage2<=1)
M.Health -= 1
damage2 = 1
else
M.Health -= damage2
view(6,src)<<"[M] attack [usr] for [damage2] damage!"
Death()
Death()

mob/proc/Death()
if(src.Health <= 0)
if(!src.client)
view(6,src)<<"[src] has been killed!"
(src.player)<<"You have lost [src]!"
del(src)
else
src<<"You have been defeated!"
src<<"All your building are now destroyed!"
src<<"And all your men lay dead!"
for(var/mob/M in world)
if(M.player == src.name)
spawn()
del(M)
for(var/obj/O in world)
if(O.name != "Town Center")
if(O.player == src.name)
spawn()
del(O)
world<<"[src] has been defeated!"
alert("Please Wait!")
sleep(170)
src.Health = 1000
src.MaxHealth = 1000
src.Attack = 25
src.Defence = 25
src.Mesatta = 1500
src.Wood = 1200
src.Player = 1
world<<"[src] has started again!"
src<<"<B>You are back</B>!"
In response to Gokuss4neo
You still have usr all over there. Don't put usr in your procs.

Lummox JR
In response to Lummox JR
What should I replace it with?
BTW, thank you for your help so far!

~GokuSS4Neo~
In response to Gokuss4neo
I updated the demo.

ID:210337

You may want to check that out before you get much further.

Wall04
In response to Wall04
I can't download your demo! Everytime I do the Seeker window opens and says : Downloading Selection Demo (3136 bytes). But once it is done, nothing happens! Maker doesn't open or anything!

~GokuSS4Neo~
In response to Gokuss4neo
Gokuss4neo wrote:
I can't download your demo! Everytime I do the Seeker window opens and says : Downloading Selection Demo (3136 bytes). But once it is done, nothing happens! Maker doesn't open or anything!

~GokuSS4Neo~

It should work now.

Wall04
In response to Wall04
HOLY BLOODY ****!!! That is so ****ing SWEET! I must say that that is one of the most impressive demo's I have ever seen (for just a demo)! That will be endlessly useful for all RTS builders!
I just can't believe how good that is! I am still muttering swear words!

But could someone tell me what I should replace Usr with?

~GokuSS4Neo~

P.s. Wall04 you have just got onto my top 10 most respected BYONDers (you're number 6!)
In response to Gokuss4neo
I have replaced my old selecting code with Wall04's new one :
client
var
Select[]=list()
imageslist[]=list()
turf/start
turf/end
Click(atom/movable/object, location)
// if something is selected
if(Select.len)
// give it/them a destination
for(var/mob/Unit/U in Select)
if(U.player == usr.name)
U.destination = object
U.Attack()
Select -= U
for(var/i in src.imageslist)
del(i)
return ..()
MouseDown(object,location)
if(!length(Select))
// if nothing is selected, draw the grid
src.Draw_Grid(location,location)
..()
MouseUp(object,location)
// if there is a selection box, select!
if(start) End_Grid()
..()
MouseDrag(src_object,over_object,src_location,over_location)
// if there is a grid started, expand it
if(start)
Draw_Grid(start,over_location)
..()
proc/Draw_Grid(S,E)
if(!start)
start = S
end = E
for(var/image/I in src.imageslist)
del(I)
var/xd=(end.x-start.x)
var/yd=(end.y-start.y)
src.imageslist += new/image ('Selecting.dmi',locate(start.x,start.y,start.z),"2")
src.imageslist += new/image ('Selecting.dmi',end,"2")
src.imageslist += new/image ('Selecting.dmi',locate(start.x,start.y+yd,start.z),"2")
src.imageslist += new/image ('Selecting.dmi',locate(start.x+xd,start.y,start.z),"2")
for(var/image/I in src.imageslist)
src << I
proc/End_Grid()
var
max_X=max(start.x,end.x)
min_X=min(start.x,end.x)
max_Y=max(start.y,end.y)
min_Y=min(start.y,end.y)
for(var/image/I in src.imageslist)
del(I)
for(var/turf/T in block(locate(min_X,min_Y,1),locate(max_X,max_Y,1)))
var/mob/Unit/M = locate() in T
if(M)
var/image/I = new('Selecting.dmi',M,"1")
Select+=M
src.imageslist+=I
src << I
start = null
end = null


My attack proc is the same as I posted earlier. How should I properly change and call it?
Also, sometimes when I double click I loose the ability to select any more units!
Here is my only use of a DblClick :

turf/Grass/DblClick()
if(usr.cur_building)
if(usr.cur_building == /obj/Building/Hovel)
if(usr.Wood>= 55)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"H[usr.colour]")
usr<<"A Hovel was built!"
usr.Wood -= 55
usr.AVM += "Peasants"
usr.AVPeasants += 2
else
usr<<"You need more wood!"
if(usr.cur_building == /obj/Building/Farm)
if(usr.Wood>= 55)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"F[usr.colour]")
usr<<"A Farm House was built!"
usr.Wood -= 55
usr.AVM += "Farmers"
usr.AVFarmers += 1
else
usr<<"You need more Wood!"
if(usr.cur_building == /obj/Building/Woodstock)
if(usr.Wood>= 15)
if(usr.Mesatta>=150)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"W[usr.colour]")
usr<<"A Woodstock was built!"
usr.Wood -= 15
usr.Mesatta -= 150
else
usr<<"You need more Mesatta"
else
usr<<"You need more Wood!"
if(usr.cur_building == /obj/Building/Market)
if(usr.Mesatta>=100)
if(usr.Wood>= 150)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"Ma[usr.colour]")
usr<<"A Marketplace was built!"
usr.Mesatta -= 100
usr.Wood -= 150
else
usr<<"You need more Wood!"
else
usr<<"You need more Mesatta"
if(usr.cur_building == /obj/Building/Basic_Gym)
if(usr.Wood>= 175)
if(usr.Mesatta>=175)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"BG[usr.colour]")
usr<<"A Basic Gym was built!"
usr.Wood -= 175
usr.Mesatta -= 175
usr.AVM += "Trainees"
usr.AVM += "Fighters"
usr.AVFighters += 1
usr.AVTrainees += 2
else
usr<<"You need more Mesatta"
else
usr<<"You need more Wood!"
if(usr.cur_building == /obj/Building/Dojo)
if(usr.Wood>= 180)
if(usr.Mesatta>=175)
var/obj/O = new usr.cur_building (src)
O.player = "[usr]"
O.overlays += icon('Colours.dmi',"Do[usr.colour]")
usr<<"A Dojo was built!"
usr.Wood -= 175
usr.Mesatta -= 175
usr.AVM += "Zensei"
usr.AVM += "Fighters"
usr.AVFighters += 1
usr.AVZensei += 1
else
usr<<"You need more Mesatta"
else
usr<<"You need more Wood!"
else
usr<<"You need to select a building first!"


Any help would be greatly appreciated!

~GokuSS4Neo~
In response to Gokuss4neo
Please help! I really need this to make my RTS. And I cannot continue until this is finished, which is annoying because I have now been waiting for a very long time!

~GokuSS4Neo~
In response to Gokuss4neo
Post [link]
In response to Airjoe
This is not intended to sound rude, but did you read my other replies/ first post? I have looked through multiple demos, and libraries. (Again not trying to sound rude) And experimented hundreds, literally hundreds of times with my code. I am sure there is a simple way to call my Attack Proc properly and a simple reason for why double click disables my ability to select units. So I was asking, because through all my experimenting I have had no avail!

Also, I was hoping Wall04 might be able to help, seeing as it is all based of his code, therefore no-one would be better suited to answer my questions than him, and next to that would be all you AMAZING elitists (of which in my opinion, you and Lummox Jr both are)

~GokuSS4Neo~

P.s. Thank you for the post reference, I will try to keep it in mind always!
In response to Gokuss4neo
Simple, my guess is that you're over riding the DblClick() option from another mob, obj...etc.
Try putting under your client/DblClick():

client
DblClick()
//stuff here
..()//You need this to call the default action/actions of other mobs that have also been defined.
In response to Goku72
But how should I call the Attack proc? It is quite essential in my game. (Which is quite obvious :P )

I have searched through the forums. I have looked in all the tutorials, and in all the demos but to no avail.

Any help, any help at all would be very gratefully appreciated.

~GokuSS4Neo~
In response to Gokuss4neo
Gokuss4neo wrote:
What should I replace it with?
BTW, thank you for your help so far!

~GokuSS4Neo~

Replace usr with src.