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
  #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
 


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 04:09 AM.


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