logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Spawn Plugin v106.108.1.1
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Jun 27, 2007 11:44    Post subject: Spawn Plugin v106.108.1.1 Reply with quote

Check it here...

Spawn Plugin v106.108.1.1
Requires NWNX4 v1.08

The Spawn Plugin gives your server access to many command options.

You can run a Program, execute a command or even look at your environment settings.

SpawnEnvironment(string sEnvVariable)
SpawnProgram(string sProgramName)
SpawnCommand(string sCommand)

but to do this there are some 'tricks' that you need to master...

SpawnEscape(string sString)
- changes the '|' character to a '\' character so you can enter PATH strings
- eg SpawnEscape("c:|temp") = "c:\temp"
SpawnQuote(string sString)
- provides double quotes around a string (with double-ups)
- eg SpawnQuote("string") = "string" (literally, with quote characters)

It will take some time to master, especially getting the quotes right, but once you have it...

Cheers
Gryphyn
Back to top
View user's profile Send private message
nosfe



Joined: 25 Apr 2007
Posts: 22

PostPosted: Wed Jun 27, 2007 20:27    Post subject: Reply with quote

hello, please enter the examples Smile because it is not documented lol
thanks
i want anderstand alllll ^^
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu Jun 28, 2007 0:38    Post subject: Reply with quote

The examples are in the demo mod.

and here...

Code:
  PrintString("SPAWN Demo");
  PrintString("Escape c:|*.* = " + SpawnEscape("c:|*.*"));
  PrintString("Quote  c:|*.* = " + SpawnQuote("c:|*.*"));
  PrintString("Esc/Q  c:|*.* = " + SpawnQuote(SpawnEscape("c:|*.*")));
  PrintString("OS = " + SpawnEnvironment("OS"));
 
  SpawnProgram(SpawnQuote(SpawnEscape("c:|autoexec.bat")));
 
  SpawnCommand(SpawnQuote("dir "+SpawnQuote(SpawnEscape("c:|*.*"))+
    " >> "+SpawnQuote(SpawnEscape("c:|temp|temp.txt"))));


Results (in sequence)

Code:
Escape c:|*.* = c:\*.*
Quote c:|*.* = "c:|*.*"
Esc/Q c:|*.* = "c:\*.*"
OS = Windows_NT    (on my machine)

SpawnProgram(SpawnQuote(SpawnEscape("c:|autoexec.bat")));
<nothing> but runs "c:\autoexec.bat"

  SpawnCommand(SpawnQuote("dir "+SpawnQuote(SpawnEscape("c:|*.*"))+
    " >> "+SpawnQuote(SpawnEscape("c:|temp|temp.txt"))));
<nothing> but issues the command (via the console)
dir  "c:\*.*" >> "c:\temp\temp.txt"
<check your c:\temp directory to find the file>


SpawnProgram() is useful for any program type (based on file extention)
eg nwnx_restart.cmd

SpawnCommand() would be useful for creating 'special log files'
eg echo "message" >> "logfile.log"

I wouldn't use it too often as it is a greedy little pig.

Oh, and both SpawnProgram() and SpawnCommand() have a SPAWN_WAIT option, that will wait for the 'task' to complete before continuing the NWScript. (as you're not returning results there's no point in waiting)

Cheers
Gryphyn
Back to top
View user's profile Send private message
redils



Joined: 13 Jan 2005
Posts: 27

PostPosted: Thu Jun 28, 2007 10:08    Post subject: Reply with quote

Thx you Gryphyn ! Thx you very much ! You save my pw's life ! ^^
Back to top
View user's profile Send private message
nosfe



Joined: 25 Apr 2007
Posts: 22

PostPosted: Thu Jun 28, 2007 13:16    Post subject: Reply with quote

great Rolling Eyes Rolling Eyes Laughing im happy Wink
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Thu Aug 30, 2007 15:41    Post subject: Reply with quote

Can you let me know how to set it up. Does the dll go in the \nwn2\nwnx4 directory or \nwn2.

What is the demo module supposed to do? It is just a grassy area with no clues. I am not sure if I even have it installed correctly.

I am wanting to delete character bic files from d:\games\nwn2\Servervault\[PlayerName]\[BicFileName].bic

Could you possibly give an example relevant to this goal?

Can anyone give advice on how special characters are handled in the PlayerName and BicFileName?
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
nosfe



Joined: 25 Apr 2007
Posts: 22

PostPosted: Thu Aug 30, 2007 19:28    Post subject: Reply with quote

hello, you could copy .dll into NWNX4 directory

for delete one file bic, try this :

d:\games\nwn2\Servervault\[PlayerName]\[BicFileName].bic

sPlayerName
sBicFileName

in script :
SpawnCommand(" del "+SpawnQuote(SpawnEscape("D:|games|nwn2|Servervault|"+sPlayerNAme+"|"+sBicFileName+".bic")));
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Aug 31, 2007 0:28    Post subject: Reply with quote

Okay - Here is what I have, but it isn't working for some reason.

Code:

#include "hcr2_core_i"
#include "nwnx_spawn"

void main()
{
   object oPC               = GetPCSpeaker();
   string sPCID             = GetExternalPCID(oPC);
   string sPlayerNAme       = GetPCPlayerName(oPC);
   string sBicFileName      = GetName(oPC);
   string sBicFilePath      = SpawnEscape("D:|games|nwn2|Servervault|"+sPlayerNAme+"|"+sBicFileName+".bic");
   int nRegisteredCharCount = h2_GetRegisteredCharCount(oPC);

   WriteTimestampedLogEntry(sBicFilePath);   
   SetLocalInt(oPC, "I_AM_RETIRED", 1);
   SQLExecDirect("call retire_pc(" + sPCID + ")");
   SendMessageToPC(oPC, H2_TEXT_TOTAL_REGISTERED_CHARS + IntToString(nRegisteredCharCount));
   SendMessageToPC(oPC, H2_TEXT_MAX_REGISTERED_CHARS + IntToString(H2_REGISTERED_CHARACTERS_ALLOWED));
   SendMessageToPC(oPC, "You'll be booted in 6 seconds, and your character will be deleted from the vault!");
   DelayCommand(6.0, BootPC(oPC));
   DelayCommand(7.0, SpawnCommand("del " + SpawnQuote(sBicFilePath)));
}


When I look at the log, the file path is correct. I even copied it and pasted it in a command prompt with "del " in front of it and it worked fine.

I have tried changing the delay time. I am stumpped!
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Aug 31, 2007 1:10    Post subject: Reply with quote

Urlord,

OK, As I said it's a jungle of quotes...
(sorry, but they're needed by the cmd console)

My example:
SpawnCommand( SpawnQuote( "dir " +
SpawnQuote( SpawnEscape( "c:|temp|temp.txt" ) ) ) );

Your command :
SpawnCommand( SpawnQuote( "del " +
SpawnQuote( SpawnEscape( "D:|games|nwn2|Servervault|" + sPlayerNAme + "|" + sBicFileName + ".bic" ) ) ) );

Code:

string sPath = "D:|games|nwn2|Servervault|";
string sBic = sPlayerNAme+"|"+sBifFileName+".bic";

SpawnCommand(
  SpawnQuote(
    "del " +
       SpawnQuote(
          SpawnEscape(
             sPath + sBic
          )
       )
  )
);

the string that should be generated is
"del ""D:\games\nwn2\Servervault\<player>\<bic>"""
<> indicates where the variables go, and the quote characters are required

this is the same as an entry in the console window (DOS)
cmd "del ""file-to-delete""" -- not just del "file-to-delete"

after all that...still confused...

DelayCommand(7.0, SpawnCommand("del " + SpawnQuote(sBicFilePath)));

should be

DelayCommand(7.0, SpawnCommand(SpawnQuote("del " + SpawnQuote(sBicFilePath))));
To put the entire command in quotes, so it can be used.

If in doubt open up the command console and try your command using the cmd "command" syntax.

Hope that helps.
Cheers
Gryphyn
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Aug 31, 2007 2:03    Post subject: Reply with quote

Gryphyn - Thanks for the support here. I am really trying to get this working.

Here is what I have now:
Code:


#include "hcr2_core_i"
#include "nwnx_spawn"

void main()
{
    object oPC          = GetPCSpeaker();int nRegisteredCharCount = h2_GetRegisteredCharCount(oPC);
   string sPCID       = GetExternalPCID(oPC);
   string sPlayerNAme    = GetPCPlayerName(oPC);
   string sBicFileName = GetName(oPC);
   string sCommand      = SpawnQuote("del " + SpawnQuote(SpawnEscape("D:|games|nwn2|Servervault|"+sPlayerNAme+"|"+sBicFileName+".bic")));
   
   WriteTimestampedLogEntry(sCommand);
   SetLocalInt(oPC, "I_AM_RETIRED", 1);
   SQLExecDirect("call retire_pc(" + sPCID + ")");   
    SendMessageToPC(oPC, H2_TEXT_TOTAL_REGISTERED_CHARS + IntToString(nRegisteredCharCount));
    SendMessageToPC(oPC, H2_TEXT_MAX_REGISTERED_CHARS + IntToString(H2_REGISTERED_CHARACTERS_ALLOWED));
   SendMessageToPC(oPC, "You'll be booted in 6 seconds, and your character will be deleted from the vault!");
   DelayCommand(6.0, BootPC(oPC));
   DelayCommand(7.0, SpawnCommand(sCommand));
}


The log has this as the value of sCommand:
"del ""D:\games\nwn2\Servervault\Urlord\Test_Monk.bic"""

But it still isn't deleting the file. Even if I go to a dos prompt and enter:

cmd "del ""D:\games\nwn2\Servervault\Urlord\Test_Monk.bic"""

It doesn't work. So I am stumpped again.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Aug 31, 2007 2:39    Post subject: Reply with quote

Urlord,

hmmm, the 1 second should be enough time for the game to save, and close, the bic file.

There could be a chance that the file is still in use (open) after the 1 second, and won't be available to be deleted.
I assume that the BootPC() also does a SingleExport().
Do you have a lot of OnExit() processing? (Area/Client).

I'd (you'll) have to watch some Filemon activity to see just when the Bic file is closed (in NWN1 I know it was opened for shared-read).

I'll get back if I find anything.

OK, the cmd command is actually cmd/c
eg cmd/c "del ""fred.txt""" deletes the file "fred.txt"
The /c is applied within the plugin.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Aug 31, 2007 2:48    Post subject: Reply with quote

I have tried it with BootPC at 6 seconds and SpawnCommand at 30 seconds and it still doesn't work.

The purpose of the "I_AM_RETIRED" variable is so I know not to process anything in the OnExit (Area/Client) events.

This is damn strange. and it has me tugging at my hair a bit.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Aug 31, 2007 2:54    Post subject: Reply with quote

Just to let you know, the following command does works in the command prompt:

cmd/c "del ""D:\games\nwn2\Servervault\Urlord\Test_Monk.bic"""
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Aug 31, 2007 3:12    Post subject: Reply with quote

Have you tries a SingleExport (save character) prior to the delete?
That should refresh the bic data to disk. (synchronize disk & data)

When you run the delete from the command console, do you ALSO have the NWN2 session running at the same time? (this should give you a reason if the delete does not happen {file open} - or add to the mystery)

One though is that maybe this should run from the 'OnClientExit()' event.
using the "I_AM_RETIRED" flag to signal the delete process.

This will be closer to when a 'close' on the file will take place.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Aug 31, 2007 3:36    Post subject: Reply with quote

Just thinking out loud here. Does the SpawnCommand function put the space between cmd/c and sCommand? Just grasping here.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group