e-mods.net

Nod Engine SDK => Scripting and Modifying => Topic started by: Barnabas on 2011-02-28, 10:32:06

Title: Need help with scripts
Post by: Barnabas on 2011-02-28, 10:32:06
Hi all,

I made some conversations for my maps. Some of them work as planned, but I had to write an own script for every conversation and add them to NPCs in the NOTEditor to make them work. I tried to use Javoīs tutorialscripts with the strings, but they didnīt work. When I tried to add the scripts to a NPC with override in Embrace, the scripts didnīt work, so I had to add them in NOTEditor.
Now I wanted to write a script, that has some variables, so that I only need one script for all of my conversations. All I want to do is to add the script in Embrace to a NPC and set the conversation files in the codex linker. For that I wrote the following script:

public class StartConvo extends Codex
{
   public StartConvo(String convoFile, String convoGiveName)
   {
      this.convoFile="";
      this.convoGiveName="";
   }   
   public void clicked (int guid, int clickerGuid, int captureID)
   {
      ExecuteConversation(clickerGuid, guid, convoGiveName, convoFile, CONV_XFLAG_WANTFEEDBACK);
}
public void convreached(int starterGuid, int curEvent, int curLine, int lineDuration, int speakerGuid)
{
   CodexCamera.SetupCutscene(starterGuid, GetClassThing(), 0);
   CodexCamera.SetShot(starterGuid, CAM_SHOT_POV_A, CAM_ANGLE_HIGH, CAM_DIST_MEDIUM, 1, 0);
}
public void convended(int starterGuid,  boolean bAborted , int returnValue)
{
   CodexCamera.Release(starterGuid);
}
private String convoGiveName;
private String convoFile;
public static String _params[] = {
    "Conversation Name", "Conversation File (NCO)"
};
}


Eclipse didnīt find an error, but the script does not work. I added it to a talkable NPC, set the conversationfile via codex linker, started the chronicle (after full export of course...), went to the NPC, clicked on him and .... nothing.

What did I do wrong? Please help.


Title: Re: Need help with scripts
Post by: Signothorn on 2011-03-01, 21:55:59
Hopefully someone knowledgeable will be able to help you. Idk if you knew this but Jav lost his internet so he won't be around much for a while, didn't want you to think he's ignoring you.
Title: Re: Need help with scripts
Post by: Barnabas on 2011-03-02, 08:55:28
Thanks for telling me that :-D - was afraid, that I was bugging Javo too much with my problems in the past^^
Title: Re: Need help with scripts
Post by: Barnabas on 2011-03-06, 04:39:13
I really canīt imagine, whatīs wrong with that script.Why doesnīt it work?
Title: Re: Need help with scripts
Post by: Javokis on 2011-03-06, 13:08:40
Your script should be working. The only thing I can think of is that ExecuteConversation can't find the nco file and/or convo name in the nco file. Make sure you're implicitly imputing filename.nco (include the nco extension). Also make sure the nco file is in the right location. Make sure you stick with ansi for the file names because the engine wont read them in UTF-8.

[edit]

Oh... just noticed this:

public StartConvo(String convoFile, String convoGiveName)
   {
      this.convoFile="";
      this.convoGiveName="";
   }   

You're setting convoFile and convoGiveName to an empty string. If you want it to work in codex linker you need to do this:

public StartConvo(String convoFile, String convoGiveName)
   {
      this.convoFile=convoFile;
      this.convoGiveName=convoGiveName;
   }   

The script you had before always set the values to an empty string no matter what you put in codex linker.
Title: Re: Need help with scripts
Post by: Barnabas on 2011-03-06, 14:04:46
Ok, the scrips looks now like this:

public class StartConvo extends Codex
{
   public StartConvo(String convoFile, String convoGiveName)
   {
      this.convoFile=convoFile;
      this.convoGiveName=convoGiveName;
   }   
   public void clicked (int guid, int clickerGuid, int captureID)
   {
      ExecuteConversation(clickerGuid, guid, convoGiveName, convoFile, CONV_XFLAG_WANTFEEDBACK);
}
public void convreached(int starterGuid, int curEvent, int curLine, int lineDuration, int speakerGuid)
{
   CodexCamera.SetupCutscene(starterGuid, GetClassThing(), 0);
   CodexCamera.SetShot(starterGuid, CAM_SHOT_POV_A, CAM_ANGLE_HIGH, CAM_DIST_MEDIUM, 1, 0);
}
public void convended(int starterGuid,  boolean bAborted , int returnValue)
{
   CodexCamera.Release(starterGuid);
}
private String convoGiveName;
private String convoFile;
public static String _params[] = {
    "Conversation Name", "Conversation File (NCO)"
};
}


Unfortunally it still doesnīt work.

Make sure you stick with ansi for the file names because the engine wont read them in UTF-8.



Hmm - what do you mean with this? Whatīs UTF-8?
Title: Re: Need help with scripts
Post by: Javokis on 2011-03-06, 15:14:07
That means the files need to be in ENGLISH. Engine can't read a file name in a foreign language. The only place foreign languages will work is inside an nls file and only if that nls file name is in English.
Title: Re: Need help with scripts
Post by: Barnabas on 2011-08-01, 21:17:32
Does a script exist, that plays random sounds from a defined stock of sounds?
Title: Re: Need help with scripts
Post by: Paine on 2011-08-02, 10:30:11
Does a script exist, that plays random sounds from a defined stock of sounds?

This should work:
Code: [Select]
import java.io.BufferedReader;
import java.io.FileReader;

import java.util.Vector;

public class ItemRandomSound extends Codex
{
Vector sounds = new Vector();

public ItemRandomSound()
{
try
{
String line = "";
BufferedReader reader = new BufferedReader(new FileReader("randomsounds.txt"));
while((line = reader.readLine()) != null)
        sounds.add(line);
reader.close();
}
catch(Exception e)
{
}

}

public void clicked(int guid, int clickerGuid, int captureID)
{
int random = (int)Math.random() * sounds.size();
String soundName = (String)sounds.elementAt(random);
CodexSound.StartMusic(soundName, 100 );
}
}
Title: Re: Need help with scripts
Post by: Barnabas on 2011-08-04, 23:59:25
Looks interesting - unfortunally, I do not really understand that script  ::) How am I able to use this?
Title: Re: Need help with scripts
Post by: Paine on 2011-08-06, 01:50:55
Looks interesting - unfortunally, I do not really understand that script  ::) How am I able to use this?

You need to compile it with the java development kit (output must be JRE 1.1 compliant) this will produce a .class file which goes in the Codex folder.
In the main vampire directory you need to create a .txt file called "randomsounds.txt".
In the random sounds.txt you should have sounds listed like:
randomsound1.mp3
randomsound2.mp3
randomsound3.mp3 etc..
Then you'll need to create a prop with the not editor, attach the ItemRandomSound script and make sure it's clickable.

All the sound files will need to go in Sounds\Music.