Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Food Bar (https://forums.graalonline.com/forums/showthread.php?t=60596)

excaliber7388 08-19-2005 09:15 PM

Food Bar
 
I'm trying to make a food system for Dark Rival. So far, i can make the person need food, and their hunger grow, etc, but i can't make it display a 'food bar, under the MP bar, that would slowly decrease. Anyone know how i would do it?

Python523 08-19-2005 09:20 PM

showimg, changeimgvis, changeimgpart

excaliber7388 08-19-2005 09:29 PM

yeah, but that puts the image at a specific x and y, on the level

Python523 08-19-2005 09:43 PM

changeimgvis.

excaliber7388 08-19-2005 09:58 PM

=/ still having trouble, but this is a start X_x
that puts it in the top corner, it moves, but it is above the asd thing X_X how your i move it down

Skyld 08-19-2005 10:08 PM

When you are working on the level layers, image X and Ys reference to coordinates on the level.
When you are working on the GUI layers, image X and Ys reference to the actual position on the screen (pixel coordinates, that is), starting from the top-left corner of the Graal window.

Idrox0 08-20-2005 04:40 AM

If you want to display the bar on the right side of the screen, do screenwidth-whatever for displaying. This ensures that people who resize their screen will still have the same format.

excaliber7388 08-20-2005 11:56 PM

im having trouble making the food points part of the bar to go down, changeimgpart in't working, but then again, im not sure i did it right. any suggestions on how to make the bar shrink by 1 each time it runs through the loop?

Maniaman 08-21-2005 02:00 AM

changeimgpart not changeimgparts

excaliber7388 08-21-2005 04:29 AM

sorry...typo X_x
i do mean changeimgpart
and nope, still cant get it. i have the bar up and lined up, the Fp runs out etc, but i cant get the bar to shrink as the food points run out. X_x

konidias 08-21-2005 04:48 AM

Can you post your changeimgpart line?

Idrox0 08-21-2005 09:40 AM

It could be a stupid mistake, such as forgetting to put the bar drawing in a repeating timeout :\. Also, a little thing in there is that if you tell it to draw the image width as 0, it will draw the entire thing. There's my two cents, but the code would be nice, yes.

xAndrewx 08-21-2005 01:32 PM

You don't need to keep updating the HP in a timeout. You can add a simple validation to check if the HP is changed from before.

konidias 08-21-2005 04:00 PM

There are multiple ways to do it. You could have the food value have a max of 100 and a min of 1. Then you just do something like:

changeimgpart index,0,0,foodvalue,10;

Which would make the food bar display from an x of 0 to an x of whatever your food value is... like if it were 50, it would display from 0 to 50, which would be half the bar, if your bar was 100 pixels in width.

Otherwise you're going to need a small formula to adjust for the difference in pixel width to food value.

excaliber7388 08-21-2005 07:19 PM

this is what I have so far, I might make it set your hearts to 1 or .5 if it tuns out, instead of killing you, that way you have time to get food:
// NPC made by Excaliber
//this script makes the player say their food points. It usually would not take 1 sec to lose a point, but this was for testing, this is for offline mode right now, with toweapons I will need one for online mode
if(playerenters){client.food=100;}
//#CLIENTSIDE
if(playerenters){
client.food=100;
toweapons *Food System;}
while(isweapon){
setplayerprop #c,#v(client.food);
client.food=client.food-1;
changeimgpart 1,0,0,client.food,10;
if(client.food<1){
playerhearts=0;client.food=1}
sleep 1}
if(created){
showimg 2,drfoodbarback.png,15,115;
changeimgvis 2,4;
showimg 1,drfoodbarfp.png,37,121;
changeimgvis 1,4;}
if(playerchats&&strequals(#c,/food)){
setplayerprop #c,#v(client.food)}

projectigi 08-21-2005 08:07 PM

maybe u should use code tags
NPC Code:

//#CLIENTSIDE
if(playerenters){
setstring client.food,;
toweapons *Food System;
}
if(created){
showimg 2,drfoodbarback.png,15,115;
changeimgvis 2,4;
showimg 1,drfoodbarfp.png,37,121;
changeimgvis 1,4;
timeout=1;
}
if(timeout){
setplayerprop #c,#v(client.food);
setstring client.food,#v(strtofloat(#s(client.food))-1);
changeimgpart 1,0,0,imgwidth(drfoodbarfp.png)/100*strtofloat(#s(client.food)),imgheight(drfoodba rfp.png);
if(strtofloat(#s(client.food))<1){
setstring client.food,1;
playerhearts=0;
}
timeout=1;
}
if(playerchats&&strequals(#c,/food)){
setplayerprop #c,#v(client.food);
}




hmm i think u should use setstring instead of client.food=;
then use probably want to use a timeout...
didnt test it cuz i dont have the images
and i used the imgwidth and imageheight cuz i dont know how width/height your images are

Skyld 08-21-2005 08:34 PM

Quote:

Originally Posted by excaliber7388
this is what I have so far, I might make it set your hearts to 1 or .5 if it tuns out, instead of killing you, that way you have time to get food:
// NPC made by Excaliber
//this script makes the player say their food points. It usually would not take 1 sec to lose a point, but this was for testing, this is for offline mode right now, with toweapons I will need one for online mode
if(playerenters){client.food=100;}
//#CLIENTSIDE
if(playerenters){
client.food=100;
toweapons *Food System;}
while(isweapon){
setplayerprop #c,#v(client.food);
client.food=client.food-1;
changeimgpart 1,0,0,client.food,10;
if(client.food<1){
playerhearts=0;client.food=1}
sleep 1}
if(created){
showimg 2,drfoodbarback.png,15,115;
changeimgvis 2,4;
showimg 1,drfoodbarfp.png,37,121;
changeimgvis 1,4;}
if(playerchats&&strequals(#c,/food)){
setplayerprop #c,#v(client.food)}

Please, format your code. It will make it both easier to read and easier to spot syntax errors.
  • Because you are closing a block of code is no reason not to use ';', so don't do sleep 1 (without the ';') and close the block
  • When you are only using one command as a result of an if check, you do not need to use '{' and '}', i.e. if (playerchats && strequals(#c,/food)) setplayerprop #c,#v(client.food);
  • Use some spacing. if(client.food<1){ is almost harder to look at than if (client.food < 1) {
  • Close blocks on a new line, don't do sleep 1;}
  • Use indentation, and when posting code on the forums, surround it with [code] tags to preserve indentation

konidias 08-21-2005 08:36 PM

It's probably better if you used clientr. strings, unless you don't care about people cheating your system and using a memory editor to make it so their hunger meter never goes down.

Amagius 08-21-2005 08:56 PM

Quote:

Originally Posted by konidias
It's probably better if you used clientr. strings, unless you don't care about people cheating your system and using a memory editor to make it so their hunger meter never goes down.

I would do it.

excaliber7388 08-21-2005 09:49 PM

clietntr?
i used them once for a weapons saver, but i wasn't 100% what they were for X_x
btw, i got it to work, yours wasn't perfect, but i couldnt do it w/o it thanks! :D

Skyld 08-22-2005 11:05 AM

Quote:

Originally Posted by excaliber7388
clietntr?
i used them once for a weapons saver, but i wasn't 100% what they were for X_x
btw, i got it to work, yours wasn't perfect, but i couldnt do it w/o it thanks! :D

clientr. strings are readable both clientside and serverside, but can only be written to on the serverside.
client. strings are readable and writable both on the clientside and the serverside.

excaliber7388 08-22-2005 05:29 PM

it works fine off line, but i'm having trouble online here is the current script i'm using:
NPC Code:
//#CLIENTSIDE
if(playerenters){
setstring client.food,100;
toweapons *Food System;
}
if(created){
showimg 2,drfoodbarback.png,15,115;
changeimgvis 2,4;
showimg 1,drfoodbarfp.png,37,121;
changeimgvis 1,4;
timeout=1;
}
if(timeout){
sleep 0;setstring client.food,#v(strtofloat(#s(client.food))-1);
changeimgpart 1,0,0,imgwidth(drfoodbarfp.png)/100*strtofloat(#s(client.food)),imgheight(drfoodba rfp.png);
if(strtofloat(#s(client.food))<2.1){
setstring client.food,2;
playerhearts=.5;
}
timeout=1;
}
if(strtofloat(#s(client.food))=5){
setplayerprop #c, I'm so hungry!;
}
if(strtofloat(#s(client.food))<1){
setstring client.food,1;
playerhearts=.5;
}
if(weaponfired){say2 You have to eat#bevery few hours.#bThe third bar at the top#bis for food.#bIf it runs out you#b will become very weak.;setplayerprop #c,#s(client.food)}


Polo 08-22-2005 06:17 PM

Quote:

Originally Posted by excaliber7388
toweapons *Food System;

Really, don't use toweapons on your server. x_x

excaliber7388 08-22-2005 10:32 PM

it wasn't toweapons, but i got it fixed :D
but now im having more problems w/ the food. i have putnpc enabled, but for some reason, it's not puiing in npc, what could be wrong?

xAndrewx 08-23-2005 11:18 AM

Paste the putnpc2 script? lol.

excaliber7388 08-23-2005 05:01 PM

i wasn't aware there was a putnpc2 command =/
whats the format of it?

xAndrewx 08-23-2005 08:57 PM

putnpc2 x,y,{script};

calani 08-23-2005 10:26 PM

Quote:

Originally Posted by excaliber7388
while(isweapon){

While() while online = while. Er, I mean bad.

ForgottenLegacy 08-23-2005 10:34 PM

Quote:

Originally Posted by calani
While() while online = while. Er, I mean bad.

Translation: Don't use the while() function serverside. It would crash a server. z-z

excaliber7388 08-24-2005 01:18 AM

yeah i've noticed...tons of lag X_x

Luigi203 08-24-2005 01:34 AM

Quote:

Originally Posted by ForgottenLegacy
Translation: Don't use the while() function serverside. It would crash a server. z-z

Uuuh? If its not used properly it will crash a server...? I used it several times and it never crashed the server.


NPC Code:


if (created) i = 0;

while (i < 10) i++;


excaliber7388 08-24-2005 02:54 AM

when it's loading it lags alot, and with multiple players in the level, or many NPCs, you could have trouble. X_x

Fry 08-24-2005 12:17 PM

That's why you put things in an event block and NOT outside.
You can use while, just make sure it isn't an infinite loop.

Skyld 08-24-2005 12:17 PM

Quote:

Originally Posted by Luigi203
Uuuh? If its not used properly it will crash a server...? I used it several times and it never crashed the server.


NPC Code:


if (created) i = 0;

while (i < 10) i++;


Why not just use for (i=0; i<0; i++)?

Anyway. Using while serverside to run as many loops as it possibly can (not just 10 in your case) will likely cause problems on a server.

ForgottenLegacy 08-24-2005 04:59 PM

Infinite loops serverside have crashed servers. I've personally watched someone do this on Doomsday z-z and I accidentally did it myself on Babylon. You want the serverside script to run /once/, and that's only when changing clientr strings or adding/removing weapons, etc. You shouldn't use showimg or any image commands serverside, unless you have to, due to the lack of a triggeraction to clientside in level npcs z-z HINT HINT STEFAN!

Infinite loops = bad
Infinite loops serverside = very bad

Skyld 08-24-2005 05:00 PM

Quote:

Originally Posted by ForgottenLegacy
Infinite loops serverside have crashed servers. I've personally watched someone do this on Doomsday z-z and I accidentally did it myself on Babylon. You want the serverside script to run /once/, and that's only when changing clientr strings or adding/removing weapons, etc. You shouldn't use showimg or any image commands serverside, unless you have to, due to the lack of a triggeraction to clientside in level npcs z-z HINT HINT STEFAN!

Infinite loops = bad
Infinite loops serverside = very bad

You should not use showimg or image commands serverside, period.

calani 08-24-2005 09:16 PM

Quote:

Originally Posted by Skyld
You should not use showimg or image commands serverside, period.

do they even work serverside....?

ForgottenLegacy 08-24-2005 09:43 PM

Quote:

Originally Posted by Skyld
You should not use showimg or image commands serverside, period.

For debug purpouses, you have to from time to time. It is frowned upon, but there is usually no possible way around it to show an image using information gathered from a serverside part of a level or DB npc.

Calani: showtext() does not work serverside. Showimg() and Showimg(@@@) DO work serverside.

calani 08-24-2005 09:47 PM

o.o kay.
waiiiit, how aobut serverside in levelnpcs? (such as from joined classes)

ForgottenLegacy 08-24-2005 09:48 PM

Quote:

Originally Posted by calani
o.o kay.
waiiiit, how aobut serverside in levelnpcs? (such as from joined classes)

Quote:

Originally Posted by ForgottenLegacy
It is frowned upon, but there is usually no possible way around it to show an image using information gathered from a serverside part of a level or DB npc.

o-o

EDIT
Eep, didn't clarify. Information gathered from/by (I use those two words interchangeably, they mean the same thing to me z-z) and used by the same or another level or DB npc.


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

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