PenUltima Online

It is currently Fri Sep 05, 2008 11:37 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: .flip (Replacement for 096)
PostPosted: Mon Oct 23, 2006 2:32 pm 
Offline

Joined: Wed May 10, 2006 5:15 pm
Posts: 113
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.

Image

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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:08 am 
Offline

Joined: Wed Aug 30, 2006 5:24 pm
Posts: 82
Location: Italy
mm and a flip cfg? Is in pol standard distro?

_________________
Admin/Scripter Innominabile
ZuluHotelItalia shard on m4d


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 11:55 am 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1122
Location: Southern Central USA
Find it in the POL 97 SVN download. Under \pkg\commands\config I believe

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:08 pm 
Offline

Joined: Wed May 10, 2006 5:15 pm
Posts: 113
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 4:31 am 
Offline

Joined: Wed Aug 30, 2006 5:24 pm
Posts: 82
Location: Italy
Thanks.
If it is on pol096 svn distro I can have the file from there :-)))

_________________
Admin/Scripter Innominabile
ZuluHotelItalia shard on m4d


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 10:31 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 405
Location: San Diego, California
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

_________________
-Austin


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 3:58 pm 
Offline

Joined: Wed May 10, 2006 5:15 pm
Posts: 113
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.)


Attachments:
File comment: Contains:
-&gt;flip.cfg (180 KB)

flip.zip [26.83 KiB]
Downloaded 37 times
Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 7:08 am 
Download removed. No longer available.


Last edited by Marilla on Sun Dec 17, 2006 8:55 am, edited 1 time in total.

Top
  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 10:50 am 
Offline

Joined: Wed May 10, 2006 5:15 pm
Posts: 113
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl