Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #21  
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
 


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 12:01 AM.


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