 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Mon Dec 19, 2011 6:41 pm
Need help |
Hello i have no idea about programming so forgive anything stubid you see below (propably all the code is really bad)
I have made a database to capture mobs and their location from the mud i play. It works ok but as i have it, it checks if the mob exist at the name field and if it does not it adds it at the db.
I want if it possible to check only names of mobs at the area i am in, but i can not figure how to do it
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<class name="Mobs db" copy="yes">
<alias name="mob" copy="yes">
<value>#T+ scan;#VAR mobname "";~scan here</value>
</alias>
<class name="scan" enabled="false" copy="yes">
<trigger priority="390" copy="yes">
<pattern>- (*)</pattern>
<value>#VAR mobname ""
#ADDKEY mobname {Name=%1}
#Addkey mobname {Location=%roomzone()}
#addkey mobname {RoomDescription=%roomname()}
#addkey mobname {Room=%roomkey()}
</value>
</trigger>
<trigger priority="410" copy="yes">
<pattern>$</pattern>
<value>#T- scan;#IF (!%null(@Mobname)) {#if (%null(%find(@Mobname.Name,Name))) {#NEW All @Mobname}}</value>
</trigger>
<trigger priority="440" copy="yes">
<pattern>^*</pattern>
<value>#IF (!%null(@Mobname)) {#if (%null(%find(@Mobname.Name,Name))) {#NEW All @Mobname}}</value>
</trigger>
<trigger priority="450" copy="yes">
<pattern>^Right here you see:</pattern>
<value>#IF (!%null(@Mobname)) {#if (%null(%find(@Mobname.Name,Name))) {#NEW All @Mobname}}</value>
</trigger>
</class>
<class name="fight" enabled="false" copy="yes">
<trigger priority="460" copy="yes">
<pattern>Ayla (*) of (*).</pattern>
<value>#ADDKEY mobname {Name=%2}
#Addkey mobname {Location=%roomzone()}
#addkey mobname {RoomDescription=%roomname()}
#addkey mobname {Room=%roomkey()}</value>
</trigger>
<trigger priority="410" ansi="true" copy="yes">
<pattern>PP</pattern>
<value>#IF (!%null(@Mobname)) {#if (%null(%find(@Mobname.Name,Name))) {#NEW All @Mobname}}
#T- fight</value>
</trigger>
</class>
<trigger priority="490" ansi="true" copy="yes">
<pattern>BP</pattern>
<value>#T+ fight
#VAR mobname ""</value>
</trigger>
</class>
</cmud> |
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Tue Dec 20, 2011 8:26 pm |
Keep trying to do something and it seems the #query,%query is the way to go but still cant figure it out.
Can someone explain to me why for example
#if (%numitems(%query((&Name = @mobname.name),All))=0) { no mob in db} {mob in db} results to ---> no mob in db
and #find @mobname.name does find the mob at the db.. |
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Wed Dec 21, 2011 5:06 pm |
I am giving up, too dificult for me. Propably have to check which records are at the area i am in and then check the @mobname.name against those records only. But i cant even start to think how i could do it. If anyone has the time to check it out for me i would apreciate it.
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Dec 21, 2011 8:16 pm |
The old internal database is crotchety and creaking. It is the old Zmud code essentially unchanged, and it frankly never worked great as a database. Rewriting it from scratch has been on the TODO list since the beginning of Cmud but it has a low priority. I don't see anything obviously wrong with your script, so I'm not sure what the problem is.
Cmud 3.xx does have a new feature allowing you to access external SQL databases of several varieties, including SQLITE databases which are essentially just a file format that can be stored in your session (your Cmud configuration files and map files are SQLITE files). Check out the #SQLDB, %sqldb(), and %sql() documentation. It supports ordinary SQL queries. If you use the SQLITE protocol (the default), you don't need to run an SQL server. Cmud can play directly with the SQLITE file. |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Dec 21, 2011 9:36 pm |
There's a free-for-personal-use edition of SQLite Expert for a more hands-on and GUI alternative to CMud. I use it, and as far as I can tell it's just as good if not better than any of the commercial products.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Thu Dec 22, 2011 5:32 am |
Rahab the script is working fine but it has one problem. The mud i play some times has the same names for mobs at diferent areas. What i want to do is check if the mob exist at the particular area and add it, as it is now it checks if the mob exist at the database.
So if there are two diferent mobs with the same name at tho areas just the first will be added.
Matt i am downloading it, havent have time to check it this morning will see it after work.
Hope you can understand me because my english are not the best |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Dec 22, 2011 2:31 pm |
You had stated earlier that your query wasn't working. If the script is working, then you just need to modify it to check both the name and the room number when deciding whether to add it. The query would be something like ((&Name = @mobname.name) && (&Room = @mobname.room)).
|
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Thu Dec 22, 2011 8:19 pm |
Then it would add at the db multi mobs with the same name just at diferent rooms, wouldnt it ?. I "kinda" found a solution, when i store the mob name i add at the name the zone num, so same names at diferent zones are unique. Its not the perfect solution but seems to work :)
#ADDKEY mobname {Name=%concat(%1,-,%zonenum())} |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Dec 22, 2011 11:54 pm |
Yes, if you did what I suggested it would add the same name with a different value for the room information. You didn't explain exactly what you wanted, so I gave you what I could. What would you prefer to happen?
|
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Fri Dec 23, 2011 4:43 am |
I would like to add the mob only if the name is unique at the zone-area it is in and not if it is unique at the entire database. The way i did it it works but its like using a cheap trick, changing the name--> @mobname.name acording to the area you are in. I am sure it is possible to just write a script that will check the name only to records from the area you are in but i dont know how. Hope this explains it better.
|
|
|
 |
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Dec 23, 2011 5:14 am |
Why not just add another field for zone in your database, instead of storing the zone in the mob name field?
|
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Fri Dec 23, 2011 1:45 pm |
[quote="Daern"]Why not just add another field for zone in your database, instead of storing the zone in the mob name field?[/quote]
i do have a zone field... ok i will try with an example to explain the problem
The mud i play Aardwolf has some mobs at diferent areas with the same name lets say a mob named "wolf" exists at area A and B, same name...
As the script is now it will add just the first and reject to add the second because it will find the same name at the db... Adding the zonenum at the name field was my "amateur" solution because i cant even begin to understand how to make the script to do it properly.
In the example one mob would be wolf-A and the other wolf-B, and the script will add them both |
|
|
 |
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Dec 23, 2011 5:42 pm |
Oh, yes, I see that you do have a zone field. Why not just check that too before inserting? Something like #if (%null(%query((Name=@Mobname.Name)&&(Location=@Mobname.Location)))) ?
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sat Dec 24, 2011 7:31 pm |
Yes, that's exactly what I suggested. What don't you like about that solution, Lykeas?
|
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Sun Dec 25, 2011 12:45 pm |
I dont know but it just doesnt work for me... propably i type something wrong but as much as i tried the query aproach i cant make it work..
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sun Dec 25, 2011 5:28 pm |
You'll have to explain in more detail what you mean by "it just doesn't work". We can't debug or rewrite it based on that information. Earlier you said your script _was_ working, which is why I suggested the simple modification of changing the query to check the location.
|
|
|
 |
lykeas Newbie
Joined: 04 Dec 2011 Posts: 9
|
Posted: Mon Dec 26, 2011 7:02 am |
Sorry for the slow replies, right now as it is is working fine. It adds the zone number to the name but i can live with it :). I dont know why it was not working with querie, (as i said propably by a stubid newbie mistake i was making). Now i have delete the code i had tried and i am tired to try it again. Thanks for the help guys
|
|
|
 |
|
|