Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2007, 01:29 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Question 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 )
__________________
**FLIP OUT**
Reply With Quote
  #2  
Old 05-23-2007, 01:32 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
player.chat = "I sold 5 wood for "@int(this.num)@" bucks!";
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 05-23-2007, 01:33 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Quote:
Originally Posted by JkWhoSaysNi View Post
player.chat = "I sold 5 wood for "@int(this.num)@" bucks!";
whats "int"?
__________________
**FLIP OUT**
Reply With Quote
  #4  
Old 05-23-2007, 01:42 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Integer.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #5  
Old 05-23-2007, 01:47 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Quote:
Originally Posted by JkWhoSaysNi View Post
Integer.
so by doing this it rounds it up or down?
__________________
**FLIP OUT**
Reply With Quote
  #6  
Old 05-23-2007, 01:51 AM
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
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.
Reply With Quote
  #7  
Old 05-23-2007, 01:52 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #8  
Old 05-23-2007, 01:59 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
You guys all act like rounding is so hard.
Just do int(this.num + 0.5)
__________________
Do it with a DON!
Reply With Quote
  #9  
Old 05-23-2007, 11:31 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 theHAWKER View Post
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 )
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.
__________________
Reply With Quote
  #10  
Old 05-23-2007, 11:40 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by theHAWKER View Post
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 )
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...
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #11  
Old 05-24-2007, 05:52 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
Quote:
Originally Posted by cbkbud View Post
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.
thank you.

addWeapon(Axe); works just fine with out the quotes, so is it adding the weapon by fluke?
__________________
**FLIP OUT**
Reply With Quote
  #12  
Old 05-24-2007, 08:20 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by theHAWKER View Post
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); )
Reply With Quote
  #13  
Old 05-24-2007, 01:50 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Twinny View Post
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
__________________
Do it with a DON!
Reply With Quote
  #14  
Old 05-25-2007, 12:06 AM
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 zokemon View Post
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 ); 
__________________
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 11:24 PM.


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