PenUltima Online Forum Index Official Core: 096.7
Official Core: 097 2008-02-26
Donate towards the POL web hosting bill!
 POL Home   FAQ   Search    Memberlist   Usergroups    Register    Profile   Log in to check your private messages   Log in
.flip (Replacement for 096)

 
Post new topic   Reply to topic    PenUltima Online Forum Index -> Custom Script Releases
Display posts from previous:   

Author Message
SMJ



Joined: 10 May 2006
Posts: 113

PostPosted: Mon Oct 23, 2006 6:32 pm    Post subject: .flip (Replacement for 096) Reply with quote

I was putting together a custom flip.cfg, and I noticed that the 096 .flip command had a lousy system for large flipping "cycles" (I have some items that can flip in excess of 20 times, that would take forever!) so I ended up writing a gump-based replacement.



Code:

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  name:    flip.src - Player Textcommand
//  version: 2.0
//  author:  SMJ
//
//  Purpose: Changes the orientation of a piece of furniture
//
////////////////////////////////////////////////////////////////////////////////////////////////////
use uo;
use cfgfile;

program flip (me)

   var flipConfig := ReadConfigFile("::flip");
   var furniture;
   var flipGraphic;

   if( TypeOf(me) == "Array" )
      furniture := me[2];
      me := me[1];
   endif

   if(furniture)
      flipGraphic := flipConfig[CInt(furniture.graphic)].ChangeTo;
   else
      SendSysMessage(me, "Flip what?");
      furniture := Target(me);

      if(!furniture)
         SendSysMessage(me, "Cancelled.");
         return 0;
      endif

      if(!furniture.isA(POLCLASS_ITEM))
         SendSysMessage(me, "You cannot flip that!");
         return 0;
      endif
   
      if(furniture.movable == 0)
         SendSysMessage(me,"That is locked down.");
         return 0;
      endif

      var myGraphic := furniture.graphic;
      var newGraphic;
      var graphicArray := {};
      var i := 1;
      if(flipConfig)
         while( (i < 100) && (myGraphic != newGraphic) )
            if(!newGraphic)
               newGraphic := myGraphic;
            endif

            newGraphic := flipConfig[CInt(newGraphic)].ChangeTo;
            if(newGraphic != myGraphic)
               graphicArray[i] := newGraphic;
               i := i+1;
            endif
         endwhile
      endif
   
      var flipmenu := CreateMenu("Select a new orientation:");
      var j;
      for(j:=1;j<i;j:=j+1)
         AddMenuItem(flipmenu,CInt(graphicArray[j]),furniture.name);
      endfor
      var selection := SelectMenuItem2(me,flipmenu);
      if(!selection)
         SendSysMessage(me,"Canceled.");
         return 0;
      endif
      flipGraphic := CInt(selection.graphic);
   endif
   furniture.graphic := flipGraphic;
endprogram


Questions? Comments? Fixes?

Author Message
innominabile



Joined: 30 Aug 2006
Posts: 81
Location: Italy

PostPosted: Thu Oct 26, 2006 9:08 am    Post subject: Reply with quote

mm and a flip cfg? Is in pol standard distro?

Author Message
Yukiko



Joined: 02 Feb 2006
Posts: 1094
Location: Southern Central USA

PostPosted: Thu Oct 26, 2006 3:55 pm    Post subject: Reply with quote

Find it in the POL 97 SVN download. Under \pkg\commands\config I believe

Author Message
SMJ



Joined: 10 May 2006
Posts: 113

PostPosted: Thu Oct 26, 2006 9:08 pm    Post subject: Reply with quote

It's also in the 096 distro- but I didn't know if I should post it or not; it's rather long. I went through InsideUO to get the flip-graphics, so if you want it, I'll post it.

Author Message
innominabile



Joined: 30 Aug 2006
Posts: 81
Location: Italy

PostPosted: Sun Oct 29, 2006 8:31 am    Post subject: Reply with quote

Thanks.
If it is on pol096 svn distro I can have the file from there Smile))

Author Message
Austin
POL Developer


Joined: 30 Jan 2006
Posts: 354
Location: San Diego, California

PostPosted: Sun Oct 29, 2006 2:31 pm    Post subject: Reply with quote

Its a really good idea, and if you make a version that matches the style guide in the distro, I will put it in.

http://svn.sourceforge.net/viewvc/pol-distro/releases/097/Distro/docs/StyleGuide.txt?view=markup

Author Message
SMJ



Joined: 10 May 2006
Posts: 113

PostPosted: Sun Oct 29, 2006 7:58 pm    Post subject: Reply with quote

Okay, here's the revised version, I followed the style guide the best I could.

flip.src
Code:
/*
 * @AUTHOR   Steven Jimenez [SMJ]
 * @DATE   October 29, 2006
 *
 * @NAME   flip.src
 * @VERSION   2.0
 *
 * @PARAM[me]   Can contain a character reference, or an array
 *      holding a character reference and the object to
 *      be flipped.
 *
 * @RETURN   1 on completion.
 *       0 on failure.
 */

use cfgfile;
use os;
use uo;

CONST FLIP_CONFIG_FILE := ("::flip");

program textcmd_flip (me)
   var flip_config := ReadConfigFile(FLIP_CONFIG_FILE);
   var object;
   var who;
   var flip_graphic;

   if(!flip_config)
      SysLog("Error: "+FLIP_CONFIG_FILE+" does not exist!");
      return 0;
   endif

   if( TypeOf(me) == TypeOf( array{} ) )
      object := me[2];
      who := me[1];
   else
      who := me;
      SendSysMessage(who,"Flip what?");
      object := Target(who);
   endif

   if( !object )
      SendSysMessage(who,"Cancelled.");
      return 0;
   endif

   if( !(object.isA(POLCLASS_ITEM)) )
      SendSysMessage(who,"You cannot flip that!");
      return 0;
   endif
   
   if( object.movable == 0 )
      SendSysMessage(who,"That is locked down.");
      return 0;
   endif

   var object_graphic := object.graphic;
   var new_obj_graphic;
   var graphic_array := {};
   var i := 1;

   while( (i < 100) && (object_graphic != new_obj_graphic) )
      if(!new_obj_graphic)
         new_obj_graphic := object_graphic;
      endif
      new_obj_graphic := flip_config[CInt(new_obj_graphic)].ChangeTo;
      if(new_obj_graphic != object_graphic)
         graphic_array[i] := new_obj_graphic;
         i := i+1;
      endif
   endwhile

   var flip_menu := CreateMenu("Select a new orientation:");
   var j;
   for(j:=1;j<i;j:=j+1)
      AddMenuItem(flip_menu,CInt(graphic_array[j]),object.name);
   endfor
   var selection := SelectMenuItem2(who,flip_menu);
   if(!selection)
      SendSysMessage(who,"Canceled.");
      return 0;
   endif
   flip_graphic := CInt(selection.graphic);

   object.graphic := flip_graphic;
   return 1;
endprogram


And if you needed to make your own flip.cfg file, here's the source to a little program I wrote to loop large groups of objects together:

fliploop.cpp (This one requires a C++ Compiler.)
Code:
/**
 * @AUTHOR  Steven Jimenez [SMJ]
 * @DATE    October 21, 2006
 *
 * @FILE    file.cpp
 * @VERSION 1.0
 */

#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>

/**
 * std::string toHex(int integer)
 *
 * @PARAM   Integer to convert to hex value.
 * @RETURN  String of hex equivalent of parameter "integer".
 */

std::string toHex(int integer) {
    std::string ret;
    char num;

    do {
        switch(integer%16) {
            case 15:
                num = 'F';
                break;
            case 14:
                num = 'E';
                break;
            case 13:
                num = 'D';
                break;
            case 12:
                num = 'C';
                break;
            case 11:
                num = 'B';
                break;
            case 10:
                num = 'A';
                break;
            case 9:
                num = '9';
                break;
            case 8:
                num = '8';
                break;
            case 7:
                num = '7';
                break;
            case 6:
                num = '6';
                break;
            case 5:
                num = '5';
                break;
            case 4:
                num = '4';
                break;
            case 3:
                num = '3';
                break;
            case 2:
                num = '2';
                break;
            case 1:
                num = '1';
                break;
            default:
                num = '0';
                break;
        }
        ret += num;
        integer /= 16;
    } while (integer);
    reverse(ret.begin(), ret.end());
    return ret;
}

/**
 * int main(VOID)
 *
 * @RETURN  0 on completion.
 */

int main() {
    int start, end, temp;
    std::string filename;
    std::string output;

    while(1) {
        system("CLS");
        std::cout << "Start: ";
        std::cin >> start;
        std::cout << "End: ";
        std::cin >> end;
        end++;

        if(start < end) {
            temp = end;
            end = start;
            start = temp;
        }
        else if(start == end) {
            return 1;
        }

        filename = "items["+toHex(start)+"-"+toHex(end)+"].txt";
        std::fstream file_op(filename.c_str(),std::ios::out);

        output = "";
        for(int i=start; i<end; i++) {
            output+= "FLIP 0x"+toHex(i)+"\n";
            output+= "{\n";
            if(i==end-1)
                output+= "\tChangeTo 0x"+toHex(start)+"\n";
            else
                output+= "\tChangeTo 0x"+toHex(i+1)+"\n";
            output+="}\n";
        }

        std::cout << (end-start) << " entries printed.\n";
        file_op << output << "###########\n";
        file_op.close();
        system("PAUSE");
    }
    return 0;
}


I've attatched my flip.cfg (Goes in /pol/config), but it's huge (Thus why I wrote a program to help out.)



flip.zip
 Description:
Contains:
->flip.cfg (180 KB)

Download
 Filename:  flip.zip
 Filesize:  26.83 KB
 Downloaded:  33 Time(s)


Author Message
Marilla



Joined: 02 Feb 2006
Posts: 329

PostPosted: Tue Oct 31, 2006 11:08 am    Post subject: Reply with quote

Download removed. No longer available.

Last edited by Marilla on Sun Dec 17, 2006 12:55 pm; edited 1 time in total

Author Message
SMJ



Joined: 10 May 2006
Posts: 113

PostPosted: Tue Oct 31, 2006 2:50 pm    Post subject: Reply with quote

That works lol

I may be using YOUR version from now on ^.^

The bug about the start/end variables was just a hack-in just before I posted it. I didn't have it in my version, but that's because I knew it'd break if I did.

Post new topic   Reply to topic    PenUltima Online Forum Index -> Custom Script Releases All times are GMT - 4 Hours
Page 1 of 1

 




Powered by phpBB © 2001, 2005 phpBB Group :: Theme & Graphics by GHS & Scott E. Royalty