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 07-26-2009, 05:17 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
Shovel Script

Hi, im working on my shovel script still and I am attempting to make it so that when you press d, it shovels, (<--that part alraedy works), and you
randomely get one of 3 weapons. Lets call them "Treasure/Map", "Treasure/Chest", and "Treasure/Key".

Basically, I would like to know how randomely adding a weapon would be dont with int ( random(.

Thanks.
Reply With Quote
  #2  
Old 07-26-2009, 05:29 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
You could do something like:

PHP Code:
temp.shoveling_prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"};
addWeapon(shoveling_prizes[int(random(0,3))]); 
Reply With Quote
  #3  
Old 07-26-2009, 05:35 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
Well this is the script.


PHP Code:
function doAddItems()
{
temp.shoveling_prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"};
addWeapon(shoveling_prizes[int(random(0,3))]);  
}
//#CLIENTSIDE
function onWeaponFired()
{
if ( 
player.level ="jamerson-shoveling.nw" )
{
setani ven_shovel,NULL;
freezeplayer 1;
doAddItems();
}
else
player.addMsg2("You must be in the shovel room to use shovel!");

Reply With Quote
  #4  
Old 07-26-2009, 05:44 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Search the forums for examples on how to use triggerserver, and on ActionServerSide.

You need to use them to call your doAddItems function on the serverside.
__________________
Quote:
Reply With Quote
  #5  
Old 07-26-2009, 05:47 PM
MysticX2X MysticX2X is offline
Prince
MysticX2X's Avatar
Join Date: Sep 2005
Posts: 2,529
MysticX2X will become famous soon enough
Also try using == for if check statements.
__________________
-Mystic

former acc: mystic2k


RIP Matt (NBK)
Reply With Quote
  #6  
Old 07-26-2009, 05:48 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
ok I got it to work, but on my systems, we use clientr.item.ITEMNAME=QUANTITY.

How would I get it to add 1 quantity when it adds the weapon? heres what I have right now.


PHP Code:
function onActionServerSidecmd )
{
  switch( 
cmd )
  {
    case 
"shovel":
    {
    
setani jamerson_shovel,NULL;
    
freezeplayer 1;
    
addWeapon(shoveling_prizes[int(random(0,3))]); 
  }
 }
}
//#CLIENTSIDE
function onWeaponFired()
{
if ( 
player.level ="jamerson-shovel.nw" )
{
triggerserver"weapon"name"shovel" );
temp.shoveling_prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"}; 
}
else
player.addMsg2("You must be in the shovel room to use shovel!");

Reply With Quote
  #7  
Old 07-26-2009, 05:52 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
Hmm its not adding clientr.item.NAME=QUANTITY
Reply With Quote
  #8  
Old 07-26-2009, 05:52 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
basically, the quantity is nothing when it adds it to you, and that defeats the purpous of the script because after you make the treasure, you sell it for cash. And quantity counts.
Reply With Quote
  #9  
Old 07-26-2009, 05:55 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
Could someone else help me?
Reply With Quote
  #10  
Old 07-26-2009, 06:43 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
PHP Code:
function onActionServerSidecmd )
{
  switch( 
cmd )
  {
    case 
"shovel":
    {
    
temp.shoveling_prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"}; 
    
findplayer(params[1]) {
      
setani jamerson_shovel,NULL;
      
freezeplayer 1;
      
clientr.item.( @ shoveling_prizes[int(random(0,3))])++;
    }
  }
 }
}
//#CLIENTSIDE
function onWeaponFired()
{
if ( 
player.level ="jamerson-shovel.nw" )
{
triggerserver"weapon"name"shovel",player.account);
}
else
player.addMsg2("You must be in the shovel room to use shovel!");

Should work. On the serverside, it is rare to have a reference to a player since the server deals with all players, so you must pass the account name of the player in the triggerserver() so you can find the player who triggered it, and then deal with them.

Also, if your servers systems are any good they would have a public function for adding items... like:
Inventory.additem(itemname,quantity);
If they don't, get them to add it.
Reply With Quote
  #11  
Old 07-26-2009, 07:43 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to all
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
if ( player.level == "jamerson-shovel.nw" )

= is equals
1 + 1 = 2

== is for comparisons
if a is like b
if ( a == b )
__________________
Reply With Quote
  #12  
Old 07-27-2009, 12:29 PM
[email protected] jamerson61894@yahoo.com is offline
Banned
Join Date: Jul 2008
Posts: 83
jamerson61894@yahoo.com is an unknown quantity at this point
Dusty your script doesn't even add the weapons!

help?
Reply With Quote
  #13  
Old 07-27-2009, 01:53 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by [email protected] View Post
Dusty your script doesn't even add the weapons!

help?
He suggested that your system should get an additem() function to handle quantity of items ;o
__________________
Reply With Quote
  #14  
Old 07-27-2009, 03:29 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 [email protected] View Post
Dusty your script doesn't even add the weapons!

help?
You need to use player.addWeapon(). Perhaps you should learn the basics of Gscript before you try to script things that involve you coming to the forums and asking how to do everything.
__________________
Reply With Quote
  #15  
Old 07-29-2009, 09:02 PM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
-
[email protected], I suggest you look through the Graal Wikipedia. It will help you a lot quicker than asking for help here. It may also benefit you to collaborate with another scripter so you can learn more about the language.
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ

Last edited by Darlene159; 07-30-2009 at 03:22 AM..
Reply With Quote
  #16  
Old 07-29-2009, 09:50 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 Programmer View Post
I suggest you look through the Graal Wikipedia. It will help you a lot quicker than asking for help here. It may also benefit you to collaborate with another scripter so you can learn more about the language.
Seriously, the GraalWiki needs some updates/changes. When I go on there to look for a function, I get about 200 unrelated pages and none of them having to do with what I'm looking for.
__________________
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.

Last edited by Darlene159; 07-30-2009 at 03:22 AM..
Reply With Quote
  #17  
Old 07-31-2009, 05:56 AM
Novice Novice is offline
Developer
Join Date: Dec 2008
Posts: 90
Novice is an unknown quantity at this point
Send a message via MSN to Novice
LOL'd at the deleted posts.

Jamerson, you may want to make a success rate on this. So maybe try
PHP Code:
temp.success int(random(1,50));
if (
success == 1) {
//continue

Also use "setani(jamerson_shovel,null);" and "freezeplayer(1);"
Reply With Quote
  #18  
Old 07-31-2009, 01:20 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by Novice View Post
LOL'd at the deleted posts.

Jamerson, you may want to make a success rate on this. So maybe try
PHP Code:
temp.success int(random(1,50));
if (
success == 1) {
//continue

Also use "setani(jamerson_shovel,null);" and "freezeplayer(1);"
That's not even his problem... yet a success rate is not bad. Even thought I think that's a little too low D:
Reply With Quote
  #19  
Old 07-31-2009, 01:33 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
Remember that random also creates a floating point, so you'd most likely want to check if 'success' was <=1, instead of just == 1. Can also simplify the matter by using int() on the random value.
Reply With Quote
  #20  
Old 07-31-2009, 01:37 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by DustyPorViva View Post
Remember that random also creates a floating point, so you'd most likely want to check if 'success' was <=1, instead of just == 1. Can also simplify the matter by using int() on the random value.
He is using int() :S
Reply With Quote
  #21  
Old 07-31-2009, 01:48 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
Hm... I don't remember seeing that before. Oh well! Still better to use <= though, as you can then create higher chances and such.
Reply With Quote
  #22  
Old 07-31-2009, 01:58 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
To clarify on what Dusty said, you really should have a player class with some basic item functions, e.g.

PHP Code:
public function addItem(itemquantity) {
  
// checks to make sure quantity is valid, etc.
  
  
this.clientr.item.(@ item) += quantity;
  
this.addWeapon(item);
  
  
// perhaps some logging?
}

public function 
removeItem(itemquantity) {
  
// checks to make sure quantity is valid
  
  
this.clientr.item.(@ item) = max(0this.clientr.item.(@ item) - quantity); // the 'max' prevents the quantity from falling below zero
  
if (this.clientr.item.(@ item) <= 0) {
    
this.removeWeapon(item);
  }
  
// perhaps some logging?
}

public function 
getItemQuantity(item) {
  return 
this.clientr.item.(@ item);

You would create a class called "player" or so, then join it to the player in the onActionPlayerOnline function in the Control-NPC, like...

PHP Code:
function onActionPlayerOnline() {
  
player.join("player");

You could then do stuff like

PHP Code:
  temp.prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"}; 
  
player.addItem(randomstring(prizes), 1); 
which would automatically handle adding the weapon, changing the quantity, and logging (if you added that).

Also, you should use player.level.name, not player.level. The former is a string, which is what you want, while the latter is an object. Unfortunately, Graal does some funny stuff which will let that work, but it's poor scripting to do so.
__________________
Reply With Quote
  #23  
Old 07-31-2009, 02:02 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
Quote:
Originally Posted by cbk1994 View Post
Also, you should use player.level.name, not player.level. The former is a string, which is what you want, while the latter is an object. Unfortunately, Graal does some funny stuff which will let that work, but it's poor scripting to do so.
I think this is one of the most frequent problems I encounter... I never remember and using the former actually works most of the time until I randomly encounter the time that player.level won't work and I sit for a day or two trying to figure out why the **** my script isn't working correctly.
Reply With Quote
  #24  
Old 07-31-2009, 02:06 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 DustyPorViva View Post
I think this is one of the most frequent problems I encounter... I never remember and using the former actually works most of the time until I randomly encounter the time that player.level won't work and I sit for a day or two trying to figure out why the **** my script isn't working correctly.
It can be quite confusing, and understandably so. The same applies to player.ani.
__________________
Reply With Quote
  #25  
Old 07-31-2009, 06:09 PM
Novice Novice is offline
Developer
Join Date: Dec 2008
Posts: 90
Novice is an unknown quantity at this point
Send a message via MSN to Novice
Quote:
Originally Posted by Pelikano View Post
That's not even his problem... yet a success rate is not bad. Even thought I think that's a little too low D:
I know, I was just giving an example and an idea.
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:29 AM.


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