Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-06-2015, 09:39 PM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Player Classes and Variables

I am attempting to create player. variables through a player-joined class. If this is not possible, then I suppose that is valuable information, and I will resort to something like clientr. variables, but nonetheless, I thought logically I would be able to create player. variables within a class when it's joined by using this. variables in the class.

I am attaching a class to a player upon log-in in the Control-NPC, as such:

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

Afterwards, in the class itself, I am attempting to set the player variables:

PHP Code:
function onCreated() {
  
this.foo 1;
  
this.bar 2;

I have also attempted the following within the class:

PHP Code:
function onCreated() {
  if ( 
this.foo == NULL && this.bar == NULL ) {
    
createVariables();
  }
}

function 
createVariables() {
  
this.foo 1;
  
this.bar 2;

I have also attempted using a weapon NPC to check the player variables and then consequently call upon a public function within the class to set said player variables:

Weapon NPC:
PHP Code:
function onCreated() {
  if ( 
player.foo == NULL && player.bar == NULL ) {
    
player.createVariables();
  }

Class NPC:
PHP Code:
public function createVariables() {
  
this.foo 1;
  
this.bar 2;

I thought this was a simple matter, but I'm not getting any return from what I can tell. Any ideas?

EDIT: Solved. For future reference for all of those rusty folk like myself out there, here is what worked for me:

Control-NPC:
PHP Code:
function onActionPlayerOnline() {
  
player.join"foobar" );
  if ( 
player.foo == NULL && player.bar == NULL ) {
    
player.createVariables();
  }

Class NPC:
PHP Code:
public function createVariables() {
  
this.foo 1;
  
this.bar 2;


Last edited by devilsknite1; 05-06-2015 at 10:23 PM..
Reply With Quote
  #2  
Old 05-07-2015, 12:50 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Because you're referring directly to the player, I'd put the check INSIDE the class. Otherwise you're defying the point of player classes.

Inside the 'foobar' class I'd do the following
HTML Code:
  //Call the check on login
function onCreated() {
  this.createVariables();
}

  //Do the check here
public function createVariables() {
  if (this.foo != null && this.bar != null) return;

  this.foo = 1;
  this.bar = 2;
}
__________________
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 09:34 PM.


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