Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How do i do? (https://forums.graalonline.com/forums/showthread.php?t=134257756)

Entrok 01-24-2010 04:41 PM

How do i do?
 
Hey, im making like a family system for a server and wants to use a DB to store the family info, but how do i load it in to this script? Iknow how to load from servrr. strings, but not from a DB.

Have the following:

PHP Code:

new GuiTextListCtrl("FamilyList")
{
  
profile GuiBlueTextListProfile;
  
0;
  
width 230;
  
fitparentwidth true;
  
clearrows();
  for (
temp.0temp.serverr.familylist.size(); temp.i++)
    
addrow(temp.iserverr.familylist[temp.i]);
    
setSelectedRow(0);



fowlplay4 01-24-2010 05:25 PM

Well you'll need to use triggerserver, and triggerclient to send data back and forth to the client. Then on the server-side you can have a DB NPC called Family (using it for the sake of the example), or so on.

In your Family's DB script you can write some accessors and mutators, here's some very generic ones.

PHP Code:

// Notice that the functions are declared public
// that is so other scripts can call them directly.
public function getValue(dbvar) {
  return 
this.(@dbvar);
}

public function 
setValue(dbvarvalue) {
  
this.(@dbvar) = value;


Then in the server-side portion of your Family's weapon script, you can set and access them using it like so:

PHP Code:

function onCreated() {
  
this.db findnpc("Family");
}

function 
onActionServerSide() {
  if (
params[0] == "exampleSituation") {
    
this.db.setValue("kids"3);
  }
  else if (
params[0] == "getKidsData") {
    
temp.val this.db.getValue("kids");
    
player.triggerclient(this.name"kidsdata"temp.val);
  }
}

//#CLIENTSIDE

function onCreated() {
  
// Due to the nature of this example, I am using two 
  // triggerservers in the same call. NEVER do this in actual code.
  
triggerserver("gui"this.name"exampleSituation");
  
triggerserver("gui"this.name"getKidsData");
}

function 
onActionClientSide() {
  if (
params[0] == "kidsdata") {
    
player.chat "I have " params[1] @ " kids!";
  }



Entrok 01-24-2010 05:44 PM

Ok, but how can i get them in to the TextList after that?

fowlplay4 01-24-2010 05:52 PM

With the params received on the client-side, you can store them into variables such as this.familys, with that you can then do the following.

PHP Code:

new GuiTextListCtrl("FamilyList"

  
profile GuiBlueTextListProfile
  
0
  
width 230
  
fitparentwidth true
  
clearrows();
  
// You need to use thiso. because you'll need to reference the weapon script
  // and now the FamilyList object itself. 
  
for (temp.0temp.thiso.familys.size(); temp.i++) 
    
addrow(temp.ithiso.familys[temp.i]); 
    
setSelectedRow(0); 



Entrok 01-24-2010 06:28 PM

Thanks for the help!


All times are GMT +2. The time now is 11:57 PM.

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