Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Sat Feb 10, 2007 2:33 am   

Big Database script
 
I have two databases, player.db and murder.db.

One stores player information (and does so quite well, thanks Xianfu). The other stores information about each playerkill.

The Triggers that put information into these databases all work perfectly.

Now I'm trying to figure out how to report the data from the murder.db to the players.

For example:
Quote:
[Ghost] John Bob vs Tom

Display [Bob: 5, Tom: 3]
....indictating that Bob has killed Tom 5 times, and Tom has killed Bob 3 times. "John" is the player requesting the information.

The fields in murder.db are as follows:
Quote:
Killer
KillerClass
KillerClan
Victim
VictimClass
VictimClan
Timestamp

From this information, players should be able to do 9 things:
Quote:
1 Clan vs Clan
2 Clan vs Class
3 Clan vs Player
4 Class vs Clan
5 Class vs Class
6 Class vs Player
7 Player vs Clan
8 Player vs Class
9 Player vs Player

(Yes I realize some of these are essential mirror duplicates. This is to avoid forcing the mudder to use any particular order.)

I need error reporting for several problems:
Quote:
If the two clans they request are the same clan (clans can't kill their own members).
If the player they request is an Immortal.
If the player they request does not exist.
If the two players they request are the same person (players can't commit suicide).


In the next post, I will paste the script I'm working with. It's large and kludgy. It does the first 5 items just fine (including the clan=clan error reporting), but gets stuck on Class vs Player, and does none of the items after that.

Any help will be greatly appreciated.
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Sat Feb 10, 2007 2:34 am   
 
Code:
#CLASS {PlayerData|MurderBot|temp}
#TRIGGER {~[Ghost~] (*) (%w) {versus|vs} (%w)} {
  #VAR SubjectA %proper( %2)
  #VAR SubjectB %proper( %3)
  #DBLOAD murder
  #IF (%ismember( @SubjectA, @listclan)) {
    #IF (%ismember( @SubjectB, @listclan)) {
      #IF (@SubjectA=@SubjectB) {ghost Clans can't decapitate their own members!} {
        #VAR vartemp1 %query( (&KillerClan=@SubjectA) & (&VictimClan=@SubjectB))
        #VAR vartemp2 %query( (&KillerClan=@SubjectB) & (&VictimClan=@SubjectA))
        #VAR var1 %numitems( @vartemp1)
        #VAR var2 %numitems( @vartemp2)
        #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
        }
      } {
      #IF (%ismember( @SubjectB, @listclass)) {
        #VAR vartemp1 %query( (&KillerClan=@SubjectA) & (&VictimClass=@SubjectB))
        #VAR vartemp2 %query( (&KillerClass=@SubjectB) & (&VictimClan=@SubjectA))
        #VAR var1 %numitems( @vartemp1)
        #VAR var2 %numitems( @vartemp2)
        #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
        } {
        #VAR vartemp1 %query( (&KillerClan=@SubjectA) & (&Victim=@SubjectB))
        #VAR vartemp2 %query( (&Killer=@SubjectB) & (&VictimClan=@SubjectA))
        #VAR var1 %numitems( @vartemp1)
        #VAR var2 %numitems( @vartemp2)
        #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
        }
      }
    } {
    #IF (%ismember( @SubjectA, @listclass)) {
      #IF (%ismember( @SubjectB, @listclan)) {
        #VAR vartemp1 %query( (&KillerClass=@SubjectA) & (&VictimClan=@SubjectB))
        #VAR vartemp2 %query( (&KillerClan=@SubjectB) & (&VictimClass=@SubjectA))
        #VAR var1 %numitems( @vartemp1)
        #VAR var2 %numitems( @vartemp2)
        #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
        } {
        #IF (%ismember( @SubjectB, @listclass)) {
          #VAR vartemp1 %query( (&KillerClass=@SubjectA) & (&VictimClass=@SubjectB))
          #VAR vartemp2 %query( (&KillerClass=@SubjectB) & (&VictimClass=@SubjectA))
          #VAR var1 %numitems( @vartemp1)
          #VAR var2 %numitems( @vartemp2)
          #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
          }
        } { //This is where it stops working. Nothing below this line works.//
        #VAR vartemp1 %query( (&KillerClass=@SubjectA) & (&Victim=@SubjectB))
        #VAR vartemp2 %query( (&Killer=@SubjectB) & (&VictimClass=@SubjectA))
        #VAR var1 %numitems( @vartemp1)
        #VAR var2 %numitems( @vartemp2)
        #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
        } {
        #IF (%ismember( @SubjectB, @listclan)) {
          #VAR vartemp1 %query( (&Killer=@SubjectA) & (&VictimClan=@SubjectB))
          #VAR vartemp2 %query( (&KillerClan=@SubjectB) & (&Victim=@SubjectA))
          #VAR var1 %numitems( @vartemp1)
          #VAR var2 %numitems( @vartemp2)
          #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
          } {
          #IF (%ismember( @SubjectB, @listclass)) {
            #VAR vartemp1 %query( (&Killer=@SubjectA) & (&VictimClass=@SubjectB))
            #VAR vartemp2 %query( (&KillerClass=@SubjectB) & (&Victim=@SubjectA))
            #VAR var1 %numitems( @vartemp1)
            #VAR var2 %numitems( @vartemp2)
            #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
            } {
            #DBLOAD player
            #IF (%numitems( %query( ((&Name = @SubjectA)), All)) > 0) {#IF (%numitems( %query( ((&Name = @SubjectB)), All)) > 0) {
                #IF (%ismember( @SubjectA, @Immortal)) {#IF (%ismember( @SubjectB, @Immortal)) {ghost Your eyes cannot withstand the wars of Immortals!} {ghost @SubjectB is not worthy to fight @SubjectA!}} {
                  #IF (%ismember( @SubjectB, @Immortal)) {ghost @SubjectA is not worthy to fight @SubjectB!} {
                    #IF (@SubjectA=@SubjectB) {ghost Players cannot kill themselves!} {
                      #DBLOAD murder
                      #VAR vartemp1 %query( (&Killer=@SubjectA) & (&Victim=@SubjectB))
                      #VAR vartemp2 %query( (&Killer=@SubjectB) & (&Victim=@SubjectA))
                      #VAR var1 %numitems( @vartemp1)
                      #VAR var2 %numitems( @vartemp2)
                      #SEND %expand( ghost %concat( ~{C~[~{Y@SubjectA~{C: ~{W@Var1~{C, ", ", ~{Y@SubjectB~{C: ~{W@Var2 ~{C~]))
                      }
                    }
                  }
                } {ghost @SubjectB does not exist}} {ghost @SubjectA does not exist}
            }
          }
        }
      }
    }
  }
#CLASS 0
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Mon Feb 12, 2007 9:53 am   
 
Wow.

46 views and no one can figure it out....

Glad I'm not the only one.

*edit: hmm...looks like it counts all views, not just unique ones...looks like those 46 (now 50) views might've been all mine...:(
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 12, 2007 10:48 am   
 
I had a look at it back when you first posted it, but you've done it in the most horridly unreadable way by making all the #ifs nested. Rewriting the whole thing to make it more readable would probably be faster. Once again, I'm wishing this was a CMUD script so you could just use #switch.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Mon Feb 12, 2007 10:53 am   
 
Yeah...the nested #IFs are horrendous....

I just checked out the cMud forums for the #SWITCH command/function, and yeah: it would be perfect for this and about a dozen other things I do in zMud. I'm waiting for the new Database module before I bother upgrading to cMud. :)

Back to the problem: I first tried a #CASE statement, but upon further investigation it didn't seem appropriate.

It's just that's there's so many things to check when the trigger fires, I couldn't find a better way to make it settle on the right data to report without the nested #IFs.

I have seen worse nested #IF on these forums though...:)

Any ideas?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 12, 2007 11:20 am   
 
Well, because all the nine (twelve if you count one or more not existing) different states are unique, you can just have an #if for each. The expressions used for each #if get more complicated (#if (%ismember(@SubjectA,@listclans) AND %ismember(@SubjectB,@listclans) AND @SubjectA=@SubjectB) - hooray!) but the script as a whole gets easier to understand, especially if you have a comment before each explaining what it's checking for. Personally, I'd put the impetus on the player to define whether each subject is a clan/class/player and do away with the whole thing :P
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Mon Feb 12, 2007 11:46 am   
 
The problem I see with doing individual #IF statements is that there's no check in place for players.

To explain (for example):

For Clan vs Clan I can do:
Code:

#IF ((%ismember( @SubjectA, @listclan)) & (%ismember( @SubjectB, @listclan))) {true}

For Clan vs Class I can do:
Code:

If ((%ismember( @SubjectA, @listclan)) & (%ismember( @SubjectB, @listclass))) {true}

But for Clan vs Player, I can't do:
Code:

IF ((%ismember( @SubjectA, @listclan)) & (%ismember( @Subject, @listplayer))) {true}

...Because there's no stringlist named @listplayer. Unlike the different classes, and different clans (which are fixed), there are hundreds of players.

Now I suppose if %ismember worked on a database column, like so:
Code:
#IF (%ismember( @SubjectA, @Name.player.db))
then that would work just fine. Unfortunately, none of the functions that seem like that should work (%iskey, %db) do -quite- what I want.

-Merc-
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 12, 2007 11:54 am   
 
Well, you already solved that problem yourself in the script above:

%numitems( %query( ((&Name = @SubjectA)), All)) > 0

will detect if the subject is a player.

EDIT: Though for speed you may want to only %query once and create a variable you can check instead.
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Mon Feb 12, 2007 12:05 pm   
 
-facepalm-

I was totally thinking about another problem when I wrote that. Hah.

While you're here, the other problem is:

In the player.db, with four fields (Name, Class, Clan, IP), given a player name: how would I do a query to find that player's class?

For example:
Quote:
Record 1pl: Bob, Mage, TheChosen, 192.168.1.1

From that example, if I input "Bob", I'd like to get "Mage" back.

I'm working on the individual #IFs now...:|
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 12, 2007 12:31 pm   
 
Hmm... I'm not sure how well this would work, having not tested it, but the %query command will spit out the player's record number, and then can't you use %db in conjunction with %dbget, like this:

PlayerRecNumber=%query( ((&Name = @SubjectA)), All)
PlayerClass=%db(%dbget(@PlayerRecNumber),Class)
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
mercatroid
Wanderer


Joined: 06 Dec 2004
Posts: 59

PostPosted: Tue Feb 13, 2007 2:10 am   
 
Xianfu, everything seems to be working fine.

Thanx for all your help.

Merc
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net