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 
 
[Ask for Help] Your help for the documentation

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Fri Dec 15, 2006 23:14    Post subject: [Ask for Help] Your help for the documentation Reply with quote

Hello, I'm thinking about integrate some concrete example of use about the function in NWNX4.

Could you, please, help me to write, in this post, some example ?

Something like :

"I want to put a persistent box to my module for allowing PC to stock their equipement...so i wrote a script like that :....SQLExecuteDirect here allow my to make a request...."

If each member put just one example, i'm sure we could have a sufficient panel to show to beginner how to use NWNX4...

Thanks for your help
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sat Dec 16, 2006 2:22    Post subject: Reply with quote

Place this in your "on PC loaded" script:

Code:

#include "nwnx_sql"

void main()
{
  object oPC = GetEnteringObject();
  location loc = GetPersistentLocation(oPC, "exitloc");
  if (GetIsObjectValid(GetAreaFromLocation((loc))) {
    AssignCommand(oPC, ActionJumpToLocation(loc));
  }

}


And place this in your On Client Exit* script:

Code:

#include "nwnx_sql"

void main()
{
  object oPC = GetExitingObject();
  location loc = GetLocation(oPC);
  if (GetIsObjectValid(GetAreaFromLocation((loc))) {
    SetPersistentLocation(oPC, "exitloc", loc);
  }

}


* caveat: I seem to recall that NWN had some dififculty in that the PC's location was no always valid by the time the PC logged off. I haven't tested this under NWN2; if anyone has and it's still an issue, pl. let me know and I'll provide a different method.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.


Last edited by Grinning Fool on Mon Dec 18, 2006 5:37; edited 2 times in total
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Sun Dec 17, 2006 10:57    Post subject: Reply with quote

thanks for your help ! Very Happy
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sun Dec 17, 2006 11:27    Post subject: Reply with quote

That is a very good idea. A collection of 5-6 short examples that are easy to understand would be very helpful for newcomers. They would not need to belong to the DB department alone, the Time demo plugin for example demonstrates a nice use of the Timer plugin.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Mon Dec 18, 2006 4:47    Post subject: Reply with quote

Quote:
the Time demo plugin for example demonstrates a nice use of the Timer plugin

If Grinning fool is agreee we could take one of his script in the demo module to demonstrate it...After you will can add this exemple to the timer plugin documentation...
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Mon Dec 18, 2006 5:43    Post subject: Reply with quote

caloup wrote:
Quote:
the Time demo plugin for example demonstrates a nice use of the Timer plugin

If Grinning fool is agreee we could take one of his script in the demo module to demonstrate it...After you will can add this exemple to the timer plugin documentation...

Sure, that's what it's there for.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Tue Dec 19, 2006 17:02    Post subject: Reply with quote

So here his an exammple of using timer plugin :

Quote:

// Name : e_trig_enter
// Purpose : Fires when the PC pulls the lever.
// Authors : Grinning Fool [Marc Paradise]
// Modified : December 6th, 2006
#include "nwnx_time"

void main()
{

AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));

object oPC = GetLastUsedBy();
int id = GetLocalInt(OBJECT_SELF, "id");
int state = GetLocalInt(OBJECT_SELF, "state");
string name = "Timer" + IntToString(id);
string time;
if (state) {
time = StopTimer(OBJECT_SELF, name);
SendMessageToPC(oPC, name + " has been stopped.");
SendMessageToPC(oPC, "Time since you started " + name + ": " + time + " microseconds");
SetFirstName(OBJECT_SELF, "Start " + name);
} else {
SendMessageToPC(oPC, name + " has been started.");
StartTimer(OBJECT_SELF, name);
SetFirstName(OBJECT_SELF, "Stop " + name);
}
SetLocalInt(OBJECT_SELF, "state", !state);


}


I think you could add this example in the documentation of timer plugin pap's. :

Perhaps you could add a note about the possibility to use this in a quest or a mini game...

For example, in a quest you could ask one or more player to activate a number of switch defined in the script (5 for example, placed in different position in the map) and the script verify "timelastswitch" - "timefirstswitch" if it's inferior to a number defined in seconde (15s for example) then a door could be open, unless the lever are reset...It could make that a quest must be done by 2 or more player !...

Another example, you place a mini game with a little labyrinth with a trigger in the beginning of the labyrinth and another in the end...If player make less than the time you're asking to do, then i won !
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Sun Dec 31, 2006 19:42    Post subject: Reply with quote

just a litle up for this post !

No other idea ?

Could some one post some exemple for the use of SetPersistentInt (string and or location ?)
Back to top
View user's profile Send private message
amphiprion



Joined: 07 Nov 2006
Posts: 44
Location: Toulouse (France)

PostPosted: Mon Jan 01, 2007 1:29    Post subject: Reply with quote

Grinning Fool wrote:
I seem to recall that NWN had some dififculty in that the PC's location was no always valid by the time the PC logged off. I haven't tested this under NWN2; if anyone has and it's still an issue, pl. let me know and I'll provide a different method.


like Nwn1 when you Exit, in the OnModuleExit script, nwn2 don't have a valid location.
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Mon Jan 01, 2007 9:47    Post subject: Reply with quote

Quote:

I seem to recall that NWN had some dififculty in that the PC's location was no always valid


could that be because of where you put the script ?

Because if the script is onclientleave...Perhaps it's lauching when the PC is already gone ! So there is'nt any valid location to save...
Back to top
View user's profile Send private message
amphiprion



Joined: 07 Nov 2006
Posts: 44
Location: Toulouse (France)

PostPosted: Mon Jan 01, 2007 13:50    Post subject: Reply with quote

yes, it is the problem.
Back to top
View user's profile Send private message
Grumalg



Joined: 04 Nov 2005
Posts: 70

PostPosted: Tue Jan 02, 2007 3:35    Post subject: Reply with quote

It is true that the PC object is no longer a valid PC at client leave and thus no longer has a valid location. But you can still access local variables stored on a pc at client leave by useing GetExitingObject(). So if you have maintained a local var copy of location and kept it updated you can get a useable location that way. This is also true for any other local vars kept on the PC.

--- Grumalg ---
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Tue Jan 02, 2007 15:47    Post subject: Reply with quote

Grumalg wrote:
It is true that the PC object is no longer a valid PC at client leave and thus no longer has a valid location. But you can still access local variables stored on a pc at client leave by useing GetExitingObject(). So if you have maintained a local var copy of location and kept it updated you can get a useable location that way. This is also true for any other local vars kept on the PC.

--- Grumalg ---

Yes, that's the route I took. On server heartbeat, I'd update a local location on the PC, since that's a fairly low-cost operation. Once the PC logged out, I would use the value retrieved from the local variable to save it to DB.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Tue Jan 02, 2007 20:25    Post subject: Reply with quote

Ok i note that idea for the FAQ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Page 1 of 1

 
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