npccreation.src follows;
/*
Created by *Edwards
For FantasiaShard.com
Edwards@FantasiaShard.com
2008-05-27
For the pleasure of Administrator Gambit. This is a present for all your efforts.
*/
use uo;
use os;
include ":gumps:gumps";
include ":gumps:gumps_ex";
include "include/packets";
include "include/yesNo";
include "include/security";
var hint := "NPC Creation for FantasiaShard.";
program command_NPCCreation( mobile )
if( !AuthorizationCode( mobile ))
SendSysMessage( mobile, "Cancelled." );
return 0;
endif
while( Send_Command( mobile ))
SleepMS(10);
endwhile
return 1;
endprogram
function Send_Command( mobile )
var config := ReadConfigFile( ":brainAI:createNPC" );
if( config.errortext )
SendSysMessage( mobile, "Error cannot open <:brainAI:createNPC> --> "+config.errortext );
return 0;
endif
var elem := config["Settings"];
var script_list := GetConfigStringArray( elem, "Elem" );
var num_options := script_list.Size();
//Initialize the gump
var gump := GFCreateGump();
GFClosable( gump, 0 );
//Load Main Background
GFResizePic( gump, 0, 0, GFGetCfgConst( "Defaults", "BackGround" ), 500, 645 );
GFResizePic( gump, 15, 15, GFGetCfgConst( "Defaults", "ForeGround" ), 470, 25 );
GFTextMid( gump, 15, 17, 470, 1720, "Npc Creation" );
//BackgroundAreas
GFResizePic( gump, 15, 45, GFGetCfgConst( "Defaults", "ForeGround" ), 470, 590 );
//Help Button
GFAddButton( gump, 30, 60, 2131, 2131, GF_CLOSE_BTN, 0xA00 );
//Display Hint
GFTextMid( gump, 15, 560, 470, 1720, hint );
GFAddButton( gump, 28, 602, 4017, 4018, GF_CLOSE_BTN, 0xA01 );
GFTextLine( gump, 60, 602, 1153, "Cancel" );
GFAddButton(gump, 445, 602, 4012, 4013, GF_CLOSE_BTN, 0xA02 );
GFTextLine( gump, 400, 602, 1153, "Apply" );
GFPage( gump, 1 );
var npc_prop := array;
var npc_elem := array;
var y_pos := 110;
foreach entry in ( script_list )
//Makes it clear for everyone with spaces...
if( entry == "Space" )
y_pos += 20;
elseif( entry != "Page" ) //Main Info
var param := SplitWords( entry );
GFTextLine( gump, 45, y_pos, 1153, param[2] );
GFResizePic( gump, 250, y_pos, GFGetCfgConst("Backgrounds", "GOLDTRIM" ), 190, 28 );
case( param[1] )
"String":
npc_prop.Append( entry );
npc_elem.Append( GFTextEntry( gump, 255, y_pos+4, 190, 28, 2100 ));
break;
"Int":
npc_prop.Append( entry );
npc_elem.Append( GFTextEntry( gump, 255, y_pos+4, 190, 28, 2100 ));
break;
"NoChoice":
npc_prop.Append( param[3] );
npc_elem.Append( GFTextEntry( gump, 255, y_pos+4, 190, 28, 2100, param[3] ));
break;
"YesNo":
GFTextLine( gump, 145, y_pos, 1153, "0: No 1: Yes" );
npc_prop.Append( entry );
npc_elem.Append( GFTextEntry( gump, 255, y_pos+4, 190, 28, 2100 ));
break;
"Choice":
var list := GetConfigStringArray( config[CStr( param[2] )], "Elem" );
var selection := select_Options( mobile, param[2], list );
npc_prop.Append( param[2] );
npc_elem.Append( GFTextEntry( gump, 255, y_pos+4, 190, 28, 2100, CStr( selection )));
break;
endcase
y_pos += 20;
endif
//Makes it clear for everyone with pages...
if( entry == "Page" && _entry_iter < num_options )
GFAddButton( gump, 30, 90, 0xA92, 0xA93, GF_PAGE_BTN, gump.cur_page+1 );
GFPage( gump, gump.cur_page+1 );
GFAddButton( gump, 40, 90, 0xA90, 0xA91, GF_PAGE_BTN, gump.cur_page-1 );
y_pos := 110;
endif
SleepMS(2);
endforeach
var input := GFSendGump( mobile, gump );
if( input[0xA00] )
return OpenBrowser( mobile, "http://"+SHARD_IP+":5000/pkg/brainAI/index.html" );
elseif( input[0xA01] ) //Cancel Button
return 0;
elseif( input[0xA02] ) //Apply Button
if( !YesNo( mobile, "Save Data?" ));
return 1;
else
if( SaveInput( mobile, input, npc_prop, npc_elem ))
return 0;
endif
endif
endif
return 1;
endfunction
function SaveInput( mobile, byref input, npc_prop, npc_elem )
var props:= array;
var prop:= array;
prop .+ pname;
prop .+ pvalue;
var template;
var size := npc_elem.Size();
var i;
for( i:=1; i <= size; i+=1 )
var result := GFExtractData( input, npc_elem
);
if( i == 1 )
template := result;
else
if( result )
prop.pvalue := result;
else
prop.pvalue := "";
endif
prop.pname := npc_prop;
props := prop;
endif
endfor
var create := AppendConfigFileElem( "npcdesc", "NPCTemplate", template, props );
if( create.errortext )
hint := "Error creatint NPC --> "+create.errortext;
return 0;
endif
UnloadConfigFile( "::npcdesc" );
return 1;
endfunction
function select_Options( mobile, option, list )
//Initialize the gump
var gump := GFCreateGump();
GFClosable( gump, 0 );
//Load Main Background
GFResizePic( gump, 0, 0, GFGetCfgConst( "Defaults", "BackGround" ), 250, 425 );
GFResizePic( gump, 15, 15, GFGetCfgConst( "Defaults", "ForeGround" ), 220, 25 );
GFTextMid( gump, 15, 17, 220, 1720, "Npc Creation" );
//BackgroundAreas
GFResizePic( gump, 15, 45, GFGetCfgConst( "Defaults", "ForeGround" ), 220, 370 );
GFTextMid( gump, 15, 60, 220, 1720, option );
//Cancel Button
GFAddButton( gump, 100, 382, 4017, 4018, GF_CLOSE_BTN, 0xA01 );
GFTextLine( gump, 132, 382, 1153, "Cancel" );
GFPage( gump, 1 );
var num_options := list.Size();
var y_pos := 110;
foreach entry in ( list )
GFTextLine( gump, 45, y_pos, 1153, entry );
GFAddButton( gump, 30, y_pos, 0x837, 0x838, GF_CLOSE_BTN, _entry_iter );
y_pos := y_pos+20;
if ( _entry_iter % 14 == 0 && _entry_iter < num_options )
GFAddButton( gump, 220, 348, 0xA92, 0xA93, GF_PAGE_BTN, gump.cur_page+1 );
GFPage( gump, gump.cur_page+1 );
GFAddButton( gump, 220, 95, 0xA90, 0xA91, GF_PAGE_BTN, gump.cur_page-1 );
y_pos := 110;
endif
SleepMS(2);
endforeach
var input := GFSendGump( mobile, gump );
if( input[0xA01] )
return "";
endif
input := input[0];
return list[input];
endfunction