Aller au contenu

Photo

Please, post your noob code here


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

#1
Qkrch

Qkrch
  • Members
  • 128 messages
 Hi there, im trying to understand the dascript but I don't know where to start, and it is not because of I don't know how to script (very confident with nwscript)... is just I don't know here to start and the concepts of the wiki seem much abstract of what i'm looking for.

So i just would like to take a look to code examples, simple routines, as example:

- Create an item inside a creature after a convo node.
- Spawn creatures at locations
- Display visual effects in some events
- Make those hidden doors to show :)
- Triggers firing traps or cutscenes
- ....

And some more you think is basic. It's the lack of code examples that pulls me out, and i'm not ready to learn from the big codes over the OC or the debug scripts...

Anyone with experience scripting in DA, please post two lines of code, it would help :happy:

thanks!!

#2
st4rdog

st4rdog
  • Members
  • 104 messages
There's plenty examples of code in the folders inside the toolset.



There's also an entire demo module you can open which has 5 scripts inside the Demo folder.

#3
Qkrch

Qkrch
  • Members
  • 128 messages
I said that i don't want to look blindly through the scripts made specifically for the OC.



Just basic examples, it would help me and thousands of people reading it.

#4
Nodrak

Nodrak
  • Members
  • 144 messages
The toolset has a list of functions, it would be a better place to start. Giving items can be done in like 3 lines of code, less if you have pre-defined variables.

#5
Phaenan

Phaenan
  • Members
  • 315 messages
Three quick copy/pasted examples. Not sure it'll help, tho. Like the others said, browsing through the core scripts and reading the included syntax help would probably be more effective.  :o

- Create an item inside a creature after a convo node.

A small script for the dialog line action :
void main() {
    object oContainer = UT_GetNearestCreatureByTag(GetHero(), "yourcreaturetag", FALSE);
    CreateItemOnObject(rRes, oContainer, 1, "optionalitemtag", TRUE);
}

- Spawn creatures at locations

Make a creature spawn next to the PC :
- http://pastie.org/707603


- Display visual effects in some events

An event handler replacing creature_core to make a creature ghostly and go "pouf" when appearing and dying.
- http://pastie.org/707592
(shamelessly taken from some core script, somewhere)

Modifié par Phaenan, 20 novembre 2009 - 02:42 .


#6
Qkrch

Qkrch
  • Members
  • 128 messages
Thanks Phaenan, much appreciated.



It is known that before reading the whole bible you start reading the known verses.



I'm not asking for someone to script my plots, just share some code.. and someday, someone will take the notes and will make examples for every function :D

#7
Erenz

Erenz
  • Members
  • 29 messages
So, that one is for triggering a cutscene - very easy stuff, you just add this script to your trigger. If you want to make sure only the Player triggers it (the code would trigger from any creature entering it, including monsters), you may look around in the wiki, it's in there.

-----
#include "events_h"
#include "wrappers_h"
#include "utility_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch(nEventType)
    {
         case EVENT_TYPE_ENTER:
         {
            CS_LoadCutscene(R"gis_rf_dscamp.cut"); //the name in " " is the name of the cutscene file.
            DestroyObject(OBJECT_SELF); //makes sure the trigger only fires once, it deletes itself after firing
         }
    }
    HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
}
-----

This one is to make something visible - activating a door/monster/area transition/whatever. Again, it will trigger from anything entering, so if you have creatures wandering around, you have to check who fired the event, and only execute your code if it was the player.

-----
#include "wrappers_h"
#include "events_h"
#include "utility_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch(nEventType)
    {
         case EVENT_TYPE_ENTER:
         {
            SetObjectActive(GetObjectByTag("dis_cth_spawn0"), TRUE);
            DestroyObject(OBJECT_SELF);
         }
    }
    HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
}
-------

Modifié par Erenz, 20 novembre 2009 - 03:32 .


#8
Qkrch

Qkrch
  • Members
  • 128 messages
Thanks Erenz



Hope to be back seeing more code in this post and posting some of my own :)

#9
AND04

AND04
  • Members
  • 154 messages

Erenz wrote...

So, that one is for triggering a cutscene - very easy stuff, you just add this script to your trigger. If you want to make sure only the Player triggers it (the code would trigger from any creature entering it, including monsters), you may look around in the wiki, it's in there.


IsPartyMember()  is your friend.

Modifié par AND04, 20 novembre 2009 - 03:50 .


#10
Qkrch

Qkrch
  • Members
  • 128 messages
 So, been practicing

This script in a trigger will make a certain NPC cry for help, then the PC will run to him and start a conversation. Usually known as speak trigger (i know there's a more complex one by default in the palette)

#include "events_h"
#include "wrappers_h"


void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    int nEventHandled = FALSE;
    object oEnterer = GetEventCreator(ev);
    object oSpeaker = GetObjectByTag("c_questgiver");

    if (IsHero(oEnterer)) //if oEnterer is our character and not any creature
          {
            if (!GetLocalInt(OBJECT_SELF,"TRIGGER_DO_ONCE_A")) //getting local variable so the trigger doesnt repeat
             {
             switch(nEventType)
                  {
                      case EVENT_TYPE_ENTER:
                         {

                         ClearAllCommands(oSpeaker,TRUE); // stop creature from doing anything else
                         ClearAllCommands(oEnterer, TRUE); //stop our PC
                         DisplayFloatyMessage(oSpeaker,"Please help me!");
                         AddCommand(oEnterer,CommandStartConversation(oSpeaker)); //start convo
                         SetLocalInt(OBJECT_SELF,"TRIGGER_DO_ONCE_A",TRUE); //setting local variable, so it wont repeat anymore
                         }
                  nEventHandled = TRUE;
                  break;
                  }

              }
        }
        if (!nEventHandled) //If this event wasn't handled by this script, let the core script try
        {
            HandleEvent(ev, RESOURCE_SCRIPT_TRIGGER_CORE);
        }


}



Note that i used te trigger local variables instead of destroying the trigger, is cleaner this way. Also I used IsHero() instead of IsPartyMember() that can work even better.

Problems: the playable character can be doing any other action, so the cue can mess up easily... how to solve this? Tried CommandWait() but didnt work

PS: one example of conversation conditional script?

Modifié par Qkrch, 20 novembre 2009 - 08:18 .