 |
 |
 |
 |
| Author |
Message |
SMJ
Joined: 10 May 2006 Posts: 113
|
Posted: Mon Oct 23, 2006 6:32 pm Post subject: .flip (Replacement for 096) |
|
|
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 |
Austin POL Developer
Joined: 30 Jan 2006 Posts: 354 Location: San Diego, California
|
|
 |
|
|
 |
 |
| Author |
Message |
SMJ
Joined: 10 May 2006 Posts: 113
|
Posted: Sun Oct 29, 2006 7:58 pm Post subject: |
|
|
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.)
| Description: |
Contains: ->flip.cfg (180 KB) |
|
 Download |
| Filename: |
flip.zip |
| Filesize: |
26.83 KB |
| Downloaded: |
33 Time(s) |
|
|
 |
|
|
 |
 |
|