Author Topic: how to: capture attempt to open door before it is opened?  (Read 2372 times)

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #30 on: September 01, 2010, 01:23:38 am »


               OH, you are going to tell me how to script. That's a laugh.  Well no-one and I mean no-one, at least not to my knowledge ever said you did not have Hutzpah!':?' 
               
               

               


                     Modifié par ffbj, 01 septembre 2010 - 12:25 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #31 on: September 01, 2010, 01:40:15 am »


               

ffbj wrote...

OH, you are going to tell me how to script. That's a laugh.  Well no-one and I mean no-one, at least not to my knowledge ever said you did not have Hutzpah!':?' 



Um, you DID ask me to look at that, unless there is another EK here. So, please, don't act like I stepped on your toes.

Facts are facts, check them out and see if I'm wrong on the OBJECT_SELF. By all means, let me know if I've erred somewhere in that post, but don't take the reply wrong, it sure looked like you asked for an evaluation.

Live and learn, eh?

'<img'>

I guess the Hutzpah is on the other foot eh?
               
               

               


                     Modifié par ehye_khandee, 01 septembre 2010 - 12:47 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #32 on: September 01, 2010, 01:51:38 am »


               

ffbj wrote...

Just something else to add to the long and fabled history of messing with doors. How many have , been iviserated, mangled, mutilated, murdered, and otherwise messed up by doors? When you go into the dungeion in my world and see a locked door you stop, and that's what you should do, mostly...hehehe.

I must digress briefly to recapitulate an amusing antidote from my first campaign world.  We had a locked door to deal with and I started bashing it.  My companion began taking damage and continued to do so, and ran down the hall.  I continued to bash the door having no idea that I wasl damaging him every time I hit the door.  Well he never came back, though he survived as we finally figured out what was happening.  He healed up and I bashed the door once more just for fun.  That's when he left.  That was one of my early scripts.


OK, funny door stories, I can think of two, even three...

1) Back in the day, nad I mean the Day - 1986ish - when we were playing pen n paper D&D, we came up to a dorr in a castle we were looting, and found it locked.  So our hero Paul - who sported a big Fro and called his character the Black Knight thus causing us to conclude that he really wanted to be a brother in an age when it wasn't hip or hop for a teen to pretend to be from da hood - announced "I kick the door in!!"  to which our DM replied "What kind of boots are you wearing?" ....  "BooOOOTS?!?!"  
2) our hero, Greer the wizard (David's character) was all that was left of not so merry band of adventurers parading through the Shadowlands.  He was in fact run up against a great door to a strange dark Keep whilst a pack of unnatural wolves descended upon him.  He called out "help, let me in blah blah"  and then tried to bash the great door to no avail.  He tried a Knock spell from a scroll to find magic was unreliable in the shadowlands, he tried to fend off the wolves but knew he had a derth of power left and all but gave up hope until.... another player (the player of the dead PC being carried by our hero leaned over and whispered something in Daves ear.  Then Dave sheepishy said "I open the door and go in."  and the great unlocked door was conquered at last.
3) we were a band of many, and we had made our way into the Mentors lair unto the door to The Room Of The Ten Doors ( not counting the one in presumably ).  And there we weare stymied.  We tried pushing and pulling and picking and bashing, we tried spells and passwords until at last - our old freind the Black Knight stepped forward and pronounced "Open" ...

These and many other tales of yore and be read at: http://calgacus.game...rum/Library.htm
               
               

               


                     Modifié par Calgacus, 01 septembre 2010 - 12:52 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #33 on: September 01, 2010, 01:58:37 am »


               

ehye_khandee wrote...

ffbj wrote...

OH, you are going to tell me how to script. That's a laugh.  Well no-one and I mean no-one, at least not to my knowledge ever said you did not have Hutzpah!':?' 



Um, you DID ask me to look at that, unless there is another EK here. So, please, don't act like I stepped on your toes.

Facts are facts, check them out and see if I'm wrong on the OBJECT_SELF. By all means, let me know if I've erred somewhere in that post, but don't take the reply wrong, it sure looked like you asked for an evaluation.

Live and learn, eh?

'<img'>

I guess the Hutzpah is on the other foot eh?



Chuzpah!??  you want Chuzpah?    check this out:  http://www.normanfin...eyond-chutzpah/

   ok, maaaay be gettin off topic...
               
               

               


                     Modifié par Calgacus, 01 septembre 2010 - 12:59 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #34 on: September 01, 2010, 04:49:54 am »


               Oh yeah. That's it, Chuzpah! Sorry if you took that wrong EK, just that, what you are suggesting is not the way to do it. Technically it's not wrong, just bad practice, imho. I was not asking you for an evaluation, I just thought you might be interested in the script.

Funny door stories btw, good luck with the labyrinth.
               
               

               


                     Modifié par ffbj, 01 septembre 2010 - 03:51 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #35 on: September 01, 2010, 12:05:08 pm »


               ffbj,

You posted "OH, you are going to tell me how to script. That's a laugh."

That was RUDE. And utterly un-called-for.

I've always treated you well. You've even visited my PW and expressed that you were impressed with what my partner and I had accomplished there (sophisticated integrated systems, 1100+ areas, lag free, crash free). While you may feel there are other ways to accomplish the task this thread discusses, even ways you would prefer, THAT WAS RUDE and inappropriate, doubly so as I was on target with the comment about AssignCommand.
               
               

               


                     Modifié par ehye_khandee, 01 septembre 2010 - 12:05 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #36 on: September 02, 2010, 12:02:57 am »


               ehye_khandee , I thought ffbj   was just joking when he wrote that.



Has anyone ever done some sort of psychological research into online flaming?  It seems people including myself are extremely sensitive when they are slighted online even when protected behind fake names and no one could possibly know their true identity.  might be a legit study.



Anyway, the purpose of this thread has been met.



Thanks for the help everyone.  It's good to see the community is still ... passionate.





               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #37 on: September 02, 2010, 12:12:44 am »


               

Calgacus wrote...
Has anyone ever done some sort of psychological research into online flaming? It seems people including myself are extremely sensitive when they are slighted online even when protected behind fake names and no one could possibly know their true identity. might be a legit study.



Wonder how long it would take for a thread on that topic to get locked.   'Posted
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #38 on: September 02, 2010, 01:20:30 am »


               

ffbj wrote...

OH, you are going to tell me how to script. That's a laugh.  Well no-one and I mean no-one, at least not to my knowledge ever said you did not have Hutzpah!':?' 


I'll laugh with you, he told me I can't script either...
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #39 on: September 02, 2010, 01:49:24 am »


               

Genisys wrote...



ffbj wrote...

OH, you are going to tell me how to script. That's a laugh.  Well no-one and I mean no-one, at least not to my knowledge ever said you did not have Hutzpah!':?' 


I'll laugh with you, he told me I can't script either...


Genesys, Laugh all you like, I've seen your code. Let's review the script I sent back to you corrected... first your original script of 89 lines intended to spawn interference (supercop) on 'improper use of a door' ...


//Script Name: sc_on_unlock
//////////////////////////////////////////
//Created By: Genisys (Guile)
//Created On: 8/19/08
/////////////////////////////////////////
/*
This will spawn in the Super Cop on
the PC for unlocking something they
were not suppose to!
*/
// GM_ODA NOTE: THE ABOVE DESCRIPTION SHOULD INCLUDE EVERYTHING THIS SCRIPT SHOULD DO
////////////////////////////////////////
#include "setxp_inc"

//Main Script
void main()
{

//Declare Major Variables
object oPlayer;
object oTarget;
object oSpawn;
object oMe = OBJECT_SELF;
location lTarget;

int nInt;
lTarget = GetLocation(oTarget); // GM_ODA NOTE: oTarget has not yet been given a value therefore this location will be invalid

//Let's make sure we define just who killed the NPC clearly..
// GM_ODA NOTE: who's talking about killing a NPC? this is on the on_unlocked script of an object!
if(!GetIsPC(GetLastUnlocked()))// GM_ODA NOTE: flawed code block used in numerous scripts in this set WILL NOT WORK AS INTENDED. Did you really test this stuff? As a PC and as a DM and as a npc possessed by a DM?
{
//if It's a DM stop here..
if(GetIsDMPossessed(GetLastUnlocked()))
{ return; }
if(GetIsDM(GetLastUnlocked()))
{ return; } // GM_ODA NOTE: this will NEVER fire, DM's are considered PCs too so would not be included in this if()'s subjects
// GM_ODA NOTE: it is a bad idea to re-invoke GetLastUnlocked() rather than set a variable to use it ONCE.

//IF It truly was an associate who attacked..
if(GetMaster(GetLastUnlocked())!=OBJECT_INVALID)
{
oPlayer = GetMaster(GetLastUnlocked());
}
else
{
oPlayer = GetLastUnlocked();
}

}
else
{
oPlayer = GetLastUnlocked(); // GM_ODA NOTE: this would mean DMs are possible values for the oPlayer ... not what was intended.
}

if(GetIsPC(oPlayer)) // GM_ODA NOTE: why do this same if() twice?
{

//Only Once Ever 30 Seconds!
int DoOnce = GetLocalInt(oPlayer, GetTag(OBJECT_SELF) + "SC");
if (DoOnce==TRUE) {return;}

SetLocalInt(oPlayer, GetTag(OBJECT_SELF) + "SC", TRUE);
DelayCommand(30.0, SetLocalInt(oPlayer, GetTag(OBJECT_SELF) + "SC", TRUE));


//Penalize the player!
ApplyRespawnPenalty(oPlayer);// GM_ODA NOTE: this was never offered in the description for the script. How is this going to work on your DM Avatar eh?

oTarget = oPlayer;
lTarget = GetLocation(oTarget); // GM_ODA NOTE: reduce this and prior line to "lTarget = GetLocation(oPlayer);"

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "supercop", lTarget);

oTarget = oSpawn;

int nInt; // GM_ODA NOTE: NEVER declare variables inside a conditional. This one is declared TWICE!
nInt = GetObjectType(oTarget);
// GM_ODA NOTE: regarding the following section, why would a OBJECT_TYPE_CREATURE you just spawned be anything but a OBJECT_TYPE_CREATURE ???
if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD), oTarget));
else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD), GetLocation(oTarget)));


AssignCommand(oPlayer, ClearAllActions());

}

//Main Script End
}



// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Now the replacement/corrected script of 37 lines that I sent you for your edification.

//Script Name: pw_on_unlock ... supercedes sc_on_unlock - redux by GM_ODA
//sc_on_unlock Created By: Genisys (Guile)
//sc_on_unlock Created On: 8/19/08
/* This will spawn in the Super Cop on the PC for unlocking
something they were not suppose to! */

//Main Script
void main()
{
//Declare Major Variables
object oTarget,oSpawn,oPlayer,oMe = OBJECT_SELF, oTest = GetLastUnlocked();
int DoOnce;
string sControl;
if(!GetIsPC(oTest))
{
if(GetIsDMPossessed(oTest))return;
oPlayer = GetMaster(oTest);
} // resolve for all NPCs
else{oPlayer = oTest;}// resolve for PC

if( (!GetIsObjectValid(oPlayer)) || GetIsDM(oTest) )return; // exit if DM or object not valid

//Only Once Ever(y) 30 Seconds! - begin
sControl = GetTag(OBJECT_SELF) + "SC";
DoOnce = GetLocalInt(oPlayer, sControl);
if (DoOnce==TRUE) {return;}
SetLocalInt(oPlayer, sControl, TRUE);
DelayCommand(30.0, SetLocalInt(oPlayer, sControl, TRUE));
//Only Once Ever(y) 30 Seconds! - end

int nInt;
location lTarget = GetLocation(oPlayer);
CreateObject(OBJECT_TYPE_CREATURE, "supercop", lTarget);
ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD),lTarget);

AssignCommand(oPlayer, ClearAllActions());
} //Main Script End


*scratches head* Now, don't you wish you'd left that can of worms unopened 'Guile'?

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


ffbj - what exactly was it that you say is 'not the way to do it. I only suggested that your use of AssignCommand was incorrect because it targets OBJECT_SELF and I can show you references that say DO NOT DO THIS. If I'm wrong I can accept that but in this case, I think you are confused.

Be well. Game on.
GM_ODA
               
               

               


                     Modifié par ehye_khandee, 02 septembre 2010 - 01:07 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #40 on: September 02, 2010, 03:15:41 am »


               I've decided to just not waste my time with some people...
               
               

               


                     Modifié par Genisys, 02 septembre 2010 - 02:30 .
                     
                  


            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #41 on: September 03, 2010, 04:09:01 pm »


               Well, ehye_khandee is actually correct on both counts here. Using AssignCommand to assign a command to OBJECT_SELF is poor form, it produces worse performance, and most importantly it is very likely to behave unexpectedly if one does not really understand exactly how the function works (See below). Doing it that way can easily lead people who are new to scripting into big trouble. The NWN Lexicon is very clear on all of these points, and none of these is a matter of personal opinion.

Do not bother to use AssignCommand(OBJECT_SELF, Foobar()), as AssignCommand() is worthless in that situation - the caller of the  script automatically uses Foobar even without the AssignCommand, and it  is only likely to generate more performance issues.

Note that AssignCommand'ed commands get executed AFTER the script finishes.

A common mistake on AssignCommand seems to be to use OBJECT_SELF. OBJECT_SELF is a constant so it is more of a NULL pointer than a "this" pointer. If you  use it in the AssignCommand or similar functions the creature will  attempt to perform the action against itself which most often seems to not be what the person using it intended.

This is the scripting forum, and we do want people to know about and avoid common mistakes, right? Well, this is one of those common mistakes. Personal egos aside, it is correct that not using AssignCommand with OBJECT_SELF here is a better solution.

As for the criticism of the script posted by Genisys earlier -- sorry if that hurts your feelings, but this is the scripting forum. If you post a script that is full of errors and sloppy coding, it is the responsibility of other community members to point out the flaws in what you posted, and explain to you how you could have accomplished your goal with better code.  Scripts that have errors or are confusing make things very difficult for newbies trying to learn by example. Scripts like that will always be critiqued, corrected, and simplified as needed. This helps everyone, especially new scripters, understand how to make scripts work properly. Everyone should be open to suggestions regarding how to improve their scripting skills, because that is the only way to get better at scripting. The very best scripters around are always looking for new ways to do things better, and they welcome suggestions on how to improve their code.

In this specific case, your script really was a confusing mess. You (and everyone else reading this thread) would be very wise to consider the very reasonable suggestions that ehye_khandee has posted regarding ways to fix the problems with your script. The purpose here is not to "say you can't script". The purpose is to fix the script so that other people will not reproduce your mistakes in their own scripts.

If you would like to avoid people correcting your scripts in the future, the solution is very simple -- spend a lot more time improving and correcting your scripts before posting them..
               
               

               


                     Modifié par Invisig0th, 03 septembre 2010 - 06:06 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #42 on: September 03, 2010, 09:25:54 pm »


               If I can split straws here  second, And get your opinion on this.  



ffbj did not use the null pointer in his script with the assign command. He did this:



object oDoor = OBJECT_SELF;

AssignCommand(oDoor, ActionOpenDoor(oDoor));



That is no longer the null  pointer being used in the AssignCommand but a object pointer pointint at the object currently running the script.  Is this really that big of a deal.  Agreed in this case the AssignCommand is not needed.  I can however see times when you may want to have the command run on either self or other and change the object pointer to the situation.  I myself do not see the problem or where it would cause errors.  



Am I incorrect in this?





               
               

               
            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #43 on: September 03, 2010, 09:28:28 pm »


               

Lightfoot8 wrote...

If I can split straws here  second, And get your opinion on this.  

ffbj did not use the null pointer in his script with the assign command. He did this:

object oDoor = OBJECT_SELF;
AssignCommand(oDoor, ActionOpenDoor(oDoor));

That is no longer the null  pointer being used in the AssignCommand but a object pointer pointint at the object currently running the script.  Is this really that big of a deal.  Agreed in this case the AssignCommand is not needed.  I can however see times when you may want to have the command run on either self or other and change the object pointer to the situation.  I myself do not see the problem or where it would cause errors.  

Am I incorrect in this?



Well, ideally you wouldn't define OBJECT_SELF in such a fashion.
               
               

               
            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #44 on: September 03, 2010, 09:32:21 pm »


               

Invisig0th wrote...

Well, ehye_khandee is actually correct on both counts here. Using AssignCommand to assign a command to OBJECT_SELF is poor form, it produces worse performance, and most importantly it is very likely to behave unexpectedly if one does not really understand exactly how the function works (See below). Doing it that way can easily lead people who are new to scripting into big trouble. The NWN Lexicon is very clear on all of these points, and none of these is a matter of personal opinion.

Do not bother to use AssignCommand(OBJECT_SELF, Foobar()), as AssignCommand() is worthless in that situation - the caller of the  script automatically uses Foobar even without the AssignCommand, and it  is only likely to generate more performance issues.

Note that AssignCommand'ed commands get executed AFTER the script finishes.

A common mistake on AssignCommand seems to be to use OBJECT_SELF. OBJECT_SELF is a constant so it is more of a NULL pointer than a "this" pointer. If you  use it in the AssignCommand or similar functions the creature will  attempt to perform the action against itself which most often seems to not be what the person using it intended.

This is the scripting forum, and we do want people to know about and avoid common mistakes, right? Well, this is one of those common mistakes. Personal egos aside, it is correct that not using AssignCommand with OBJECT_SELF here is a better solution.

As for the criticism of the script posted by Genisys earlier -- sorry if that hurts your feelings, but this is the scripting forum. If you post a script that is full of errors and sloppy coding, it is the responsibility of other community members to point out the flaws in what you posted, and explain to you how you could have accomplished your goal with better code.  Scripts that have errors or are confusing make things very difficult for newbies trying to learn by example. Scripts like that will always be critiqued, corrected, and simplified as needed. This helps everyone, especially new scripters, understand how to make scripts work properly. Everyone should be open to suggestions regarding how to improve their scripting skills, because that is the only way to get better at scripting. The very best scripters around are always looking for new ways to do things better, and they welcome suggestions on how to improve their code.

In this specific case, your script really was a confusing mess. You (and everyone else reading this thread) would be very wise to consider the very reasonable suggestions that ehye_khandee has posted regarding ways to fix the problems with your script. The purpose here is not to "say you can't script". The purpose is to fix the script so that other people will not reproduce your mistakes in their own scripts.

If you would like to avoid people correcting your scripts in the future, the solution is very simple -- spend a lot more time improving and correcting your scripts before posting them..



Agreed, it can be appealing to make your script look "big" and cool, but honestly, you want your script as simple as possible. While you may impress average people with a 500 line code to do something, other scripters will appreciate the ability to do the same thing in as simple form as possible.