SphereCommunity
Distance @timer - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Distance @timer (/Thread-Distance-timer)



Distance @timer - Rizz - 04-26-2015 06:29 AM

PHP Code:
ON=@TIMER



IF (<link.action>==Skill_Magery)
    
TIMERD=10
    LOCAL
.distance= <ref1.distance <ref2> >
    
serv.b distance<dLOCAL.distance>
    return 
1
ENDIF
return 


I can't say it's not working but... it gives me 1520+<distance>
Did i wrong something lol?

I tried this way:

PHP Code:
[FUNCTION f_magery_target_distance]
ref1=<argn1>
serv.b name <name> <ref1.name>
serv.b distance <ref1.distance>

ON=@timer
link
.f_magery_target_distance <ref1

The function works in game but doesn't work if i call from the @timer trigger


RE: Distance @timer - Coruja - 04-26-2015 07:49 AM

REFx is not a global reference to an object, so you must define it again when using on @Timer

Code:
ON=@Timer
LINK.f_magery_target_distance <REF1>
this probably can get the LINK reference without problems but not the REF1 because there's no REF1 set (so it will be 0)

PS: you can't use triggers directly inside [functions] templates Tongue


RE: Distance @timer - Rizz - 04-26-2015 08:09 AM

Refx are set under @timer, i just didn't copy here, i know they are not global lol

Infact the funcion works and gives me the two names but cannot resolve the coord.

The originale one is:

PHP Code:
on=@timer
ref1
=<tag0.target>
...
..
.
link.f_magery_target_distance <ref1
...
..


And as i told you, the serv.b names works correctly but not the distance.


RE: Distance @timer - XuN - 04-27-2015 02:56 AM

<argn> means ARG Numeric while <args> means ARG String (fast explanation), since UIDs are hexadecimal values and also have strings the argn value will not be read probably, use <args> instead, <argv0> or <argv[0]>.


RE: Distance @timer - Rizz - 04-27-2015 03:43 AM

Still the same problem, i cannot get the distance:

Can't resolve <ref1.distance>

It works only if i type in game .f_magery_target_distance <uid>


RE: Distance @timer - Rizz - 04-27-2015 05:22 AM

I decided to fix in this way:

Code:
[FUNCTION f_magery_target_distance]
ref1=<args>
// serv.b names <name> <ref1.name>
// serv.b distance <ref1.distance>
LOCAL.deltax=<eval <ref1.p.x>-<p.x>>
LOCAL.deltay=<eval <ref1.p.y>-<p.y>>
serv.b components <dLOCAL.deltax> <dLOCAL.deltay>
LOCAL.sum=(<LOCAL.deltax>*<LOCAL.deltax>) + (<LOCAL.deltay>*<LOCAL.deltay>)
LOCAL.hdistance=<eval SQRT(<LOCAL.sum>)>
serv.b handmade distance <dLOCAL.hdistance>


Normal distance and distance found in that way is almost the same but sometimes they have a difference of 1 tile.
Is a truncation problem?
How sphere calculates it?

Is just a difference between p.x and p.y and you take the biggest one?