Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Old Scripting Engine (GS1) (https://forums.graalonline.com/forums/forumdisplay.php?f=154)
-   -   One npc triggered by another one (https://forums.graalonline.com/forums/showthread.php?t=134266697)

E_Man 06-21-2012 05:25 PM

One npc triggered by another one
 
I'm making a script and I want to use the command placenpc. I need to to be triggered by the original weapon, but I don't know how to do that because "if (weaponfired)" won't work and "if (hasweapon(weapon))" won't work because that I don't want it to activate instantly. How do I trigger a separate npc with a weapon?

E_Man 06-21-2012 05:32 PM

:O I just got an idea. I could make a separate flag. I can use this.bomb and this.explosion to trigger the other weapon.

(Try to guess what weapon this is, there was a hit in those flags ;))

cbk1994 06-21-2012 05:41 PM

Quote:

Originally Posted by E_Man (Post 1697968)
(Try to guess what weapon this is, there was a hit in those flags ;))

Why are you writing nuclear bomb control software in GS1? I'm going to have to report you to the authorities.

E_Man 06-21-2012 05:49 PM

Quote:

Why are you writing nuclear bomb control software in GS1? I'm going to have to report you to the authorities.
WHAT! NO! Wait, is that a joke. I didn't want to say this because I was going to put it in the new code gallery, but it is remote bombs, link in legend of zelda minish cap. I'm having a few troubles with the script right now, but I should be able to figure it out in a bit.

(Why would you have to report me?)

callimuc 06-21-2012 05:50 PM

lol
Quote:

Originally Posted by E_Man (Post 1697972)
(Why would you have to report me?)

because its dangerous

E_Man 06-21-2012 05:57 PM

Quote:

Originally Posted by callimuc (Post 1697973)
because its dangerous

It's an ingame weapon, like is nukeshot dangerous?

E_Man 06-21-2012 06:07 PM

Quote:

I'm having a few troubles with the script right now, but I should be able to figure it out in a bit.
Yaaaaa... I need some help with me script x_x, I can't figure out what I'm doing wrong. :(

Here it is:


Weapon:
PHP Code:

// NPC made by E-Man
if (created) {
  
this.bomb=0;
  
this.explosion=0;
  
setimg remotebomb1.png;
}
if (
playertouchsme) {
  
toweapons Remote Bomb;
  
hide;
}
if (
weaponfired && this.bomb=&& playerdir0) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+0.5,playery-1;
  
this.bomb=1;
}
if (
weaponfired && this.bomb=&& playerdir1) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx-1.5,playery+1;
  
this.bomb=1;
}
if (
weaponfired && this.bomb=&& playerdir2)  {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+0.5,playery+2.5;
  
this.bomb=1;
}

if (
weaponfired && this.bomb=&& playerdir3) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+2.5,playery+1;
  
this.bomb=1;
}
if (
weaponfired && this.bomb=1) {
  
setani shoot,remote.png;
   
setimg remotebomb1.png;
 
this.explosion=1;
    }
if (
this.bomb=1) {
  
setimg remoteimage.png;



remotebomb.txt:
PHP Code:

if (this.explosion=1) {
setimg remotebomb2.png;
sleep 0.5;
putexplosion 2,x,y;
this.explosion=0;
hide;


Remotebomb.txt never activates and also I can't get the image in my inventory to turn back into remotebomb1.png

xXziroXx 06-21-2012 06:15 PM

If I remember right, putnpc doesn't work in the editor anymore, and haven't for 6+ years.

E_Man 06-21-2012 06:21 PM

Quote:

If I remember right, putnpc doesn't work in the editor anymore, and haven't for 6+ years.
Awww, I wasted so much time on this. Is there a way to change it so it does work?

(Also, I'm just curious, if it did still work, would this script be successful?)

ffcmike 06-21-2012 06:46 PM

I'm pretty sure putnpc does still work within the editor, it might just be a case of the text file not being found. It may need to be placed within the same folder as the level, or manually browsed to within the NPC image field for it to be added to filenamecache.txt.

E_Man 06-21-2012 06:57 PM

Quote:

Originally Posted by ffcmike (Post 1697983)
I'm pretty sure putnpc does still work within the editor, it might just be a case of the text file not being found. It may need to be placed within the same folder as the level, or manually browsed to within the NPC image field for it to be added to filenamecache.txt.

It is in the same folder and the script is found, because if it wasn't and I click test, it would say that the file is not found, but it does not say that, it says that everything is correct.

ffcmike 06-21-2012 07:02 PM

The placed NPC would be a separate object to the original weapon script, so the this. variable would not transfer between them. It should use 'if(created){}' as the condition, and then probably use 'destroy;' rather than 'hide;'.

Also I know this is old gscript but I believe you still need to use '==' rather than a single '='. A single '=' is for assigning values, whereas a double '==' is for comparing different values. In modern gscript using just one would result in the condition being determined as true, even if the 2 compared values were different.

E_Man 06-21-2012 09:14 PM

Quote:

Originally Posted by ffcmike (Post 1697986)
The placed NPC would be a separate object to the original weapon script, so the this. variable would not transfer between them. It should use 'if(created){}' as the condition, and then probably use 'destroy;' rather than 'hide;'.

Also I know this is old gscript but I believe you still need to use '==' rather than a single '='. A single '=' is for assigning values, whereas a double '==' is for comparing different values. In modern gscript using just one would result in the condition being determined as true, even if the 2 compared values were different.

But I am assigning values, it is so that when I use the weapon, it can place the bomb first, then when you use the weapon again, it blows it up, and I can't do "if(created)" because I need it to blow up when I want it to, not on it's own.

ffcmike 06-21-2012 09:25 PM

Quote:

Originally Posted by E_Man (Post 1698002)
But I am assigning values, it is so that when I use the weapon, it can place the bomb first, then when you use the weapon again, it blows it up

Your assigning of variables is correct, it is the comparing of variables within the if conditions which is incorrect, using an assignment causes the if conditions to always be true.

It should be for example:

PHP Code:

if(playertouchsme){
  if(
this.value == 2){
    
this.value 3;
  }


Doing something like:

PHP Code:

if(this.value 2){
  
//stuff


is essentially the same as:

PHP Code:

if(true){
 
//stuff


It's probably worth mentioning that the opposite can also be applied for doing 'not equal to', for example:

PHP Code:

if(playertouchsme){
  if(
this.value != 2){
    
this.value 2;
  }


Quote:

Originally Posted by E_Man (Post 1698002)
and I can't do "if(created)" because I need it to blow up when I want it to, not on it's own.

In that case, you should write and read the 'bomb' variable without using 'this.', so it is a global flag, rather than one tied to the weapon.

E_Man 06-21-2012 09:38 PM

Quote:

Originally Posted by ffcmike (Post 1698004)
Your assigning of variables is correct, it is the comparing of variables within the if conditions which is incorrect, using an assignment causes the if conditions to always be true.

It should be for example:

PHP Code:

if(playertouchsme){
  if(
this.value == 2){
    
this.value 3;
  }


Doing something like:

PHP Code:

if(this.value 2){
  
//stuff


is essentially the same as:

PHP Code:

if(true){
 
//stuff


It's probably worth mentioning that the opposite can also be applied for doing 'not equal to', for example:

PHP Code:

if(playertouchsme){
  if(
this.value != 2){
    
this.value 2;
  }




In that case, you should write and read the 'bomb' variable without using 'this.', so it is a global flag, rather than one tied to the weapon.

I don't get why I need to compare variables, also would client.variable work for global flags? Though it probably is the comparing variables because I can place the bomb but it blows up on it's own.

ffcmike 06-21-2012 09:50 PM

Quote:

Originally Posted by E_Man (Post 1698006)
I don't get why I need to compare variables,

When I say comparing variables, this also counts for checking to see if one variable is equal to a numerical value.

Quote:

Originally Posted by E_Man (Post 1698006)
also would client.variable work for global flags?

It would work yes, but this is a functionality designed to save variables permanently for online usage, which doesn't apply here.

It should be fine to do:

PHP Code:

//Weapon
bomb 1;

//NPC
if(bomb == 1){




E_Man 06-21-2012 10:01 PM

Quote:

Originally Posted by ffcmike (Post 1698008)
When I say comparing variables, this also counts for checking to see if one variable is equal to a numerical value.



It would work yes, but this is a functionality designed to save variables permanently for online usage, which doesn't apply here.

It should be fine to do:

PHP Code:

//Weapon
bomb 1;

//NPC
if(bomb == 1){




I tried that and it still blows up on it's own and the image does not change back, here is the script, I also can send the images if you need to test it.

Weapon:
PHP Code:

// NPC made by E-Man
if (created) {
  
client.bomb=0;
  
client.explosion=0;
  
setimg remotebomb1.png;
}
if (
playertouchsme) {
  
toweapons Remote Bomb;
  
hide;
}
if (
weaponfired && client.bomb==&& playerdir0) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+0.5,playery-1;
  
client.bomb=1;
}
if (
weaponfired && client.bomb==&& playerdir1) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx-1.5,playery+1;
  
client.bomb=1;
}
if (
weaponfired && client.bomb==&& playerdir2)  {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+0.5,playery+2.5;
  
client.bomb=1;
}

if (
weaponfired && client.bomb==&& playerdir3) {
  
putnpc remotebomb1.png,remotebomb.txt,playerx+2.5,playery+1;
  
client.bomb=1;
}
if (
weaponfired && client.bomb==1) {
  
setani shoot,remote.png;
   
setimg remotebomb1.png;
 
client.explosion=1;
    }
if (
client.bomb==1) {
  
setimg remoteimage.png;


remotebomb.txt
PHP Code:

if (created) {
setimg remotebomb1.png;
}
if (
client.explosion==1) {
canbecarried;
setimg remotebomb2.png;
sleep 0.5;
putexplosion 2,x,y;
client.explosion=0;
destroy;



ffcmike 06-21-2012 10:16 PM

The problem now is that you are checking if conditions are true having already determined if a previous condition was true, and so both actions are happening within the same fire.

While there are better ways to go about this, this script could be compressed down to:

PHP Code:

if (weaponfired){
  if(
client.bomb == 1){
    
setani shoot,remote.png;
    
setimg remotebomb1.png;
    
client.explosion 1;
    
client.bomb 0;
  }
  else{
    if(
playerdir == 0){
      
this.placex playerx 0.5
      
this.placey playery 1;
    }
    else if(
playerdir == 1){
      
this.placex playerx 1.5
      
this.placey playery 1;
    }
    else if(
playerdir == 2){
      
this.placex playerx 0.5
      
this.placey playery 2.5;
    }
    else if(
playerdir == 3){
      
this.placex playerx 2.5
      
this.placey playery 1;
    }
    
putnpc remotebomb1.png,remotebomb.txt,this.placex,this.placey;
    
client.bomb 1;
  }


Quote:

PHP Code:

if (created) {
setimg remotebomb1.png;
}
if (
client.explosion==1) {
canbecarried;
setimg remotebomb2.png;
sleep 0.5;
putexplosion 2,x,y;
client.explosion=0;
destroy;



This won't work because the if condition is not occurring within an action.
You could try:

PHP Code:

//weapon
if (weaponfired){
  if(
client.bomb == 1){
    
setani shoot,remote.png;
    
setimg remotebomb1.png;
    
triggeraction this.placex,this.placey,explode,;
    
client.bomb 0;
  }
}

//npc

if(actionexplode){
  
canbecarried;
  
setimg remotebomb2.png;
  
sleep 0.5;
  
putexplosion 2,x,y;
  
client.explosion=0;
  
destroy;


or

PHP Code:

if(created){
  
setimg remotebomb1.png;
  
timeout 0.05;
}

if(
timeout){
  if(
client.explosion){
    
canbecarried;
    
setimg remotebomb2.png;
    
sleep 0.5;
    
putexplosion 2,x,y;
    
client.explosion=0;
    
destroy;
  }
  else{
    
timeout 0.05;
  }



E_Man 06-21-2012 10:30 PM

Quote:

Originally Posted by ffcmike (Post 1698012)
The problem now is that you are checking if conditions are true having already determined if a previous condition was true, and so both actions are happening within the same fire.

While there are better ways to go about this, this script could be compressed down to:

PHP Code:

if (weaponfired){
  if(
client.bomb == 1){
    
setani shoot,remote.png;
    
setimg remotebomb1.png;
    
client.explosion 1;
    
client.bomb 0;
  }
  else{
    if(
playerdir == 0){
      
this.placex playerx 0.5
      
this.placey playery 1;
    }
    else if(
playerdir == 1){
      
this.placex playerx 1.5
      
this.placey playery 1;
    }
    else if(
playerdir == 2){
      
this.placex playerx 0.5
      
this.placey playery 2.5;
    }
    else if(
playerdir == 3){
      
this.placex playerx 2.5
      
this.placey playery 1;
    }
    
putnpc remotebomb1.png,remotebomb.txt,this.placex,this.placey;
    
client.bomb 1;
  }




This won't work because the if condition is not occurring within an action.
You could try:

PHP Code:

//weapon
if (weaponfired){
  if(
client.bomb == 1){
    
setani shoot,remote.png;
    
setimg remotebomb1.png;
    
triggeraction this.placex,this.placey,explode,;
    
client.bomb 0;
  }
}

//npc

if(actionexplode){
  
canbecarried;
  
setimg remotebomb2.png;
  
sleep 0.5;
  
putexplosion 2,x,y;
  
client.explosion=0;
  
destroy;


or

PHP Code:

if(created){
  
setimg remotebomb1.png;
  
timeout 0.05;
}

if(
timeout){
  if(
client.explosion){
    
canbecarried;
    
setimg remotebomb2.png;
    
sleep 0.5;
    
putexplosion 2,x,y;
    
client.explosion=0;
    
destroy;
  }
  else{
    
timeout 0.05;
  }



It still did not work, I tried all of those, the first one would place either a bomb that does not blow up or a bomb that does blow up instead of placing one and it changes into the other. Then I forget which one does which, but one of the bottom ones allows you to place more than one bomb and they still don't blow up, and the other does not place bombs, and if your wonder, I know that the second last one only replaced the last flag of the script.


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

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