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 
 
nwnx_funcs for windows
Goto page Previous  1, 2, 3 ... 25, 26, 27, 28, 29  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed May 02, 2012 10:01    Post subject: Reply with quote

Flutterby wrote:
apsoft wrote:
hi,

I've a problem with NWNXFuncs_AddKnownSpell, OS is Win7

When i add a spell on this PC "5 lev Sorcerer + 10 Lev Pale Master" with this func
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 1, SPELL_MAGIC_MISSILE);

the server works fine, but when i modify my script with
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 3, SPELL_GREATER_MAGIC_WEAPON);

script adds the spell to the creature's list of known spells but the server crashes when player log out Sad, anyone knows why?

thank you to all

p.s. sorry for my english XD


I'm having the same problem. Some more specifics:

- The crash only occurs when learning a spell of a level that is not normally available for that character, given his base class. E.g. my sorc 10 / pale master 10 would normally be able to learn spells up to spell level 5. If I add a spell of spell level 5 or below, the server will not crash. If I add a spell of level 6 or up, the server will crash.
- In either case, the character will not have the newly learned spell available when logging in to the server again.

This issue occurs when using 0.0.93 as well as 0.0.91 or 0.0.89.

Here's to hoping someone will be able to help out!

Edit: Using Windows 7, 64 bit


Im pretty sure that Spells are one of those things that get stored in the LevelStats structure of the bic file.

By attempting to modify/insert into a level stats node that doesnt exist.
eg- Inserting a spell for level 32, when we are only level 22, will crash - because level 32's node does not exist.

Way I got around this was to level the player up to level 40, use the henchman auto level up function, and then delevel the player back to 1.

This will create the nodes, and allow you to insert spells at any level.
I used this to get around a similar crash for Modifying the HitPoints gained at levels.

This may or may not be ur issue.
Back to top
View user's profile Send private message
Flutterby



Joined: 01 May 2012
Posts: 11

PostPosted: Wed May 02, 2012 10:08    Post subject: Reply with quote

Baaleos wrote:
Flutterby wrote:
apsoft wrote:
hi,

I've a problem with NWNXFuncs_AddKnownSpell, OS is Win7

When i add a spell on this PC "5 lev Sorcerer + 10 Lev Pale Master" with this func
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 1, SPELL_MAGIC_MISSILE);

the server works fine, but when i modify my script with
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 3, SPELL_GREATER_MAGIC_WEAPON);

script adds the spell to the creature's list of known spells but the server crashes when player log out Sad, anyone knows why?

thank you to all

p.s. sorry for my english XD


I'm having the same problem. Some more specifics:

- The crash only occurs when learning a spell of a level that is not normally available for that character, given his base class. E.g. my sorc 10 / pale master 10 would normally be able to learn spells up to spell level 5. If I add a spell of spell level 5 or below, the server will not crash. If I add a spell of level 6 or up, the server will crash.
- In either case, the character will not have the newly learned spell available when logging in to the server again.

This issue occurs when using 0.0.93 as well as 0.0.91 or 0.0.89.

Here's to hoping someone will be able to help out!

Edit: Using Windows 7, 64 bit


Im pretty sure that Spells are one of those things that get stored in the LevelStats structure of the bic file.

By attempting to modify/insert into a level stats node that doesnt exist.
eg- Inserting a spell for level 32, when we are only level 22, will crash - because level 32's node does not exist.

Way I got around this was to level the player up to level 40, use the henchman auto level up function, and then delevel the player back to 1.

This will create the nodes, and allow you to insert spells at any level.
I used this to get around a similar crash for Modifying the HitPoints gained at levels.

This may or may not be ur issue.


Yes, that seems to be the issue indeed - although strangely, it works well on 32 bit. Also, correct me if I'm wrong, but wouldn't you have to do this every time the player logs on (I'm coding for a PW), and wouldn't it still be problematic once the player hits max level and you can't create the nodes for them any more?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed May 02, 2012 11:58    Post subject: Reply with quote

you would only need to do this once for a player/character on character creation, or for the first login per character.

Once the nodes are all created, they dont need to be re-created, as they are never deleted.
Back to top
View user's profile Send private message
Wallack



Joined: 30 Apr 2012
Posts: 27

PostPosted: Fri May 04, 2012 18:48    Post subject: Reply with quote

I'm having problems with NWNXFuncs_SetAbilityScore and GetAbilityScore.

Because GetAbilityScore gets the current ability score (you can set if base or with item bonuses) with the racial bonus, example:

Elf with 16 dexterity will return in 16.

But NWNXFuncs_SetAbilityScore sets the ability as base and then adds the racial bonuses, example:

SetDex to 16 to an elf will result in a 18 dexterity elf.

It should change the ability just to the indicated number. Any way to fix this?
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri May 04, 2012 18:58    Post subject: Reply with quote

Wallack wrote:
I'm having problems with NWNXFuncs_SetAbilityScore and GetAbilityScore.

Because GetAbilityScore gets the current ability score (you can set if base or with item bonuses) with the racial bonus, example:

Elf with 16 dexterity will return in 16.

But NWNXFuncs_SetAbilityScore sets the ability as base and then adds the racial bonuses, example:

SetDex to 16 to an elf will result in a 18 dexterity elf.

It should change the ability just to the indicated number. Any way to fix this?
Did it behave the same in latest version 9.0.3 and latest stable version 8.9? If someone have source for 8.9 I could fix this.

EDIT: found the 8.9 on svn
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect


Last edited by ShaDoOoW on Fri May 04, 2012 19:44; edited 1 time in total
Back to top
View user's profile Send private message
Wallack



Joined: 30 Apr 2012
Posts: 27

PostPosted: Fri May 04, 2012 19:34    Post subject: Reply with quote

I'm going to try a temporary fix:

Change racial to human, adjust stats, change racial back.
Back to top
View user's profile Send private message
Wallack



Joined: 30 Apr 2012
Posts: 27

PostPosted: Fri May 04, 2012 19:40    Post subject: Reply with quote

Wallack wrote:
I'm going to try a temporary fix:

Change racial to human, adjust stats, change racial back.


Worked.
Back to top
View user's profile Send private message
Flutterby



Joined: 01 May 2012
Posts: 11

PostPosted: Sat May 05, 2012 0:22    Post subject: Reply with quote

Flutterby wrote:
apsoft wrote:
hi,

I've a problem with NWNXFuncs_AddKnownSpell, OS is Win7

When i add a spell on this PC "5 lev Sorcerer + 10 Lev Pale Master" with this func
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 1, SPELL_MAGIC_MISSILE);

the server works fine, but when i modify my script with
Code:
NWNXFuncs_AddKnownSpell (oPC, CLASS_TYPE_SORCERER, 3, SPELL_GREATER_MAGIC_WEAPON);

script adds the spell to the creature's list of known spells but the server crashes when player log out Sad, anyone knows why?

thank you to all

p.s. sorry for my english XD


I'm having the same problem. Some more specifics:

- The crash only occurs when learning a spell of a level that is not normally available for that character, given his base class. E.g. my sorc 10 / pale master 10 would normally be able to learn spells up to spell level 5. If I add a spell of spell level 5 or below, the server will not crash. If I add a spell of level 6 or up, the server will crash.
- In either case, the character will not have the newly learned spell available when logging in to the server again.

This issue occurs when using 0.0.93 as well as 0.0.91 or 0.0.89.

Here's to hoping someone will be able to help out!

Edit: Using Windows 7, 64 bit


Resolved this issue. Basically, when you're using a 64-bit system, there's a memory allocation mismatch that causes the server to crash when you log off with a character that has memory allocated to it that's not been allocated by the game. We made an edit in NWNXFuncs_RemoveAllSpells, adding a parameter that tells you from which level on you want to remove the spells, and that makes sure the memory is cleaned up after removing them.
I added a check in the hooked onexit script that checks if a character has been given extra spells, calculates which level is their 'natural' maximum and removed everything above that. It works like a charm.

For those of you who are savvy with C:
Code:
// CNssSpells.cpp RemoveAllSpells now takes minlevel, maxlevel and freemem as extra parameters.
int CNssSpells::RemoveAllSpells(CGameObject *oObject, char *Params) {
   CNWSCreature *cre = oObject->AsNWSCreature();
   if (!cre) {
      _log(2, "o Error RemoveAllSpells used on non-creature object.\n");
      sprintf(Params, "-1");
      return 0;
   }

   uint8_t Class = 0;
   uint8_t MinLevel = 0;
   uint8_t MaxLevel = 0;
   uint8_t FreeMem = 0;
   CParams::ExtractP4(Params, Class, MinLevel, MaxLevel, FreeMem);

   int i=0, sp_level=MinLevel;
   CNWSStats_Level *ls;

   if (cre->cre_stats == NULL) {
      sprintf(Params, "-1");
      return 0;
   }

   if (MinLevel < 0 || MaxLevel > 9) {
      _log(2, "o Error RemoveAllSpells has invalid spell level range.\n");
      sprintf(Params, "-1");
      return 0;
   }

   /* find the requested class and level, then remove the new spell */
   for (i = 0; i < cre->cre_stats->cs_classes_len; i++) {
      if (cre->cre_stats->cs_classes[i].cl_class != Class)
         continue;

      if (cre->cre_stats->cs_classes[i].cl_spells_known[sp_level].len > 0) {
         for (sp_level = MinLevel; sp_level <=MaxLevel; sp_level++) {
            if (cre->cre_stats->cs_classes[i].cl_spells_known != NULL) {
               cre->cre_stats->cs_classes[i].cl_spells_known[sp_level].len = 0;
               if(FreeMem == 1)
               {
                  cre->cre_stats->cs_classes[i].cl_spells_known[sp_level].alloc = 0;
                  free(cre->cre_stats->cs_classes[i].cl_spells_known[sp_level].data);
                  cre->cre_stats->cs_classes[i].cl_spells_known[sp_level].data = NULL;
               }
            }
         }
      }
   }

   int iCharacterLevel=0;
   sp_level=MinLevel;
   while ((ls = GetLevelStats(cre->cre_stats, ++iCharacterLevel)) != NULL) {
      for (sp_level = MinLevel; sp_level <=MaxLevel; sp_level++) {
         if (ls->ls_spells_known != NULL) {
            ls->ls_spells_known[sp_level].len = 0;
            if(FreeMem == 1)
            {
               ls->ls_spells_known[sp_level].alloc = 0;
               free(ls->ls_spells_known[sp_level].data);
               ls->ls_spells_known[sp_level].data = NULL;
            }
         }
      }
   }

   return 1;
}


And a small edit in nwnx_funcs.nss:
Code:
// Removes all known spells for a class from spell levels iMinLevel to iMaxLevel
// If bFreeMemory is TRUE nwnx will free the memory allocated for storing learned spells. Be careful with this as
// freeing memory for spell levels given by the game will crash the server while not freeing memory for spell levels
// given by nwnx will also crash the server. Only use this when you used NWNXFuncs_AddKnownSpell to add spells at spell
// levels not available in standard game rules.
// Only works for spell casting classes that need to select which spells they want to know (Sorcerer, Wizard, Bard)
void NWNXFuncs_RemoveAllSpells(object oCreature, int iClass, int iMinLevel = 0, int iMaxLevel = 9, int bFreeMemory=FALSE);

void NWNXFuncs_RemoveAllSpells(object oCreature, int iClass, int iMinLevel = 0, int iMaxLevel = 9, int bFreeMemory=FALSE) {
    SetLocalString(oCreature, "NWNX!FUNCS!REMOVEALLSPELLS", IntToString(iClass)+" "+IntToString(iMinLevel)+" "+IntToString(iMaxLevel)+" "+IntToString(bFreeMemory));
    DeleteLocalString(oCreature, "NWNX!FUNCS!REMOVEALLSPELLS");
}
Back to top
View user's profile Send private message
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Sat May 05, 2012 4:17    Post subject: Reply with quote

I've been trying to find a way to tackle that memory issue myself since its impossible to alter the data on objects that deallocate from nwnx plugins without cleaning up, and tags, names, etc you can't really cleanup either since you want them to stick.

So if anyone has/knows any solution to it I'd be a happy person because I've been googling and reading though msdn documentation coming up short.
_________________
I dun have any signature, I'm happy anyway.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
wowgold123477



Joined: 16 Apr 2012
Posts: 2
Location: America

PostPosted: Sat May 05, 2012 8:11    Post subject: To experience these Reply with quote

results, a new 'wow' internet site ought to give you the required info in the well put together as well as organised method that costs nothing involving jumbled images and big blocks regarding text message.buy wow gold
Pictures, where utilized, ought to be offered inside of a creative method in which involves the site customer. For instance, your web site may available with a empty web site upon which impression aspects gradually appear based on the motion in the visitor's cursor before thebuy wow gold
whole web site usually takes shape. This may encourage people to explore the site, because all the ticks they make for their computer mouse button reveals another, undetectable graphic orcheap wow gold
feature.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Zarx



Joined: 06 May 2012
Posts: 4

PostPosted: Sun May 06, 2012 12:09    Post subject: Reply with quote

Terra_777 wrote:
I've been trying to find a way to tackle that memory issue myself since its impossible to alter the data on objects that deallocate from nwnx plugins without cleaning up, and tags, names, etc you can't really cleanup either since you want them to stick.

So if anyone has/knows any solution to it I'd be a happy person because I've been googling and reading though msdn documentation coming up short.


Yes, this is a problem, but as it seems it is not possible to make nwn save things added by nwnx to the bic file and load it back. In the issue as stated by flutterby, the added spells do seem to be saved into the bic file (when inspecting using Leto) but they are removed again when re-loading the character into nwn. The game probably checks the validity of these kinds of adjustments and 'corrects' them.

The best solution so-far is to store all adjustments you make (e.g. extra spell levels) as variables onto an inventory item in the PC's inventory (e.g. for spells you give the PC an undroppable spellbook in their inventory). In the logout script, you restore all properties to their original state (freeing memory allocated by nwnx like in flutterby's fix). In the login script, you check if a PC has such an inventory item and you restore the properties using nwnx. When doing this for spells it works like a charm. I don't see a reason why the same thing wouldn't work on other properties requiring nwnx to allocate memory.
Back to top
View user's profile Send private message
Zarx



Joined: 06 May 2012
Posts: 4

PostPosted: Sun May 06, 2012 13:11    Post subject: Reply with quote

By the way, is there any reason why some of the getter functions in nwnx_funcs' CNssSpells (e.g. GetKnowsSpell, GetRemainingSpellSlots, GetMaxSpellSlots) start out setting the parameters to "0" (using calls to sprintf)? This way these functions will never work and always will return -1, since all parameters specifying thing like class and level are overwritten at the start of the function. Shouldn't these sprintf statements be removed?
Back to top
View user's profile Send private message
Wallack



Joined: 30 Apr 2012
Posts: 27

PostPosted: Tue May 08, 2012 20:11    Post subject: Reply with quote

Hello, I found another problem.

When changing dexterity, AC is not updated in the sheet (didn't test in game engine) so to update it I have to apply a 6 secs temporary effect upgrading dexterity by 2 points. That increases AC by 1 point (so is still wrong in the sheet) but when the effect is gone, the AC remains untouched.

Example:

Human 16 dex (+3)
AC 13

Now I apply with nwnx_funcs +2 DEX so:

Human 18 dex (+4)
AC still 13

Now I apply a temporary effect of +2 DEX:

Human 20 dex (+5)
AC 14 (-1 !!)

Now the effect is gone:

Human 18 dex (+4)
AC 14

The problem comes if the player has the max dex (+12 for now) he will have to remove some item that increases DEX and put it back again to update the AC.

Also another option is to use a temporary effect of -2 DEX
I asume none of my players will go around with -12 dex (also I can increase it to -20 safely) but I think this is not the best solution. That's why I'm asking you if you know another way to fix it.

Kind regards.
Back to top
View user's profile Send private message
Kato



Joined: 05 Mar 2010
Posts: 47

PostPosted: Tue May 08, 2012 20:37    Post subject: Reply with quote

Wallack wrote:
Hello, I found another problem.

When changing dexterity, AC is not updated in the sheet (didn't test in game engine) so to update it I have to apply a 6 secs temporary effect upgrading dexterity by 2 points. That increases AC by 1 point (so is still wrong in the sheet) but when the effect is gone, the AC remains untouched.

Example:

Human 16 dex (+3)
AC 13

Now I apply with nwnx_funcs +2 DEX so:

Human 18 dex (+4)
AC still 13

Now I apply a temporary effect of +2 DEX:

Human 20 dex (+5)
AC 14 (-1 !!)

Now the effect is gone:

Human 18 dex (+4)
AC 14

The problem comes if the player has the max dex (+12 for now) he will have to remove some item that increases DEX and put it back again to update the AC.

Also another option is to use a temporary effect of -2 DEX
I asume none of my players will go around with -12 dex (also I can increase it to -20 safely) but I think this is not the best solution. That's why I'm asking you if you know another way to fix it.


To refresh the sheet, you could swap a worn item with itself, so that nothing changes in the inventory. The pc hide created by the horse system is usually a good choice because you can be sure that it will exist on the toon. Simply re-equip the item in code:

object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC);
AssignCommand(oPC, ActionEquipItem(oHide, INVENTORY_SLOT_CARMOUR));

I use this technique with several different nwnx plugins and it works well, so hopefully this can help...


Kato
Back to top
View user's profile Send private message Send e-mail
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed May 09, 2012 17:10    Post subject: Reply with quote

There is also a nwnx_funcs function that updates the character sheet.

Possibly added because this problem was forseen?


But that being said - I have seen a few mentions recently about critical bugs in the recent versions of nwnx funcs.

Im on an old version - and dont need to update since the functionality works fine at the moment.
Hope it gets resolved though, cause I have had a peek at the src, and it looks alot better structured than the version I had originally.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Goto page Previous  1, 2, 3 ... 25, 26, 27, 28, 29  Next
Page 26 of 29

 
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