Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Simple, yet Confusing problem. (https://forums.graalonline.com/forums/showthread.php?t=74365)

MrAnonymous_P2P 06-03-2007 06:11 AM

Simple, yet Confusing problem.
 
I cannot get this script to work. It is so simple yet it will not work.
The script is a baddy for a quest and as you can see it asks you a question, the player is supposed to respond with an answer.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
showcharacter();
  
head       "head47.png";
  
colors0] = "orange";
  
colors1] = "black";
  
colors2] = "darkred";
  
colors3] = "white";
  
colors4] = "black";
  
shield     "no-shield.png";
  
body       "body18.png";
  
dir        2;
  
setcharani("niromia2_idle",NULL);
  
  
showtext1this.x+1.5this.y-.5"Kartika""cb""Click me");
}

function 
onMouseDown(button)
{
  if (
button == "left" || button == "right") {
    if (
mousex in 2326| && mousey in 4446|) {
      
say2("If you can answer one question...
   I will aid you in your quest.

   What are the 2 nations on Niromia?"
);
    }
  }
}

function 
onPlayerChats() {
  if (
player.chat == "test") {
    
findimg(1).text "I will now give you this weapon.";
  }


Anybody know what the problem is?

Skyld 06-03-2007 08:22 PM

Please be more clear with your problem; what does and doesn't function correctly?

Googi 06-03-2007 08:26 PM

For some reason I recall hearing somewhere that showtext isn't supposed to be used under onCreated...

godofwarares 06-03-2007 08:33 PM

Quote:

Originally Posted by Googi (Post 1314740)
For some reason I recall hearing somewhere that showtext isn't supposed to be used under onCreated...

I use it all the time under 'onCreated' x.x

Angel_Light 06-03-2007 08:33 PM

Quote:

Originally Posted by Googi (Post 1314740)
For some reason I recall hearing somewhere that showtext isn't supposed to be used under onCreated...

I works, I've done it before. :/

Inverness 06-03-2007 11:04 PM

It may work but there could be unknown reasons as to why it would be better to use it some other way, like in onPlayerEnters().

MrAnonymous_P2P 06-04-2007 12:29 AM

My problem is when the player answers the question (saying test) nothing happens. It just stays the same.

DustyPorViva 06-04-2007 12:38 AM

Have you took steps to debug it?
Have tried having it do something else, like changing the players text instead of changing the image?
You should break down the part of the script not working, adding little test lines until you can find out specifically what the problem is.

godofwarares 06-04-2007 12:57 AM

Quote:

Originally Posted by MrAnonymous_P2P (Post 1314812)
My problem is when the player answers the question (saying test) nothing happens. It just stays the same.

PHP Code:

//#CLIENTSIDE
function onPlayerChats()
{
     if (
player.chat.trim() == "test")
     {
          
// Yadda yadda yadda.
     
}



MrAnonymous_P2P 06-04-2007 04:34 AM

Ok now this is just being plain weird.
I got the script to work just fine except for one problem.

NPC Code:
//#CLIENTSIDE
function onCreated() {
showcharacter();
head = "head47.png";
colors[ 0] = "orange";
colors[ 1] = "black";
colors[ 2] = "darkred";
colors[ 3] = "white";
colors[ 4] = "black";
shield = "no-shield.png";
body = "body18.png";
dir = 2;
setcharani("niromia2_idle",NULL);

showtext( 1, this.x+1.5, this.y-.5, "Kartika", "cb", "Click me");
}

function onMouseDown(button)
{
if (button == "left" || button == "right") {
if (mousex in | 23, 26| && mousey in | 44, 46|) {
showtext( 1, this.x+1.5, this.y-.5, "Kartika", "cb", "If you can answer this question I will give you a prize.");
sleep(5);
showtext( 1, this.x+1.5, this.y-.5, "Kartika", "cb", "What are the two nations on Niromia?");
}
}
}
//#CLIENTSIDE
function onPlayerChats()
{
if (player.chat.trim() == "test")
{
showtext( 1, this.x+1.5, this.y-.5, "Kartika", "cb", "I will now present you with this weapon.");
sleep(5);
destroy();
}
}



Now this all works except when I click on the Baddy the showtext works ok but for some reason it also gives me a sign with the previous script which said to show a sign. And it does the same thing for when the player chats test. It shows me a sign and it changes the text above the baddy. Its like the script before this one and this modified one are conjoined together. Anybody know how to fix this?

xXziroXx 06-04-2007 05:07 AM

ERROR! ERROR! ERROR!

You are using 2x //#CLIENTSIDE, terminating program.

MrAnonymous_P2P 06-04-2007 05:19 AM

It still doesnt work even if I take the clientside out :(

xXziroXx 06-04-2007 05:31 AM

Is this NPC a class?

Chompy 06-04-2007 02:46 PM

I find it using findimg() would be better..

findimg(index).text = "foo";

instead of recreating the TShowImg object you can just change the vars of it..

theHAWKER 06-04-2007 05:08 PM

reconnect? : )

MrAnonymous_P2P 06-04-2007 06:45 PM

I reconnected, and nothing happened, and yes it is an npc class.

cbk1994 06-06-2007 03:06 PM

showtext shows an image, which the engine generates with the characters given. It isn't a GuiTextCtrl, or such, and the text can't be changed like that ...

You need to reshow the text in order for it to change.

Chompy 06-06-2007 03:08 PM

Quote:

Originally Posted by cbkbud (Post 1315576)
showtext shows an image, which the engine generates with the characters given. It isn't a GuiTextCtrl, or such, and the text can't be changed like that ...

You need to reshow the text in order for it to change.

findimg(index).text

zokemon 06-06-2007 03:32 PM

Quote:

Originally Posted by cbkbud (Post 1315576)
showtext shows an image, which the engine generates with the characters given. It isn't a GuiTextCtrl, or such, and the text can't be changed like that ...

You need to reshow the text in order for it to change.

No you don't. In fact, let me show you something that the engine has in it.

PHP Code:

function showtext(inxnyfst) {
  
findimg(i).text t;
  
findimg(i).nx;
  
findimg(i).ny;
  
findimg(i).font f;
  
findimg(i).style s;


I may have gotten some of the variable names wrong but in essence, that is all that that function is doing.


All times are GMT +2. The time now is 04:09 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.