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 06-22-2011, 09:30 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
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;
} 
Reply With Quote
  #2  
Old 06-22-2011, 09:56 PM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
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");
  }
} 
Reply With Quote
  #3  
Old 06-22-2011, 11:28 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
Make the functions public in the class you join to the player.
__________________
Reply With Quote
  #4  
Old 06-22-2011, 11:47 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by 0PiX0 View Post
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);
} 
__________________
Quote:
Reply With Quote
  #5  
Old 06-23-2011, 03:15 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #6  
Old 06-23-2011, 04:30 AM
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 Mark Sir Link View Post
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.
__________________
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:20 PM.


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