Aller au contenu

Photo

A couple of scripting issues for a n00b scripter


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

#1
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
 Alright so im very new to scrippting in general but i think im picking it up fairly fast, though i have a few issues with a couple of these scripts im working on. 

Script one is a Item Activation script, the purpose of it is that when the user activates the script on a hostile target, the item will apply dmg to the target. I have most of it workign great but its not registering that the dmg is from the user, so if the creature dies the user dosnt get any exp...
heres the bones of my script:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Script 1 was reposted

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

         Script 2 im not even sure how to realy start, but the idea is to make a spell script that when the caster sucessfully finishes the spell it creates x amount of an item and places it in the casters inventory, then after 60 seconds times x amount of time remove these items. where x = caster level
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"
void main(){
      /*  Spellcast Hook Code  Added 2003-06-20 by Georg  If you want to make changes to all spells,  check                             x2_inc_spellhook.nss to find out more
              */
    if (!X2PreSpellCastCode())    {   
// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell       
              return;    }
// End of Spell Cast Hook
     object oCaster = OBJECT_SELF;
     //object oItem = //"item tag? but my compiler couldnt find it";
     int nCasterLvl = GetCasterLevel (OBJECT_SELF); 
     
           if (nCasterLvl < 10)
           {
               nCasterLvl = 10;
           }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this is all ive gotten so far, i've tried using their giveitem fcn but it couldnt find my item and also kept giving me a unextected end of opterations error or somthing liek that regaurdless of how i closed my }

Any help with these will be greatly appreciated, and any good sources for learngin all the commands for nwn2 would alos help a ton!

Modifié par AstoriaWMY, 15 juillet 2012 - 08:27 .


#2
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
Srry that it looks real messy for script one it didnt past correctly

#3
MasterChanger

MasterChanger
  • Members
  • 686 messages

AstoriaWMY wrote...

Srry that it looks real messy for script one it didnt past correctly


I'd recommend trying the following, in order:
1) Put the script in "quote" blocks, i.e. "quote" and "/quote" with square brackets around each. This will keep formatting.
2) Put the script in "code" blocks, which may or may not keep formatting.
3) If neither of these gets you good results, use Pastebin.com, which is a good place to link blocks of code so that others can see.

As it is, the code is so messy that it's pretty hard to follow. That's this forum's fault, not yours, but try some of the ways I describe above to make it easier to read.

#4
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
 ["//Script 1 the script name is i_"item name"_ac so that it links to the item
#include"x2_inc_switches"
#include "x0_I0_SPELLS"
#include "x2_inc_spellhook"

 void main(){                
     int nEvent =GetUserDefinedItemEventNumber();          // Exit if not an activate event   
          if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)               
               return;    // Your script here   
     object oUser = GetItemActivator();   
     object oTarget = GetItemActivatedTarget();   
     string sName = GetName(oTarget);   
     string sTag = GetTag(oTarget);   
     location lLoc = GetLocation(oTarget);       
     int nDamage = d6;       
     int isEnemy = 0;       
     effect eDam;       
     effect eVis = EffectNWN2SpecialEffectFile("sp_call_lightning.sef");              
          if (GetIsEnemy(oTarget))       
               {               
                    isEnemy = 1;               
                          {                       
                                 eDam = EffectDamage (nDamage, DAMAGE_TYPE_ELECTRICAL, DAMAGE_POWER_ENERGY, FALSE);                       
                                ApplyEffectToObject (DURATION_TYPE_INSTANT, eDam, oTarget);
                          }               
                        ApplyEffectToObject (DURATION_TYPE_INSTANT, eVis, oTarget);       
               }
}"]    

//its too bad that these forums dont have a preview post option, lol srry again for that, it showed up fine untill i posted it
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//updated script 2

"[#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"
void main(){
/*  Spellcast Hook Code  Added 2003-06-20 by Georg  If you want to make changes to all spells,  check x2_inc_spellhook.nss to find out more
*/
    if (!X2PreSpellCastCode())   
{    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell       
return;   
}
// End of Spell Cast Hook
object oCaster = OBJECT_SELF;
int nCasterLvl = GetCasterLevel (OBJECT_SELF);
object oItem = BA_swordmo;
     if (nCasterLvl < 10) {
          nCasterLvl = 10;
     }
     object oTarget = OBJECT_SELF;    
{       
     if (spellsIsTarget(oTarget, SPELL_TARGET_SELECTIVEHOSTILE, OBJECT_SELF))         
 //Fire cast spell at event for the specified target           
         SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, "spellname"));
                   ActionGiveItem (oItem, oCaster);
}
}"]

Modifié par AstoriaWMY, 16 juillet 2012 - 05:36 .


#5
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
For your first problem, the issue is that when you use 'ApplyEffectToObject' to do the damage, it's the owner of the script (i.e. the item) that does the damage. To get the PC, (i.e. oUser) to do the damage instead, you have to rig the script so that oUser is running 'ApplyEffectToObject'. Probably the simplest why to do this is to create a separate function at the top of your script (something like void ApplyDamage(object oTarget)) and then use 'AssignCommand' to have oUser run the function.

#6
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
How do I get AssignCammand to run the rest of the script? 

i cant put void ApplyDamage (object oTarget) anywhere without getting a syntax error "at the '('" and i tried messing around with assign command as AssignCommand (oUser, eDam) but it wont use eDam as its an effect so i tried makking it an action but then it gives me an error saying that it cant be made an action.

could you give me an example of how it would fit in my script plz?

Also ive just aded the line 
{AssignCommand((GetItemActivator()), ActionPlayAnimation (ANIMATION_LOOPING_CONJURE1, 1.0, 1.0));}
to the top of my script i would like it to play the effect befor the rest of the scrip or while the rest of the script goes off ig but it wont play the animation till after everthing is done is there any way to fix this?

Modifié par AstoriaWMY, 16 juillet 2012 - 05:25 .


#7
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Non-main functions are declared above the main function (and individually they can only use functions declared above themselves). AssignCommand is a regular function, look it up in the script assist on the right of your compiler.

#8
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
DELETED

Modifié par AstoriaWMY, 17 juillet 2012 - 02:09 .


#9
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
 Thanks for all the help i actualy ended up putting in the following lines,
object oUser = GetItemActivator();
if(!GetIsPC(OBJECT_SELF))
ExecuteScript("scriptname", oUser);

Now on to the script 2 issue, ive modified my spells 2da file to modify the specific spell i wanted, and switch its current script with the script I made, but after the spell is cast nothing happens...
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//script 2
#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"
void main(){
/*  Spellcast Hook Code  Added 2003-06-20 by Georg  If you want to make changes to all spells,  check x2_inc_spellhook.nss to find out more
*/
    if (!X2PreSpellCastCode())   
{    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell       
return;   
}
// End of Spell Cast Hook
object oCaster = OBJECT_SELF;
int nCasterLvl = GetCasterLevel (OBJECT_SELF);
string sItem = GetLocalString(oCaster, "nw_it_sparscr603");
if (nCasterLvl < 10) {
nCasterLvl = 10;
}
object oTarget = OBJECT_SELF;    
{        
CreateItemOnObject(sItem, oCaster);
}
}

Do I need to get this scripts file from my module and place it somewhere for the spell to recongnize it, or is the problem in the script itself? also if i wanted to use a custom item do i need to copy that file to a diferent location as well?

Modifié par AstoriaWMY, 17 juillet 2012 - 02:12 .


#10
Dann-J

Dann-J
  • Members
  • 3 161 messages
Is nw_it_sparscr603 the name of a local variable stored on the caster, or is it the resref of the item you want to spawn? If the latter, then you might as well hardcode the resref in CreateItem:

// unnecessary code has been commented out
object oCaster = OBJECT_SELF;
//int nCasterLvl = GetCasterLevel (OBJECT_SELF);
//string sItem = GetLocalString(oCaster, "nw_it_sparscr603");
//if (nCasterLvl < 10) {
//nCasterLvl = 10;
//}
//object oTarget = OBJECT_SELF;
//{
CreateItemOnObject("nw_it_sparscr603", oCaster);
//}

#11
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
the reson for the casterlevel part is that i would like to somehow make it so that after a set duration (60seconds/Lvl to a maximum of 600 seconds) the items will get removed or somthing to that nature. and is the spellhook thing necassary because i want it to function as a spell or is it just somthing that they put for their own made spells for whatever reason?

Anyway hardocing the string worked great thanks!

Also is there a way in script one for me to play an animation while the item is used BEFOR the rest of the script activates, right now all the functions only play the animations AFTER, or is this somthing that i would have to modify on the items file itself?

again thanks for all the help and input guys! srry that we seem to be on on opisit times of the day XD

Modifié par AstoriaWMY, 17 juillet 2012 - 09:46 .


#12
AstoriaWMY

AstoriaWMY
  • Members
  • 15 messages
I figured out how to do the animation, it has to be on the item itself in the 2da file, im using the magic scroll base for now untill i make my own 2da