|
|
 |
 |
 |
 |
|
 |
 |
|
 |
 |
|
 |
|
Quests::Q&A This is the quest support section |

11-25-2011, 06:17 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
Check if item exist
I may end up having to change the source myself, but before I go to the trouble I wanted to ask.
Is there any way to check in Perl for the existence of an item ? I need a simple bool response on if an item exist.
Also, maybe some of the powers that be can also answer this one. If I am changing the source, do you absolutely have to recompile every time to test ?
|

11-25-2011, 07:12 PM
|
Demi-God
|
|
Join Date: Aug 2010
Posts: 1,742
|
|
If an item exists where? In the database, a player's inventory, their bank?
If you are changing the C++ source you must recompile, stop your server, copy the executables to where your server is run from, and start your server every time.
|

11-25-2011, 07:14 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
In the database.
|

11-25-2011, 07:58 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
So far, most of this is making a fair amount of sense. There is one thing in perlparser.cpp that is not making sense, this line.
Code:
int class_id = (int)SvIV(ST(0));
Class_id is something I am using, then everything to the right is a mystery.
|

11-25-2011, 08:13 PM
|
 |
Hill Giant
|
|
Join Date: Aug 2010
Location: UT
Posts: 215
|
|
I asked this same question once here, hopefully the solution there will work for you.
As far as changing the source and compiling, yeah you have to compile every time you change something.
|

11-25-2011, 09:59 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
That is definitely going to help, I kind of had gotten all of that from the comments on the top of one of the files, which was also invaluable.
I think my problem was just not understanding the structure changes coming from C#.
Like this
if (condition)
my_action();
my_second_action();
I figured that the second action would fire, but come to find out if you have two actions, you have to encase them in {}. I kind of found that reading further into the code, I saw where that happened. It will just be a learning curve, I will not pick it all up in one night.
|
 |
|
 |

11-26-2011, 02:34 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
Trying to do something pretty funky here, making small amounts of headway and looking for a way of doing this. This is all just testing right now, so I will clean it up before I am completely done. Since I do not know jack about C++, this is 'train as you go'.
Running this query returns 1276 results, but only the id column. I am sure the result amount will be less when I am done. Anyway I want to dump these 1276 results into I guess an array, then run the random number generator on it. I thought about doing the random row thing with MySQL but everyone says that is crap and takes way too long. I figured the best way then would be to get back a small amount of results and let C++ do a random number pull on it. Anyway I do not know jack about arrays in C++, this would be super easy with C# so I am struggling. I want to take the results and put them into something, and then pull a single random and return that item's id.
Code:
if(database.RunQuery(query, MakeAnyLenString(&query,"select `id` from `items` WHERE `classes`= '%i'", class_id), errbuf, &result))
{
while((row = mysql_fetch_row(result)))
{
int32 result=0;
// take result from mysql and pull random number
return result;
}
mysql_free_result(result);
}
|
 |
|
 |

11-26-2011, 06:12 PM
|
 |
Demi-God
|
|
Join Date: Nov 2007
Posts: 2,175
|
|
I am going the other road, the PERL road. I think eventually I would find a C++ solution but I would rather not change the C++ more than I have to. During updates, it would make it more of a bitch to change.
So far the PERL way is working pretty awesome.
|
 |
|
 |

11-26-2011, 06:38 PM
|
Demi-God
|
|
Join Date: Aug 2010
Posts: 1,742
|
|
I would do something like this:
Code:
int retval = 0;
if(database.RunQuery(query, MakeAnyLenString(&query,"select `id` from `items` WHERE `classes`= '%i'", class_id), errbuf, &result))
{
int selected_row = MakeRandomInt(0, mysql_num_rows(result) - 1);
mysql_data_seek(result, selected_row);
if(row = mysql_fetch_row(result))
{
retval = atoi(row[0]);
}
mysql_free_result(result);
}
return retval;
You don't want to return the result where you did, or you will leak memory because the mysql_free_result() call will be skipped.
This will return 0 if there aren't any items that match the query. You will want to check for that in whatever code you use that calls this as an error.
The query you're using is also a bit suspect. I'm not sure what the value of class_id is, but in the best case, assuming the value is (1 << (client->GetClass() - 1)) you will only select items where the class can exclusively equip them. If the value is just what GetClass() returns then it will only return valid items for a warrior or a cleric.
You probably want something like:
Code:
if(database.RunQuery(query, MakeAnyLenString(&query,"select `id` from `items` WHERE `classes` & (1 << %i)", class_id), errbuf, &result))
Where class_id = client->GetClass() - 1.
|
 |
|
 |
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 09:37 AM.
|
|
 |
|
 |
|
|
|
 |
|
 |
|
 |