Jump to content
  • 0
CyberDevil

[SQL] Vending NPC with items/currency from SQL table

Question

I wanted to know if it was possible to create a classic NPC vending but that takes the currency, the IDs of the items and the required cost, directly from an SQL table.
For example, I have the "shop_npc" table with the fields called "currency","item1_id":"item1_cost","item2_id":"item2_cost" and so on for other items, respectively.
The NPC must then have a query with variables that take the respective values in the above table, example (I apologize for the code taken at random but it is just an example) :

prontera,100,100,3	itemshop	SQL Shop	506, +.@currency$[.@i]+ , +.@item1_id$[.@i]+ : +.@item1_cost$[.@i]+ , +.@item2_id$[.@i]+ : +.@item2_cost$[.@i];

Original static code without sql function, here:

prontera,100,100,3	itemshop	Static Shop	506,6767,17681:5,9997:10;

I don't know how to set up a script like that but it would be very interesting because I could develop a control panel via web (FluxCP/Addon) to make this NPC configurable to any GM/Admin, obviously launching the reload command in play after the table changes.

Do you think this thing can be applied and do you know how to help me not being a good c++ coder?

p.s.: I believe that the table creation query is like this:
 

CREATE TABLE `shop_npc` (
  `id` int(11) NOT NULL,
  `currency` int(11) NOT NULL,
  `item1_id` int(11) NOT NULL,
  `item1_cost` int(11) NOT NULL,
  `item2_id` int(11) NOT NULL,
  `item2_cost` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

Edited by CyberDevil
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
On 6/21/2019 at 7:18 PM, CyberDevil said:

I wanted to know if it was possible to create a classic NPC vending but that takes the currency, the IDs of the items and the required cost, directly from an SQL table.
For example, I have the "shop_npc" table with the fields called "currency","item1_id":"item1_cost","item2_id":"item2_cost" and so on for other items, respectively.
The NPC must then have a query with variables that take the respective values in the above table, example (I apologize for the code taken at random but it is just an example) :

prontera,100,100,3	itemshop	SQL Shop	506, +.@currency$[.@i]+ , +.@item1_id$[.@i]+ : +.@item1_cost$[.@i]+ , +.@item2_id$[.@i]+ : +.@item2_cost$[.@i];

Original static code without sql function, here:

prontera,100,100,3	itemshop	Static Shop	506,6767,17681:5,9997:10;

I don't know how to set up a script like that but it would be very interesting because I could develop a control panel via web (FluxCP/Addon) to make this NPC configurable to any GM/Admin, obviously launching the reload command in play after the table changes.

Do you think this thing can be applied and do you know how to help me not being a good c++ coder?

p.s.: I believe that the table creation query is like this:
 

CREATE TABLE `shop_npc` (
  `id` int(11) NOT NULL,
  `currency` int(11) NOT NULL,
  `item1_id` int(11) NOT NULL,
  `item1_cost` int(11) NOT NULL,
  `item2_id` int(11) NOT NULL,
  `item2_cost` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

Sorry i dont really get the whole idea. What you mean is you want an npc basically open an item shop base on the table shop_npc in your database?

Link to comment
Share on other sites

  • 0

Yes exactly, but I have already verified that it is not technically possible to do this, so I found a good solution (not very secure but working)... I created a symbolic link from the custom NPC folder (in rAthena) to a .txt file in an accessible folder via the web (under my url site). Then I created a simple FluxCP add-on accessible only to ADMIN where it is a simple PHP code for reading and editing the .txt file in a textarea field, similar to this one:
 

<?php
if($_POST['Submit']){
$open = fopen("npc.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />"; 
echo "File:<br />";
$file = file("npc.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("npc.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
} 
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>

This is just an example of the code because in reality it is a bit different to be adapted to other functions of this my add-on, but basically it works like this... in fact if you try to put this php file in the same folder as the .txt file, you can still read it and edit it via web but you don't have any authentication and anyone can modify it, while under add-on you can take advantage of the FluxCP protection and authentication.
Obviously, once the .txt file has been modified, the reload command must be launched.

Edited by CyberDevil
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.