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 ? |
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. |
In the database.
|
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)); |
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. |
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. |
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)) |
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. |
I would do something like this:
Code:
int retval = 0; 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)) |
All times are GMT -4. The time now is 04:02 PM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.