.flip (Replacement for 096)

Post your Custom Scripts or Packages.
Post Reply
SMJ
Grandmaster Poster
Posts: 113
Joined: Wed May 10, 2006 5:15 pm

.flip (Replacement for 096)

Post by SMJ »

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: Select all

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  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?
innominabile
Adept Poster
Posts: 85
Joined: Wed Aug 30, 2006 5:24 pm

Post by innominabile »

mm and a flip cfg? Is in pol standard distro?
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Find it in the POL 97 SVN download. Under \pkg\commands\config I believe
SMJ
Grandmaster Poster
Posts: 113
Joined: Wed May 10, 2006 5:15 pm

Post by SMJ »

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.
innominabile
Adept Poster
Posts: 85
Joined: Wed Aug 30, 2006 5:24 pm

Post by innominabile »

Thanks.
If it is on pol096 svn distro I can have the file from there :-)))
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

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-d ... iew=markup
SMJ
Grandmaster Poster
Posts: 113
Joined: Wed May 10, 2006 5:15 pm

Post by SMJ »

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

flip.src

Code: Select all

/*
 * @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: Select all

/**
 * @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
flip.zip
Contains:
-&gt;flip.cfg (180 KB)
(26.83 KiB) Downloaded 625 times
Marilla

Post by Marilla »

Download removed. No longer available.
Last edited by Marilla on Sun Dec 17, 2006 8:55 am, edited 1 time in total.
SMJ
Grandmaster Poster
Posts: 113
Joined: Wed May 10, 2006 5:15 pm

Post by SMJ »

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 Reply