Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Shovel Script (https://forums.graalonline.com/forums/showthread.php?t=87088)

[email protected] 07-26-2009 05:17 PM

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.

Pelikano 07-26-2009 05:29 PM

You could do something like:

PHP Code:

temp.shoveling_prizes = {"Treasure/Map""Treasure/Chest""Treasure/Key"};
addWeapon(shoveling_prizes[int(random(0,3))]); 


[email protected] 07-26-2009 05:35 PM

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!");



fowlplay4 07-26-2009 05:44 PM

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.

MysticX2X 07-26-2009 05:47 PM

Also try using == for if check statements.

[email protected] 07-26-2009 05:48 PM

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!");



[email protected] 07-26-2009 05:52 PM

Hmm its not adding clientr.item.NAME=QUANTITY

[email protected] 07-26-2009 05:52 PM

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.

[email protected] 07-26-2009 05:55 PM

Could someone else help me?

DustyPorViva 07-26-2009 06:43 PM

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.

ff7chocoboknight 07-26-2009 07:43 PM

if ( player.level == "jamerson-shovel.nw" )

= is equals
1 + 1 = 2

== is for comparisons
if a is like b
if ( a == b )

[email protected] 07-27-2009 12:29 PM

Dusty your script doesn't even add the weapons!

help?

Chompy 07-27-2009 01:53 PM

Quote:

Originally Posted by [email protected] (Post 1510808)
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

cbk1994 07-27-2009 03:29 PM

Quote:

Originally Posted by [email protected] (Post 1510808)
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.

Programmer 07-29-2009 09:02 PM

-
[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.

Switch 07-29-2009 09:50 PM

Quote:

Originally Posted by Programmer (Post 1511439)
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.

Novice 07-31-2009 05:56 AM

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);"

Pelikano 07-31-2009 01:20 PM

Quote:

Originally Posted by Novice (Post 1511810)
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:

DustyPorViva 07-31-2009 01:33 PM

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.

Pelikano 07-31-2009 01:37 PM

Quote:

Originally Posted by DustyPorViva (Post 1511838)
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

DustyPorViva 07-31-2009 01:48 PM

Hm... I don't remember seeing that before. Oh well! Still better to use <= though, as you can then create higher chances and such.

cbk1994 07-31-2009 01:58 PM

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.

DustyPorViva 07-31-2009 02:02 PM

Quote:

Originally Posted by cbk1994 (Post 1511850)
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.

cbk1994 07-31-2009 02:06 PM

Quote:

Originally Posted by DustyPorViva (Post 1511855)
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.

Novice 07-31-2009 06:09 PM

Quote:

Originally Posted by Pelikano (Post 1511833)
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.


All times are GMT +2. The time now is 07:50 AM.

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