ID:1299066
 
(See the best response by Super Saiyan X.)
Code:
//Target Control
mob
Click()
var/C = src
if (usr == src)
return 0
if(src==usr.target)
return 0
else
usr:Target(C)
return 1

//Attack and Defend Controls
client
Click(object,location,control,params)
var/list/p = params2list(params)

if(p["right"]) //If it was a right-click, then defend
usr.defend()

else //If not a right-click....

if(..()) //If overriden by other procs(namely the targetting proc), return
return
else //If not overriden, initiate an attack
usr.attack()


Problem description:

So this is the bit of code I came up with to allow players to use their mouse for a few basic combat verbs. Basically clicking a mob targets it, clicking anywhere initiates an attack, and right-clicking makes them defend.

Now, there are no loose ends within the verbs themselves because using the verbs without mouse clicks causes no issues. However, after using a mouseclick to iniate any of these verbs, I find my mob's movement frozen. I can do anything but move. Does anyone have any clue as to what may be causing this?


Can you show us these procs you are calling?
usr.defend()
usr.attack()


Be sure to provide those procs as they may be the cause of your problem.
//Combat Verbs
mob/verb

attack()
set name = "Attack"
if(usr.busy == 0)
if(usr.chi>maxchi/100)
for(var/mob/m in get_step(src, usr.dir))
if(m.health> 0)
usr.busy = 1
usr.attacking = 1
m.Factor_LF()
usr.Factor_LF()
flick("punch1",src)
var/dmg = ((usr.lf/usr.baself)*usr.str)/((m.lf/m.baself)*m.end)
if(dmg<0)
dmg = 0
m.Damage(dmg,m,usr)
m.Factor_LF()
usr.chi-= maxchi/100
usr.Factor_LF()
spawn(14)
usr.busy = 0
usr.attacking = 0

defend()
set name = "Block"
if(usr.busy==0)
blocking = 1
busy = 1
flick("Block",src)
spawn(14)
blocking = 0
busy = 0


But as previously stated, the verbs work when not called by mouseclicks.
for(var/mob/m in get_step(src, usr.dir))

wat.

And also, do you have client/Click() set to return 0 by default? Because otherwise you're never going to attack because ..() will always return 1.
//Target Control
mob
Click()
var/C = src
if (usr == src)
return 0
if(src==usr.target)
return 0
else
usr:Target(C)
return 1


The way I have it set up is if you click, and it's a mob and it targets someone, it returns 1. So if mob/Click() returns 1, as opposed to 0, then client/Click() does nothing else. So, in other words, if I click to target someone, on that specific click, it doesn't attack.

As for the "for(var/mob/m in get_step(src, usr.dir))" that just checks to see if someone is in their next step/direction and if so, then it attacks.
In response to Khye
I realize what it does, I'm wondering why you used src and usr in the same line.
What happens if you right click without targeting someone, can you still move?

Click()
var/C = src
if (usr == src)
return 0
if(src==usr.target)
return 0
else
usr:Target(C)
return 1


I understand that you have var/C = src, but I find that to be buggy, and byond likes it best if you pass things by reference than by direct association of src or usr.
You are not telling it that there is an arg so try doing:

Click(mob/tAttack)
if(tAttack == usr)
return 0
if(tAttack == usr.target)
return 0
else
usr:Target(tAttack)
return ..()


I suggest returning ..() instead of just 1 as there may be some hidden functionality of Click() that may be causing the lock up, and by returning ..() you allow that the finish out.
mob/Click() means that src is the mob clicked and usr is the clicker.
Yes, but it could think that the src is the turf and not the mob, and maybe that is causing the error. Have you changed the mob's bounding boxes at all? What happens if you click on something other than a mob?

Using the argument method allows you to do a bit more control on what the Click() should be looking for as there is nothing specifying what to do if it is not a mob that is clicked on.
if(ismob(src))
Do you see that in his code above?
I could give a smart retort about how you didn't suggest it to him as well, so let's not start that.
No, I haven't used if(ismob(src)). And no, I haven't messed with the bounding boxes. If I click on anything other than a mob, then it attacks. If I click a mob, it targets it. If I click a mob I've already targeted, it attacks also.


Perhaps something I should mention is that this movement freezing wasn't an issue until I added in:

client
Click(object,location,control,params)
var/list/p = params2list(params)

if(p["right"]) //If it was a right-click, then defend
usr.defend()


After adding in this specific portion and selecting "Send right-clicks to mouse procs" in the map control. Up until that point, it worked smoothly.

I just tried using your method, Akando, and now that I think about it, it's probably a safer way to go about it, but I'm getting the same issue.
Make sure you to add :

..() after the usr.defend() because you are not giving the proc a way of exiting when it goes down that tree so it just stays there unsure what to do.
Noted and done. ^^
Did that work?
It didn't resolve the issue sadly.
If you right click does it stop your movement, or only when you target something?
else            //If not overriden, initiate an attack
usr.attack()



add ..() after usr.attack() also
Page: 1 2