NPC Creation

Post your Custom Scripts or Packages.

Moderator: POL Developer

Post Reply
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

NPC Creation

Post by *Edwards »

Of course, I hope few of you will enjoy this command. It gives the power to create NPC directly in-game via a nice display of text entries, arrows and touch button ;)

Warning: the command itself is not packaged, you will have to edit your own properties for your NPCs so it will fit with YOUR reality and you will have to set your "spaces" between the options.

Well, afterall it works, it's really basic and completely useless if you are alone on your shard.

I would rate this command 4/10.

Edited: The requirments are the gumppackage that you will find with distro097


Updated 2009-05-16
Attachments
NPCCreation.rar
(4.32 KiB) Downloaded 634 times
Last edited by *Edwards on Fri May 15, 2009 3:53 pm, edited 2 times in total.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Post by *Edwards »

Alright, just to let everyone knows that the code has been updated..
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Post by ncrsn »

Nice - you did what I was going to propose.
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Post by coltain »

Nice, thx

btw
I added reloadconfiguration() after applying data to npcdesc.cfg
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Post by *Edwards »

Thanks, I will have to modify it so you can select the option via menu for most of the options given... Well something that could be truly done all via in-game. To be updated ^^
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: NPC Creation

Post by *Edwards »

Final.
Pachacuti
Apprentice Poster
Posts: 51
Joined: Fri Jun 12, 2009 8:57 am

Re: NPC Creation

Post by Pachacuti »

I dont know what the shit I'm doing...

I'm geting an error while compiling.

Code: Select all

Compiling: c:/POL/Distro/pkg/commands/gm/NPCCreation.src
Unable to read include file 'c:\POL\Distro\pkg\commands\gm\include/yesNo.inc'
Compilation failed.
Execution aborted due to: Error compiling file
It says that it cant read the file "yesNo.inc"

What I did wrong?

PS: Note that I'm a real newbie

EDIT: I'm using pol 097
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: NPC Creation

Post by Pierce »

Pol says that it can't find the yesNo.inc include file.
There could be several reasons depending on your used system (linux or windows).

The first reason maybe that there is no yesNo.inc file in the directory
c:\POL\Distro\pkg\commands\gm\include/

Another reason if you use e.g. linux could be the spelling of the file. With linux it has to be named yesNo.inc (not yesno.inc or YesNo.inc .....)

For that file i suggest (if you have it) to put it into pkg/scripts/include/ and name it yesno.inc.
And change the include line inside the script to
include "include/yesno";

In that case you'll never have a windows/linux compile error again. If you use both.
Surely you have to do this to all scripts that call yesno.inc :D
Pachacuti
Apprentice Poster
Posts: 51
Joined: Fri Jun 12, 2009 8:57 am

Re: NPC Creation

Post by Pachacuti »

i think it worked now, but maybe with some bugs.

I copyed the file "yesno.inc" and the "packets.inc" to the same directory of "npccreation.src" and changed the include to:

Code: Select all

include "packets";
include "yesno";
I couldn't find the "security.inc" anywhere so I simple erased the code that used one of it's functions and erased it's include.
Other error I got was with the http part, so I simply erased this part too =D

I think it's working now, but it could have a better explanation of each parameter, cause I'm a little lost.
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: NPC Creation

Post by CWO »

it didn't find them because in order to find them in pol/scripts/include, you need to make it

Code: Select all

include "include/packets";
include "include/yesno";
cockneybloke
New User
Posts: 4
Joined: Mon Jun 17, 2013 2:08 pm

Re: NPC Creation

Post by cockneybloke »

Hi
I know this is an old post but should this script work on POL 99?

I have POL 099 with the full distro and get the following error when trying to compile;


C:\POL server\scripts>ecompile
EScript Compiler v1.12
Copyright (C) 1993-2009 Eric N. Swanson

Compiling: C:/POL server/pkg/commands/admin/NPCCreation.src
Variable SHARD_IP has not been declared on line 132.
Error compiling statement at C:\POL server\pkg\commands\admin\NPCCreation.src, Line 132
Error in IF statement starting at File: C:\POL server\pkg\commands\admin\NPCCreation.src, Line 131
Error compiling statement at C:\POL server\pkg\commands\admin\NPCCreation.src, Line 131
Error in function 'Send_Command', File: C:\POL server\pkg\commands\admin\NPCCreation.src, Line 132

Error in function 'Send_Command'.
File: C:\POL server\pkg\commands\admin\NPCCreation.src, Line 132
Execution aborted due to: Error compiling file

C:\POL server\scripts>



Cheers in adv. :)
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: NPC Creation

Post by RusseL »

you should add consts in your scripts/modules/uo.em

Code: Select all

const SHARD_IP					:= 1.1.1.1; // your ip here
const SHARD_WWWPORT				:= 1; // your port here
cockneybloke
New User
Posts: 4
Joined: Mon Jun 17, 2013 2:08 pm

Re: NPC Creation

Post by cockneybloke »

Thanks for that RusseL, seems to have cleared that error but now I have a new one after I added those const's to scripts/modules/uo.em and now find the following error when trying to compile;

Compiling: C:/POL server/pkg/commands/admin/NPCCreation.src
Exception Detected:
Expected an identifier to follow the member (.) operator.
Compilation failed.
Execution aborted due to: Error compiling file

C:\POL server\scripts>


Thanks
PS Im a techie but not a coder (though I'm learning quick!) so apologies if this seems a bit simple!
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: NPC Creation

Post by RusseL »

Typo anywhere. Show us your code
cockneybloke
New User
Posts: 4
Joined: Mon Jun 17, 2013 2:08 pm

Re: NPC Creation

Post by cockneybloke »

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
Agata
Journeyman Poster
Posts: 63
Joined: Sun Oct 30, 2011 6:33 am

Re: NPC Creation

Post by Agata »

shouldn't it be "1.1.1.1" instead of just 1.1.1.1?
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: NPC Creation

Post by RusseL »

Agata wrote:shouldn't it be "1.1.1.1" instead of just 1.1.1.1?
it works for me without quotes, but cockney, try it with quotes
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: NPC Creation

Post by Yukiko »

RusseL wrote:you should add consts in your scripts/modules/uo.em

Code: Select all

const SHARD_IP					:= 1.1.1.1; // your ip here
const SHARD_WWWPORT				:= 1; // your port here
It's probably not a good idea to add things to the *.em files. It's better to add constant definitions to an include file that you can include where needed. The *.em files are files generated when the Core is compiled. You most likely won't cause any problems by modifying the *.em files but every time you update POL to a new version you will have to remember to add the changes into the *.em files for the updated Core.
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: NPC Creation

Post by RusseL »

Yukiko wrote: It's probably not a good idea to add things to the *.em files.
why not? i have many new functions and constants there. This files were created to store such things :)
Tomi
POL Developer
Posts: 478
Joined: Tue Feb 21, 2006 5:08 pm

Re: NPC Creation

Post by Tomi »

Its true that it makes life easier to add stuff like that into .em files but if/when the .em files changes you have to modify them manually.
We could add a custom.em without any hardcoded constants or core functions to be a file to use instead of includes
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: NPC Creation

Post by Yukiko »

RusseL wrote:
Yukiko wrote: It's probably not a good idea to add things to the *.em files.
why not? i have many new functions and constants there. This files were created to store such things :)
I explained why in my post. As I said, you probably won't cause any problems but as I said and Tomi repeated, every time the Core gets updated you have to re-enter your changes to whatever *.em files you have modified. If you don't mind that issue then there's no problem.

Tomi, I am curious. Why do the devs have to provide a custom.em file? Can't we just create one in the \modules directory and add stuff to it or will POL complain about an unknown *.em file being present?
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: NPC Creation

Post by CWO »

Tomi wrote:Its true that it makes life easier to add stuff like that into .em files but if/when the .em files changes you have to modify them manually.
We could add a custom.em without any hardcoded constants or core functions to be a file to use instead of includes
I know its still a bit of an old topic. Hopefully you haven't bothered doing anything to this effect yet. That's what something like

Code: Select all

include "include/constants";
is for...

--- The Coding Practice Nazi has struck again ---
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: NPC Creation

Post by Yukiko »

Right CWO. I haven't looked at the POL 0.99 "Distro" closely so I can't speak for it but the older Distros had a file named "client.inc" which contained constant definitions for such things as sounds, animations etc. Some of us have created our own custom include files such as your "constants.inc" for just such a purpose. I suppose one could just create a "constants.em" file if they wanted to but that breaks the consitency of the POL file system hierarchy.

Anyway, always good to hear your take on things CWO. You've certainly helped me pull my bacon out of the fire a few times.
Post Reply