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-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
  #2  
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
  #3  
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
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 03:19 AM.


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