PDA

View Full Version : Bottle Help


E_Man
06-20-2012, 11:37 PM
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:
if (playerenters) {
show;
setimg eman_water_potion.png;
}
if (playertouchsme) {
toweapons Empty Bottle;
hide;
}
if (hasweapon(Red Potion)) {
destroy;
}

Red Potion:
// 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
}

xXziroXx
06-21-2012, 03:34 PM
I believe it can be solved by running your hasweapon checks in a timeout.

E_Man
06-21-2012, 04:29 PM
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:
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:
// 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 = 0 && timeout) {
setimg eman_water_potion.png;
toweapons Empty Bottle;
}
if (timeout) {
timeout = 0.05;
}

xXziroXx
06-21-2012, 04:32 PM
Empty Bottle:

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.

cbk1994
06-21-2012, 04:35 PM
Empty Bottle:

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?

if (hasweapon(Red Potion) && timeout)

The "&& timeout" is extraneous; it's already nested in the timeout block.

xXziroXx
06-21-2012, 04:56 PM
I'm no expert in old GScript, but isn't this line redundant?

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 :p

E_Man
06-21-2012, 06:13 PM
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.

Tricxta
06-22-2012, 07:46 AM
// 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 = 0 && 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.


// 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(playerd ir)] 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;
}
}

Tigairius
06-22-2012, 09:20 AM
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:

if (playerenters) {
setimg eman_water_potion.png;
show;
}

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

if (destroy) {
destroy;
}

Red Potion:

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*;
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:

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:

if (playerenters) {
show;
setimg eman_water_potion.png;
}

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

if (destroy) {
destroy;
}


Red Potion:

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.

I was also thinking that in the red potion you could do something dumb like this:

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.

E_Man
06-22-2012, 07:42 PM
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 x_x but it gets the job done and does what I want it to do. Also how would the random npc work in a gmap?

DustyPorViva
06-22-2012, 07:49 PM
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.

Tigairius
06-22-2012, 09:48 PM
That will work but I have to put the random npc in every room x_x 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.