Sauerworld Forum

Simple selection commands to expand map editing possibilities in Sauer


  • **
  • 92
  • +22/-1
    • Projects by Salatiel
Hello, these are 4 new functions, the goal is to expand the possibilities of map editing using cubescript.

editinview variable, if 0 the player can edit even if the selection is off the screen, if 1 edit is blocked if the selection is off screen, default is 1.

getselpos command is based on the getcampos command, and returns the position of the current edit selection.

setselpos command sets the position of the edit selection based on 3 int values ​​(x, y, z), if a current selection does not exist, it will be created.

movesel command moves the edit selection toward a direction.
First argument is the number of cubes to move (-1, 1).
Second argument is the direction (0 = x, 1 = y, 2 = z).
/movesel 1 2 will move the selection 1 cube up.

Code: [Select]
VARP(editinview, 0, 1, 1);
bool noedit(bool view, bool msg)
    if(!editmode) { if(msg) conoutf(CON_ERROR, "operation only allowed in edit mode"); return true; }
    if(view || haveselent()) return false;
    float r = 1.0f;
    vec o = sel.o.tovec(), s = sel.s.tovec();
    s.mul(float(sel.grid) / 2.0f);
    r = float(max(s.x, max(s.y, s.z)));
    bool viewable = (isvisiblesphere(r, o) != VFC_NOT_VISIBLE);
    //if(!viewable && msg) conoutf(CON_ERROR, "selection not in view");
    //return !viewable;
    if(!viewable && editinview && msg) {conoutf(CON_ERROR, "selection not in view");}
    if (editinview){return !viewable;} else {return false;}

ICOMMAND(getselpos, "", (),
    defformatstring(pos)("%s %s %s", floatstr(sel.o.x), floatstr(sel.o.y), floatstr(sel.o.z));

void setselpos(int* posx, int* posy, int* posz)
    if(noedit(moving!=0)) return;
    if(!havesel){havesel = true;};
    sel.o.x = *posx - *posx % gridsize;
    sel.o.y = *posy - *posy % gridsize;
    sel.o.z = *posz - *posz % gridsize;
COMMAND(setselpos, "iii");

void movesel(int *dir, int *pface)
    if(noedit(moving!=0)) return;
    if((*pface > 2) || (*pface < 0)) return;
    int s = *dir;
    sel.o[*pface] += s*sel.grid;
COMMAND(movesel, "ii");

Where to install it
These commands goes somewhere after line 90 in the original file (src/engine/octaedit.cpp, before VARF(gridpower, 0, 3, 12... ).
Be careful to not multiply the bool noedit function, it already exists (line 149), you can replace it entirety.
Or you can download the octaedit.cpp file below.

feel free to leave your feedback :D