Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Old Scripting Engine (GS1)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-20-2012, 10:37 PM
E_Man E_Man is offline
E-Man
E_Man's Avatar
Join Date: Jun 2012
Posts: 81
E_Man will become famous soon enough
Bottle Help

I made this but it did not work, the empty bottle does not delete, I actually have to use the empty bottle once I get the red potion to delete it, also, when I use the red potion, I don't get my red potion back. Here are the scripts:


Empty Bottle:
PHP Code:
if (playerenters) {
show;
setimg eman_water_potion.png;
}
if (
playertouchsme) {
toweapons Empty Bottle;
hide;
}
if (
hasweapon(Red Potion)) {
destroy;

Red Potion:
PHP Code:
// NPC made by E-Man
if (playerenters) {
show;
setimg eman_red_potion.png;
x=24;
y=29.9;
}
if (!
hasweapon(Empty Bottle) && playertouchsme) {
say2
You 
require an Empty Bottle;
}
if (
hasweapon(Empty Bottle) && playertouchsme) {
toweapons Red Potion;
hide;
}
if (
weaponfired) {
playerhearts=100;
setplayerprop #c, *gulp*;
destroy;
setimg eman_water_potion.png;
toweapons Empty Bottle

Reply With Quote
  #2  
Old 06-21-2012, 02:34 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
I believe it can be solved by running your hasweapon checks in a timeout.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 06-21-2012, 03:29 PM
E_Man E_Man is offline
E-Man
E_Man's Avatar
Join Date: Jun 2012
Posts: 81
E_Man will become famous soon enough
Quote:
Originally Posted by xXziroXx View Post
I believe it can be solved by running your hasweapon checks in a timeout.
Ok, I tried that on the empty bottle first, it worked perfectly, but then I tried to fix the red potion and it messed up again, they both won't delete now. I'll show you what I have now.

Empty Bottle:
PHP Code:
if (playerenters) {
show;
setimg eman_water_potion.png;
timeout=0.05;
}
if (
playertouchsme) {
toweapons Empty Bottle;
hide;
}
if (
hasweapon(Red Potion) && timeout) {
destroy;
}
if (
timeout) {
timeout=0.05;

Red Potion:
PHP Code:
// NPC made by E-Man
if (playerenters) {
  
show;
  
setimg eman_red_potion.png;
  
x=24;
  
y=29.9;
  
timeout 0.05;
  
this.redpotion 1;
}
if (!
hasweapon(Empty Bottle) && playertouchsme) {
  
say2
  You 
require an Empty Bottle;
}
if (
hasweapon(Empty Bottle) && playertouchsme) {
  
toweapons Red Potion;
  
this.redpotion 1;
  
hide;
}
if (
weaponfired && this.redpotion 1) {
  
playerhearts=100;
  
setplayerprop #c, *gulp*;
  
this.redpotion 0;
}
if (
this.redpotion && timeout) {
  
setimg eman_water_potion.png;
  
toweapons Empty Bottle;
}
if (
timeout) {
  
timeout 0.05;

Reply With Quote
  #4  
Old 06-21-2012, 03:32 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Empty Bottle:

PHP Code:
if (playerenters) { 
  
show
  
setimg eman_water_potion.png
  
timeout 0.05
}

if (
playertouchsme) { 
  
toweapons Empty Bottle
  
hide
}

if (
timeout) { 
  if (
hasweapon(Red Potion) && timeout)
    
destroy;
  
  
timeout 0.05

As I said, you need to do the hasweapon check in a timeout. And I know it's just GS1, but you need to work on styling your code.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 06-21-2012, 03:35 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
Empty Bottle:

PHP Code:
if (playerenters) { 
  
show
  
setimg eman_water_potion.png
  
timeout 0.05
}

if (
playertouchsme) { 
  
toweapons Empty Bottle
  
hide
}

if (
timeout) { 
  if (
hasweapon(Red Potion) && timeout)
    
destroy;
  
  
timeout 0.05

As I said, you need to do the hasweapon check in a timeout. And I know it's just GS1, but you need to work on styling your code.
I'm no expert in old GScript, but isn't this line redundant?

PHP Code:
if (hasweapon(Red Potion) && timeout
The "&& timeout" is extraneous; it's already nested in the timeout block.
__________________
Reply With Quote
  #6  
Old 06-21-2012, 03:56 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
I'm no expert in old GScript, but isn't this line redundant?

PHP Code:
if (hasweapon(Red Potion) && timeout
The "&& timeout" is extraneous; it's already nested in the timeout block.
Oh, yeah it's very redundant, I didn't look at the code too closely
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 06-21-2012, 05:13 PM
E_Man E_Man is offline
E-Man
E_Man's Avatar
Join Date: Jun 2012
Posts: 81
E_Man will become famous soon enough
The problem is still the same as before, even if I slightly change the timeout script because both scripts already use timeout, but I think it has something to do with the red potion because before I edited it, the empty bottle worked perfectly.
Reply With Quote
  #8  
Old 06-22-2012, 06:46 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
PHP Code:
// NPC made by E-Man 
if (playerenters) { 
  
show
  
setimg eman_red_potion.png
  
x=24
  
y=29.9
  
timeout 0.05
  
this.redpotion 1

if (!
hasweapon(Empty Bottle) && playertouchsme) { 
  
say2 
  You 
require an Empty Bottle

if (
hasweapon(Empty Bottle) && playertouchsme) { 
  
toweapons Red Potion
  
this.redpotion 1
  
hide

if (
weaponfired && this.redpotion 1) { 
  
playerhearts=100
  
setplayerprop #c, *gulp*; 
  
this.redpotion 0

if (
this.redpotion && timeout) { 
  
setimg eman_water_potion.png
  
toweapons Empty Bottle

if (
timeout) { 
  
timeout 0.05

The problem is with your replacement of the weapon after using it. The only upperhand you have is you can use setimg and stuff to manipulate the image of the weapon whilst it's in your inventory.

I made a bottle weapon which was used to obtain water, but instead of replacing the weapon I instead manipulated a client stored variable.

PHP Code:
// NPC made by tricxta
if (playerenters){
  if (!
isweapon)toweapons bottle;
  
this.watertiles={0x142};
}

if (
weaponfired){
  if (
strtofloat(#s(client.bottle))==0){//the bottle is empty!
    
if (tiles[playerx+1.5+vecx(playerdir),playery+2+vecy(playerdir)] in this.watertiles){
      
freezeplayer 2;
      
setani watercanfill,;
      
//change the state of the string and weapon image
      
setimg nmbottlewicon.png;
      
setstring client.bottle,1;
      
sleep 2;
      
setani idle,;
    }
  }
  else {
//Hey! there's water in that bottle
    
setstring client.bottle,0;
    
playerhearts+=2;
    
setimg nmbottleicon.png;
  }

Reply With Quote
  #9  
Old 06-22-2012, 08:20 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
I'm afraid Tricxta is right. I don't think you can toweapons from within a weapon (can't toweapons inside of something that was added with toweapons). Here is the closest thing you could do: you could require an empty bottle to get a red potion, then you could remove the empty bottle when you receive the red potion, and delete the red potion when it's been used, but you cannot replace it with an empty bottle using offline GS1.

I've written a quick example for you.

Empty Bottle:
PHP Code:
if (playerenters) {
  
setimg eman_water_potion.png;
  
show;
}

if (
playertouchsme) {
  
toweapons Empty Bottle;
  
hide;
}

if (
destroy) {
  
destroy;

Red Potion:
PHP Code:
if (playerenters) {
  
setimg eman_red_potion.png;
  
show;
}

if (
playertouchsme) {
  if (
hasweapon(Empty Bottle)) {
    
toweapons Red Potion;
    
removeEmptyBottle();
    
hide;
  }else {
    
say2 You need an empty bottle.;
  }
}

function 
removeEmptyBottle() {
  for (
0weaponscount++) {
    if (
strequals(#w(i),Empty Bottle)) {
      
callweapon i,destroy;
      break;
    }
  }
}

if (
weaponfired) {
  
playerhearts playerfullhearts;
  
setplayerprop #c, *gulp*;
  
destroy;

You'll also notice that the use of timeout was not needed due to callweapon.

The -best- alternative I can offer you is have a listening NPC to add the empty bottle after the red potion has been used. But unfortunately, that'll only provide a solution in that level because offline GS1 doesn't support with(levelname) stuff. Here's what I mean:

Random NPC:
PHP Code:
if (created) {
  
0;
  
0;
  
setshape 1,32,32;
  
dontblock;
}

if (
actionaddemptybottle) {
  
setimg eman_water_potion.png;
  
toweapons Empty Bottle;
  
hide;
}

if (
destroy) {
  
destroy;

Empty Bottle:
PHP Code:
if (playerenters) {
  
show;
  
setimg eman_water_potion.png;
}

if (
playertouchsme) {
  
toweapons Empty Bottle;
  
hide;
}

if (
destroy) {
  
destroy;

Red Potion:
PHP Code:
if (playerenters) {
  
setimg eman_red_potion.png;
  
show;
}

if (
playertouchsme) {
  if (
hasweapon(Empty Bottle)) {
    
toweapons Red Potion;
    
removeEmptyBottle();
    
hide;
  }else {
    
say2 You need an empty bottle.;
  }
}

function 
removeEmptyBottle() {
  for (
0weaponscount++) {
    if (
strequals(#w(i),Empty Bottle)) {
      
callweapon i,destroy;
      break;
    }
  }
}

if (
weaponfired) {
  
playerhearts playerfullhearts;
  
setplayerprop #c, *gulp*;
  
triggeraction 0,0,addemptybottle,0;
  
destroy;

Those three scripts WILL actually do what you want, but like I said, it'll only work in that level.

I was also thinking that in the red potion you could do something dumb like this:
PHP Code:
if (created) {
  
setstring this.origin,#L;
}

...

if (
weaponfired) {
  
playerhearts playerfullhearts;
  
setplayerprop #c, *gulp*;
  
setstring this.oldlevel,#L,#v(playerx),#v(playery);
  
setlevel #s(this.origin);
  
triggeraction 0,0,addemptybottle,0;
  
setlevel2 #I(this.oldlevel,0), strtofloat(#I(this.oldlevel,1)), strtofloat(#I(this.oldlevel,2));
  
destroy;

But I think the execution thread stops when setlevel happens, so it probably wouldn't work.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 06-22-2012 at 09:37 AM..
Reply With Quote
  #10  
Old 06-22-2012, 06:42 PM
E_Man E_Man is offline
E-Man
E_Man's Avatar
Join Date: Jun 2012
Posts: 81
E_Man will become famous soon enough
Quote:
The -best- alternative I can offer you is have a listening NPC to add the empty bottle after the red potion has been used. But unfortunately, that'll only provide a solution in that level because offline GS1 doesn't support with(levelname) stuff. Here's what I mean:

Random NPC:
PHP Code:
if (created) {
x = 0;
y = 0;
setshape 1,32,32;
dontblock;
}

if (actionaddemptybottle) {
setimg eman_water_potion.png;
toweapons Empty Bottle;
hide;
}

if (destroy) {
destroy;
}
Empty Bottle:
PHP Code:
if (playerenters) {
show;
setimg eman_water_potion.png;
}

if (playertouchsme) {
toweapons Empty Bottle;
hide;
}

if (destroy) {
destroy;
}
Red Potion:
PHP Code:
if (playerenters) {
setimg eman_red_potion.png;
show;
}

if (playertouchsme) {
if (hasweapon(Empty Bottle)) {
toweapons Red Potion;
removeEmptyBottle();
hide;
}else {
say2 You need an empty bottle.;
}
}

function removeEmptyBottle() {
for (i = 0; i < weaponscount; i ++) {
if (strequals(#w(i),Empty Bottle)) {
callweapon i,destroy;
break;
}
}
}

if (weaponfired) {
playerhearts = playerfullhearts;
setplayerprop #c, *gulp*;
triggeraction 0,0,addemptybottle,0;
destroy;
}
Those three scripts WILL actually do what you want, but like I said, it'll only work in that level.
That will work but I have to put the random npc in every room but it gets the job done and does what I want it to do. Also how would the random npc work in a gmap?
__________________
Reply With Quote
  #11  
Old 06-22-2012, 06:49 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Alternatively you can try scripting your own inventory to handle special situations like this and give you the flexibility to change the weapon names and such. A lot of work, but you're not going to get this sort of freedom with gs1.
Reply With Quote
  #12  
Old 06-22-2012, 08:48 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by E_Man View Post
That will work but I have to put the random npc in every room but it gets the job done and does what I want it to do. Also how would the random npc work in a gmap?
Quite honestly, I'm not sure how it will behave on a GMAP. You'll have to test it and see if it works by just placing the NPC only in the top left level of the GMAP. If that doesn't work, then you'll have to place it in every level probably.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:50 AM.


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