Jump to content
  • 0

Trying to get server variable to showup in FluxCP with php...


Peopleperson49

Question


  • Group:  Members
  • Topic Count:  218
  • Topics Per Day:  0.05
  • Content Count:  1180
  • Reputation:   141
  • Joined:  01/27/12
  • Last Seen:  

I'm trying to get a server variable to show up in my FluxCP using php. Basically I want to show my bank account balance on the zeny ranking page. I have been working on it for a long time so I figured I'm at the point of asking for help! I used the code below.

At the top I used this:

$sql  = "SELECT Balance FROM BankBalance AS bbalance";
$sth = $server->connection->getstatement($sql);
$bankbalance = $sth->fetchAll();

Farther down in the actual table I used this. This results in an error, Notice: Trying to get property of non-object in /usr/html/themes/default/ranking/zeny.php on line 60 0.

<td><?php echo number_format($bankbalance->bbalance) ?></td>

On logout this is updated:

if(#assistantbankbalance) {
 set .@cid, getcharid(0);
 query_sql("SELECT char_id FROM BankBalance WHERE char_id = "+ .@cid, .@HasBankRecord);
 if(.@HasBankRecord) { query_sql("UPDATE BankBalance SET Balance = Balance + "+ #assistantbankbalance +" WHERE char_id = "+ .@cid); } else { query_sql("INSERT INTO BankBalance (char_id, Balance) VALUES ("+ .@cid +", "+ #assistantbankbalance +")"); }
}
if(trustfundbalance) {
 set .@cid, getcharid(0);
 query_sql("SELECT char_id FROM TrustBalance WHERE char_id = "+ .@cid, .@HasTrustRecord);
 if(.@HasTrustRecord) { query_sql("UPDATE TrustBalance SET Balance = Balance + "+ trustfundbalance +" WHERE char_id = "+ .@cid); } else { query_sql("INSERT INTO TrustBalance (char_id, Balance) VALUES ("+ .@cid +", "+ trustfundbalance +")"); }
}

Edited by Peopleperson49
Link to comment
Share on other sites

9 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

maybe like this ??

$sql  = "SELECT Balance FROM BankBalance AS bbalance";
$sth = $server->connection->getstatement($sql);
$sth->execute();
$bankbalance = $sth->fetchAll();

i think you need to execute it before you can fetch it ?~

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  218
  • Topics Per Day:  0.05
  • Content Count:  1180
  • Reputation:   141
  • Joined:  01/27/12
  • Last Seen:  

Thanks, not sure how I missed that since I had it there already. I guess I removed it expermenting around and forgot to put it back. Anyways, I still get the same error with it: Notice: Trying to get property of non-object in /usr/html/themes/default/ranking/zeny.php on line 62 0. I can't seem to get it to pull info from my SQL db table. Even once I figure this out I still have a lot of work because the way I currently have it is only updated upon logout, but I would really like it to be updated real time like the zeny is. When it changes in game it will update everytime somebody refreshes the screen.

Peopleperson49

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

maybe you should try show your zeny.php ?

and these php command ...or query....should be done in the modules folder..the themes folder just for html / php tag to display the contents.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  247
  • Reputation:   207
  • Joined:  10/23/12
  • Last Seen:  

It's not necessarily hard to add another char status variable in the source. This might help you with the updating part, and use less queries overall as this method will make your current, OnLogout script void. Untested but should work. You should take the time to make sure it functions as intended. Also, this pulls from char table, so if you do go this route, you'll need to transfer your current bank balance to the char table in the SQL in a new 'bankbalance' collumn.

mmo.h

FIND

#define MAX_QUEST_OBJECTIVES 3 //Max quest objectives for a quest

ADD AFTER

#define MAX_BANK #### //Replace with a number

FIND

struct mmo_charstatus {
int char_id;
int account_id;
int partner_id;
int father;
int mother;
int child;

ADD AFTER

unsigned int bankbalance;

char.c

FIND

"`robe`"

REPLACE WITH

 "`robe`,`bankbalance`"

FIND

|| SQL_ERROR == SqlStmt_BindColumn(stmt, 35, SQLDT_SHORT,  &p.robe, 0, NULL, NULL)

ADD AFTER

|| SQL_ERROR == SqlStmt_BindColumn(stmt, 36, SQLDT_UINT,  &p.bankbalance, 0, NULL, NULL)

FIND

 "`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`"

REPLACE WITH

 "`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`,`bankbalance`"

FIND

|| SQL_ERROR == SqlStmt_BindColumn(stmt, 51, SQLDT_SHORT,  &p->robe, 0, NULL, NULL)

ADD AFTER

|| SQL_ERROR == SqlStmt_BindColumn(stmt, 52, SQLDT_UINT,  &p->bankbalance, 0, NULL, NULL)

FIND

 (p->rename != cp->rename) || (p->robe != cp->robe)

REPLACE WITH

 (p->rename != cp->rename) || (p->robe != cp->robe) || (p->bankbalance != cp->bankbalance)

FIND

"`delete_date`='%lu',`robe`='%d'"

REPLACE WITH

  "`delete_date`='%lu',`robe`='%d',`bankbalance`='%d'"

FIND

  (unsigned long)p->delete_date,  // FIXME: platform-dependent size
  p->robe,

REPLACE WITH

  (unsigned long)p->delete_date,  // FIXME: platform-dependent size
  p->robe, p->bankbalance,

script.c

Usage:

bankbalance(+-Value);

checkbank(); Returns current bank balance

ADD NEW FUNCTIONS

BUILDIN_FUNC(bankbalance)
{
int num;
TBL_PC *sd;
sd = script_rid2sd(st);
if( sd == NULL )
 return 0;
num = script_getnum(st,2);
if(sd->bankbalance - num < 0) {
 ShowError("script:bankbalance: attempting to set bank to lower than 0 %d\n", num);
 return 1;
} else if(MAX_BANK < num + sd->bankbalance) {
 ShowError("script:bankbalance: attempting to set bank higher than max \n");
 return 1;
} else
 sd->bankbalance += num;
return 0;
}

BUILDIN_FUNC(checkbank)
{
int num;
TBL_PC *sd;
sd = script_rid2sd(st);
if( sd == NULL )
 return 0;

script_pushint(st, sd->bankbalance);
return 0;
}

BUILDIN_DEF(bankbalance,"i"),
BUILDIN_DEF(checkbank,""),

Edited by Akinari
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  218
  • Topics Per Day:  0.05
  • Content Count:  1180
  • Reputation:   141
  • Joined:  01/27/12
  • Last Seen:  

I added the source mod in but how do I add a new table in to my sql db. I know how to modify data there, but can't seem to find where to add a new on at. Rows seem to be easy enough to add, lol. Thanks.

Edit: For using src mods how would I make it share between accounts also. I'm assuming that it wouldn't go in the char table. Can I use variables in the src? For example the bankbalance is shared between all characters of an account. In game I would #bankbalance. How do I get the src to perform that way also? Thanks again.

Edit Again: Got the columns added. Not to just figure out what to do next.

I installed the changes to the src manually and made my char table using the columns bankbalance, trustbalance, and smokiebalance. However the src changes errors preventing me from recompiling. I believe I installed it just as you said. My goal is to make something similar to replace the #assitantbankbalance, trustfund, and #smokiepoint variables on my server that are only updated OnLogout. Maybe somebody will make an actual diff so I know that it works and I installed it correctly. Thanks for everybodies help.

Peopleperson49

Edited by Peopleperson49
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  247
  • Reputation:   207
  • Joined:  10/23/12
  • Last Seen:  

If you're looking to do an account variable, I suggest using a normal #variable which will update it normally. If you want to add another account variable that's stored within the login table, it's a much more in-depth process from my experience as you would need to pull up the information and store it into the session data using RFIFO and calling it across the servers with WFIFO. That's why using a normal #variable for what you need will probably be your best method, then pulling that information up from the SQL in the global_reg_value table.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  218
  • Topics Per Day:  0.05
  • Content Count:  1180
  • Reputation:   141
  • Joined:  01/27/12
  • Last Seen:  

I created the balance columns in the char table, should I remove the columns I put in there? I can also try to put the mods back in if you think it will work.

Peopleperson49

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  247
  • Reputation:   207
  • Joined:  10/23/12
  • Last Seen:  

Well it's not about what I think will work necessarily. I don't fully understand what you're aiming to do with this addition. I posted that modification because your first post contained SQL queries which were getting information from character IDs. But you say you want it account based, so that modification really isn't valid. Like I said, making your script use account (#) variables and then pulling from global_reg_table using account ID would probably be easiest.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  218
  • Topics Per Day:  0.05
  • Content Count:  1180
  • Reputation:   141
  • Joined:  01/27/12
  • Last Seen:  

If you check out my website at www.ro-underground.com on the home page you will see the Wealth ranking towards the bottom center you will see where I got it to use the variables for that. However, its not like the normal zeny ranking. For example when you go to the normal FluxCP zeny ranking and refresh it pulls all characters latest zeny amounts. I currently have it up to only update when a characters OnPCLogin or OnPCLogout so all ingame changes are not updated until that point. I'm trying to get it to pull from a table to always be updated. Thanks.

Peopleperson49

Link to comment
Share on other sites

×
×
  • Create New...