SphereCommunity
Fixing wrong Z position - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Submissions (/Forum-Script-Submissions)
+--- Thread: Fixing wrong Z position (/Thread-Fixing-wrong-Z-position)



Fixing wrong Z position - escribano - 07-19-2017 01:59 AM

Have you ever tried to create an object/mobile at random places and figured out your items has been added underground? or get stuck trying to detecting the correctly Z point to add some item?

Ok... me too! but not anymore!!!

Code:
[FUNCTION f_fix_z]
local.z = <z>
local.tz = <serv.map(<p.x>,<p.y>).terrain.z>

if (<abs <eval (<local.z> - <local.tz>)>> < 10)
    z <local.tz>
else
    local.z <local.tz>
    for x 1 <serv.map(<p.x>,<p.y>).statics>
        if (<abs <eval (<local.z> - <serv.map(<p.x>,<p.y>).statics.<local.x>.z>)>> < 10)
            local.z <serv.map(<p.x>,<p.y>).statics.<local.x>.z>
        endif
    endfor

    z <local.z>
endif

To use it, just need to call in any item or mobile after create at the desired position...

The script will try to detect the correct Z position at X,Y based on:

- The land Z point
- The item Z point before the function (in case the item is added in structures with more than 1 floor)
- The possible view/climbable height

So... there is a lot do in this script, but.... it helped me A LOT!


RE: Fixing wrong Z position - amonvangrell - 07-19-2017 07:20 AM

Nice!


RE: Fixing wrong Z position - escribano - 07-21-2017 05:15 AM

Thanks Amon!!!

Hope it helps Smile


RE: Fixing wrong Z position - oozy - 03-22-2018 10:27 PM

Really helpful thing. But what with situation when we have more than one static items in on location? Maybe f_fix_z function need something like that?
Code:
IF (<SERV.MAP(<p.x>,<p.y>).STATICS>)
FOR X 1 <SERV.MAP(<p.x>,<p.y>).STATICS>
LOCAL.Z=<EVAL <DLOCAL.Z>+<SERV.MAP(<p.x>,<p.y>).STATICS.<DLOCAL.X>.Z>>
ENDFOR
ENDIF