Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   rounding plz? (https://forums.graalonline.com/forums/showthread.php?t=74139)

theHAWKER 05-23-2007 01:29 AM

rounding plz?
 
I have made a shop where you can buy axe's and go chop some trees down.
then you can come back and sell your wood for a random amount of the day(well not exactly)

here is my script:
PHP Code:

function onPlayerEnters(){
this.num random(3,20);
}
function 
onPlayerChats(){
if (
player.chat == "/buy axe"){
if (
player.rupees >= 500){
player.rupees -= 500;
addweapon(Axe);
player.chat "I got an Axe!";
}
if (
player.rupees 500){
player.chat "I need more rupees for that axe!";
}
}
if (
player.chat == "/sell wood"){
clientr.woods -= 5;
player.rupees += this.num;
player.chat "I sold 5 wood for "@this.num@" bucks!";
}


there is nothing wrong with it, i just dont want it to say:
I sold 5 wood for 13.457252421932 bucks!
cause thats just redonculous(re-donk-u-lus :D)

JkWhoSaysNi 05-23-2007 01:32 AM

player.chat = "I sold 5 wood for "@int(this.num)@" bucks!";

theHAWKER 05-23-2007 01:33 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1310861)
player.chat = "I sold 5 wood for "@int(this.num)@" bucks!";

whats "int"?

JkWhoSaysNi 05-23-2007 01:42 AM

Integer.

theHAWKER 05-23-2007 01:47 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1310867)
Integer.

so by doing this it rounds it up or down?

DustyPorViva 05-23-2007 01:51 AM

No, it just removes the floating point(everything right of the decimal), and leaves you with the whole number.
If you want it to round, you'll have to make it do so yourself... I dunno why there isn't something that does so already, but ah well.

JkWhoSaysNi 05-23-2007 01:52 AM

Down, it will just strip everything after the decimal point.

If you want it to round up or down you can do this:
PHP Code:

(this.num >= 0.5) ? int(this.num)+int(this.num


zokemon 05-23-2007 01:59 AM

You guys all act like rounding is so hard.
Just do int(this.num + 0.5)

cbk1994 05-23-2007 11:31 PM

Quote:

Originally Posted by theHAWKER (Post 1310859)
I have made a shop where you can buy axe's and go chop some trees down.
then you can come back and sell your wood for a random amount of the day(well not exactly)

here is my script:
PHP Code:

function onPlayerEnters(){
this.num random(3,20);
}
function 
onPlayerChats(){
if (
player.chat == "/buy axe"){
if (
player.rupees >= 500){
player.rupees -= 500;
addweapon(Axe);
player.chat "I got an Axe!";
}
if (
player.rupees 500){
player.chat "I need more rupees for that axe!";
}
}
if (
player.chat == "/sell wood"){
clientr.woods -= 5;
player.rupees += this.num;
player.chat "I sold 5 wood for "@this.num@" bucks!";
}


there is nothing wrong with it, i just dont want it to say:
I sold 5 wood for 13.457252421932 bucks!
cause thats just redonculous(re-donk-u-lus :D)

Round of applause theHAWKER!

Looks like you're learning GS2, good job!

One thing I would like to point out however.
You used
PHP Code:

addWeapon(Axe); 

what you should use is
PHP Code:

addWeapon("Axe"); 

that way it is not trying to add whatever is in the variable 'Axe', which is most likely NULL.

Switch 05-23-2007 11:40 PM

Quote:

Originally Posted by theHAWKER (Post 1310859)
I have made a shop where you can buy axe's and go chop some trees down.
then you can come back and sell your wood for a random amount of the day(well not exactly)

here is my script:
PHP Code:

function onPlayerEnters(){
this.num random(3,20);
}
function 
onPlayerChats(){
if (
player.chat == "/buy axe"){
if (
player.rupees >= 500){
player.rupees -= 500;
addweapon(Axe);
player.chat "I got an Axe!";
}
if (
player.rupees 500){
player.chat "I need more rupees for that axe!";
}
}
if (
player.chat == "/sell wood"){
clientr.woods -= 5;
player.rupees += this.num;
player.chat "I sold 5 wood for "@this.num@" bucks!";
}


there is nothing wrong with it, i just dont want it to say:
I sold 5 wood for 13.457252421932 bucks!
cause thats just redonculous(re-donk-u-lus :D)

Eh, I just learned int too :o
Make "this.num = random(3,20);" into "this.num = int(random(3,20));" and all should be fine...

theHAWKER 05-24-2007 05:52 AM

Quote:

Originally Posted by cbkbud (Post 1311151)
Round of applause theHAWKER!

Looks like you're learning GS2, good job!

One thing I would like to point out however.
You used
PHP Code:

addWeapon(Axe); 

what you should use is
PHP Code:

addWeapon("Axe"); 

that way it is not trying to add whatever is in the variable 'Axe', which is most likely NULL.

:D thank you.

addWeapon(Axe); works just fine with out the quotes, so is it adding the weapon by fluke?

Twinny 05-24-2007 08:20 AM

Quote:

Originally Posted by theHAWKER (Post 1311291)
:D thank you.

addWeapon(Axe); works just fine with out the quotes, so is it adding the weapon by fluke?

It works because it's basically referring to this object. Similar to addweapon(this); However, you should get used to doing addweapon("string"); rather than objects. (Though I admit I often do findplayer("Twinny").addweapon(this); ^^)

zokemon 05-24-2007 01:50 PM

Quote:

Originally Posted by Twinny (Post 1311315)
It works because it's basically referring to this object. Similar to addweapon(this); However, you should get used to doing addweapon("string"); rather than objects. (Though I admit I often do findplayer("Twinny").addweapon(this); ^^)

findplayer("Twinny").addweapon(this);
findplayer("Twinny").addweapon(name);

Whatever :)

cbk1994 05-25-2007 12:06 AM

Quote:

Originally Posted by zokemon (Post 1311360)
findplayer("Twinny").addweapon(this);
findplayer("Twinny").addweapon(name);

Whatever :)

Most common thing to see at the top of one of my scripts:

PHP Code:

findPlayer"cbk1994" ).addweaponname ); 



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

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