Aller au contenu

Photo

Help for a newbie


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
delucrist

delucrist
  • Members
  • 3 messages
Hello,

so I've been trying out the NWN2 toolset for two days now, and I'm absolutely stuck at scripting. Before you ask, I've spent most of today reading every possible resource on scripting that I could find, to no avail.

Anyway, I thought I'd try out something easy: a chest next to the character starting location that has equipment inside depending on the PC's race/class/feats/skills. And I can't friggin' get it to work!

I attached the script to activate on clicking the container. Yes, I believe there's a better way and yes, I know it re-activates all over again if I reopen the chest, but bear with me. At the moment, I've been trying to add a +1 healing kit to the chest if the PC is a dwarf, and also to add a +3 healing kit regardless of who the PC is.


void main()
{
object chest = OBJECT_SELF;
object oPC = GetClickingObject();

if(GetRacialType(oPC) == 1)
 {
 CreateItemOnObject("nw_it_medkit001", chest);
 }

 CreateItemOnObject("nw_it_medkit002", chest);
}


The +3 kit is created every time I click the chest, just as intended. But my PC (who is a dwarf, by the way - I even named him Dwarf McDwarf just to be sure) doesn't seem to register as a dwarf. I've tried several different ways to check the player's race. I also tried other things, like checking if the player has the Cleave feat and so on. Again, nothing inside the IF brackets works.

So here's my request. Can anyone post working code that does something like this:
1. puts a rapier into a container if the PC has Weapon Finesse feat,
2. a +1 healing kit if the PC has at least one rank in Heal skill,
3. a longbow if the PC is an elf,
4. and a scale mail suit if the PC is a paladin.

If it matters, I've only the NWN2 original game, fully patched I think. And if possible, suggest alternative means to triggering the script, not just on opening the chest.

#2
Shaughn78

Shaughn78
  • Members
  • 637 messages
1 problem you may be having is identifying the PC. I would put this script on the on open script and identify the player as object oPC = GetLastOpenedBy();

I created a unique weapon for a player, it would go through race then class then weapon focus. It would only create 1 item so if you had a dwarf it would first ID the weapon as a dwarven war axe, but if your class was a monk it would change the weapon to gauntlets, then if you had the feat weapon focus kama the weapon would be a kama.

I have a few other ideas and pointers for you but I have to get my kids at the bus stop, I will post them later.

Modifié par Shaughn78, 17 octobre 2011 - 06:05 .


#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I don't think GetClickingObject is the function you want, use GetLastOpenedBy or something like that.

#4
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
hmm first issue is it's going to be an elf, not a dwarf ( looked up the nwscript information at CSL Doxygen

this is the constants for RACIAL_TYPE_*

int RACIAL_TYPE_DWARF = 0
int RACIAL_TYPE_ELF = 1

so something like the following
void main()
{
object chest = OBJECT_SELF;
object oPC = GetLastUsedBy();

SendMessageToPC( oPC, "Opening "+GetName(oChest)+" By "+GetName(oPC)+" who is racial type "+IntToString(GetRacialType(oPC))  );

if(GetRacialType(oPC) == RACIAL_TYPE_DWARF)
 {
 CreateItemOnObject("nw_it_medkit001", chest);
 }

 CreateItemOnObject("nw_it_medkit002", chest);
}

The RACIAL_TYPE_DWARF is the exact same thing as that number, its a synonym to make things easier to read, however it is far easier to read. It's something called a Constant, and each function generally has constants related to it, in this case the function uses RACIAL_TYPE_*, for which you would type "RACIAL_TYPE_" into script assist. ( note the core game variables are not declared as proper constants, but they are also not actually the same thing as variables either, you should treat them as if they are the same thing. )

http://www.nwnlexicon.com/ is for NWN1, and besides some functions changing, or no longer relating since features of the game are different, it's is for the most part usable as is. The links at the top left lead you to http://www.nwnlexico...ting.index.html which you should follow and learn the basics so to speak. There also is a noobs guide knightmare setup as well.

The referencing objects varies by script type, i have a reference Referencing objects in scripts

A placeable on used is i think what you are using here - but i am not really sure, i'd read thru the different ones and perhaps do some trial and error. The other posters are likely right about using GetLastOpenedBy(), you just have to learn what functions refer to the actors in the specific event, it really varies a great deal.
Placeable On Used ( a lever for example )
object oPC =  GetLastUsedBy();
object oLever = OBJECT_SELF;

Door/chest On Opened ( a door for example )
object oPC =  GetLastOpenedBy();
object oDoor = OBJECT_SELF;


To debug things, i'd actually try to add a line like the following ( and this is the ONLY time to use GetFirstPC() outside of a loop paired with GetNextPC() )

SendMessageToPC( oPC, "Opening "+GetName(oChest)+" By "+GetName(oPC)+" who is racial type "+IntToString(GetRacialType(oPC))  );

This way you can see what is going on, note that it will return the integer and not the constant. Make sure you comment out this line after you are done with testing.

Modifié par painofdungeoneternal, 17 octobre 2011 - 06:26 .


#5
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Check out nwn2scripting.com. That is where I learned to script.

Also Knightmare's scripting for noobs comes highly recommended.

#6
delucrist

delucrist
  • Members
  • 3 messages
So far, so good. I got things moving a bit - the chest can now tell the difference between a dwarf and a human. Most of the thanks go to you all, not to any of the scripting sites I've been reading.

Now I'm trying to make it so that items appear in the chest only on the first opening. Been browsing said sites and found no conclusive help for a working "do once" command. Well, I'm guessing I should use a 0->1 local int but I can't get it to work. Here's what I have now:

int onlyonce;
if(onlyonce < 1)
{
stuff
SendMessageToPC(oPC, "The localint is "+IntToString(GetLocalInt(OBJECT_SELF, "onlyonce")));
SetLocalInt(OBJECT_SELF, "onlyonce", 1);
}

When I click on the container the second time and onwards, the message shows that "onlyonce" has indeed become 1, but for some reason the script keeps activating when I click it. What am I misunderstanding or doing wrong? I mean, how complicated can it be to check if a value is 0 or 1 and to set it to 1 if it's 0?

Damn, scripting in Morrowind was much easier and more intuitive.

#7
Morbane

Morbane
  • Members
  • 1 883 messages
try this:

if(GetLocalInt(OBJECT_SELF, "do_once") == 1) return; //at the top of the script

SetLocalInt(OBJECT_SELF, "do_once", 1); // below the previous line or at the bottom

Modifié par Morbane, 17 octobre 2011 - 08:25 .


#8
Shaughn78

Shaughn78
  • Members
  • 637 messages
For the 1 time I would use a local int on the chest. I would suggest instead of "onlyonce" as the int name maybe use the a unique int name based on the charatcer.

string sOnce = GetFirstName(oPC)+GetLastName(oPC);

if(GetLocalInt(OBJECT_SELF,sOnce) != 0)return;

SetLocalInt(OBJECT_SELF,sOnce,1);

This will check a local int based on the characters first and last name. If that int has a value of 0 then the script will fire and set the int value to 1. If the same character uses the chest again nothing will happen. This will allow the game to be used in multiplayer and each player will be able to open the chest and get their character specific loot.

#9
delucrist

delucrist
  • Members
  • 3 messages

Morbane wrote...

try this:

if(GetLocalInt(OBJECT_SELF, "do_once") == 1) return; //at the top of the script

SetLocalInt(OBJECT_SELF, "do_once", 1); // below the previous line or at the bottom



Excellent, this settled it! Now I can go on with my scripting. TYVM

#10
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
As M. Rieder said, you might check out my tutorial linked below if you have not done so already.

#11
Morbane

Morbane
  • Members
  • 1 883 messages
Check out this script generator LS-TK

#12
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
You may want to look at the script 11_p_chest_open from the OC. It doles out equipment based on class rather than race.

I have an updated version of it that includes the additional classes Favored Soul, Spirit Shaman, and Swashbuckler in my King's Festival+Queen's Harvest campaign called bb_p_chest_open.

Don't overlook the OC as a source for functional scripts. There are plenty there.

And next time you create a post consider giving it a title that actually describes the problem you need solved. ("Initial equipment chest script" would be far more informative than "Help for a newbie".)

Regards

Modifié par Kaldor Silverwand, 19 octobre 2011 - 05:05 .