Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Issue with joining player to class, using DBNPC functions. (https://forums.graalonline.com/forums/showthread.php?t=134263638)

Mark Sir Link 06-22-2011 09:30 PM

Issue with joining player to class, using DBNPC functions.
 
Issue: After joining a player to a class, calling functions defined in the class only works within a with statement. Trying to execute them by other means causes the class itself to never be invoked. Example given:

I'm not sure what is causing this behavior in which class calls work fine inside of a with statement, but do not work outside of it.

PHP Code:

with(findplayer("Mark Sir Link")){
  
addhat3(922);  //successfully manipulates SQL row
  
echo(hashat3(922)); //returns true
}
findplayer("Mark Sir Link").addhat3(921); //does not call class
echo(findplayer("Mark Sir Link").hashat3(921)); //returns false
} 

class:
PHP Code:

function onCreated(){
  
this.sqlcontrol = findnpc("SQL-Control");
}
function 
hashat3(temp.i){
  
client.showhats = gethats3();
  return 
this.sqlcontrol.playerHasHat(player, i);
}

function 
addhat3(temp.i){
  
this.sqlcontrol.playerAddHat(player, i);
  
client.showhats = gethats3();
}

function 
removehat3(temp.i){
  
this.sqlcontrol.playerRemoveHat(player, i);
  
client.showhats = gethats3();
}

function 
gethats3(){
  return 
this.sqlcontrol.playerGetHats(player);
} 

DB-NPC:
PHP Code:

public function playerHasHat(temp.pl, temp.i){
  return (
i in playerGetHats(pl));
}

public function 
playerGetHats(temp.pl){
  
temp.query = "SELECT censored FROM censored WHERE account='%s'";
  
temp.ret = reqsql2("censored", format(query, pl.account), true);
  return 
ret[0].hats.tokenize(",");
}

public function 
playerRemoveHat(temp.pl, temp.i){
  
temp.hats = playerGetHats(pl);
  
temp.hats.remove(i);
  
temp.query = "UPDATE censored SET censored='%2$s' WHERE account ='%1$s'";
  
reqsql2("censored", format2(query, {pl.account, hats}), false);
  
savelog2("hatdbSQL_log.txt","hat" @ i @ " removed from " @ pl.account);
}

public function 
playerAddHat(temp.pl, temp.i){
  
temp.hats = playerGetHats(pl);
  
temp.hats.add(i);
  
temp.query = "UPDATE censored SET censored='%2$s' WHERE account ='%1$s'";
  
reqsql2("censored", format2(query, {pl.account, hats}), false);
  
savelog2("hatdbSQL_log.txt","hat" @ i @ " added to " @ pl.account);
}



function 
reqsql2(temp.db, temp.query, temp.waitfor){
  
temp.req = requestsql2(db, query, waitfor);
  
  if(
req.error != ""){
    echo(
req.error, query);
  }
  
  if(!
waitfor){
    return;
  }
  
  if(!
req.completed){
    
waitfor(req, "onReceiveData", 60);
  }
  return 
req.rows;
} 


0PiX0 06-22-2011 09:56 PM

Seems somewhat similar to this issue:

PHP Code:

for (temp.pl: findlevel("somelevel.nw").players) {
  
//does not work
  
temp.pl.findweapon("myweapon").trigger("Event");

  
//works
  
with (temp.pl) {
    
findweapon("myweapon").trigger("Event");
  }
} 


cbk1994 06-22-2011 11:28 PM

Make the functions public in the class you join to the player.

fowlplay4 06-22-2011 11:47 PM

Quote:

Originally Posted by 0PiX0 (Post 1655820)
Seems somewhat similar to this issue:

PHP Code:

for (temp.pl: findlevel("somelevel.nw").players) {
  
//does not work
  
temp.pl.findweapon("myweapon").trigger("Event");

  
//works
  
with (temp.pl) {
    
findweapon("myweapon").trigger("Event");
  }
} 


Try:

temp.pl.weapons[temp.pl.weapons.index((@"myweapon"))].trigger("Event");

I don't believe findweapon would be a player function. Then you could do something like this in a player-joined class:

PHP Code:

public function triggerWeapon(wep, a, b, c, d, e, f) {
  
player.weapons[player.weapons.index((@wep))].trigger(a, b, c, d, e, f);
} 


Mark Sir Link 06-23-2011 03:15 AM

Quote:

Originally Posted by cbk1994 (Post 1655833)
Make the functions public in the class you join to the player.

They actually had been before and I tried making them not public, figuring the player should have access to those either way if it is joined to it. Was not a working fix for the issue.

cbk1994 06-23-2011 04:30 AM

Quote:

Originally Posted by Mark Sir Link (Post 1655865)
They actually had been before and I tried making them not public, figuring the player should have access to those either way if it is joined to it. Was not a working fix for the issue.

The player has access to them but you're not calling them from inside the player object.


All times are GMT +2. The time now is 05:55 AM.

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