View previous topic :: View next topic |
Author |
Message |
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Wed Jun 27, 2007 11:44 Post subject: Spawn Plugin v106.108.1.1 |
|
|
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 |
|
|
nosfe
Joined: 25 Apr 2007 Posts: 22
|
Posted: Wed Jun 27, 2007 20:27 Post subject: |
|
|
hello, please enter the examples because it is not documented lol
thanks
i want anderstand alllll ^^ |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Thu Jun 28, 2007 0:38 Post subject: |
|
|
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 |
|
|
redils
Joined: 13 Jan 2005 Posts: 27
|
Posted: Thu Jun 28, 2007 10:08 Post subject: |
|
|
Thx you Gryphyn ! Thx you very much ! You save my pw's life ! ^^ |
|
Back to top |
|
|
nosfe
Joined: 25 Apr 2007 Posts: 22
|
Posted: Thu Jun 28, 2007 13:16 Post subject: |
|
|
great im happy |
|
Back to top |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Thu Aug 30, 2007 15:41 Post subject: |
|
|
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 |
|
|
nosfe
Joined: 25 Apr 2007 Posts: 22
|
Posted: Thu Aug 30, 2007 19:28 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Fri Aug 31, 2007 0:28 Post subject: |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Fri Aug 31, 2007 1:10 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Fri Aug 31, 2007 2:03 Post subject: |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Fri Aug 31, 2007 2:39 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Fri Aug 31, 2007 2:48 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Fri Aug 31, 2007 2:54 Post subject: |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Fri Aug 31, 2007 3:12 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Fri Aug 31, 2007 3:36 Post subject: |
|
|
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 |
|
|
|