Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-21-2009, 03:45 PM
fragman85 fragman85 is offline
Banned
Join Date: Mar 2009
Location: Switzerland
Posts: 261
fragman85 is on a distinguished road
LeaveMessage()

This is my first post in the Code Gallery, I am looking for good critique to improve my coding/styling etc.

If you like my code, feel free to use/edit it.

Also I think this is quite a good example for using DataBase NPCs :o

So I made this 4 functions:

LeaveMessage(Account, MSG, DataBase)

Will create/add a Message to a Database as an array (named as the Account of the Receiver.)

CheckMessage(Account, DataBase)

Will return how many Messages are saved for an Account in a DataBase.

GetMessage(Account, Database, ID)

Will return a Message. If ID is not provided, the first one.

DeleteMessage(Account, Database, ID)

Will delete a Message, if ID is not provided the first one.

PHP Code:
function LeaveMessage(AccountMSGDataBase) {
  if (
Account && MSG && DataBase) {
    
// Edited:
      
findNPC(DataBase).this.(@ Account).add(MSG);
      return 
true;
  }
  else {
    echo(
"LeaveMessage(Account, MSG, DataBase)!");
    return 
false;
  }
}
function 
CheckMessage(AccountDataBase) {
  if (
Account && DataBase) {
    return 
findNPC(DataBase).(@ Account).size();
  }
  else {
    echo(
"CheckMessage(Account, Database!");
    return 
false;
  }
}
function 
GetMessage(AccountDataBaseID) {
  if (
Account && DataBase) {
    if (
ID 0) {
      return 
findNPC(DataBase).(@ Account)[ID 1];
    }
    else {
      return 
findNPC(DataBase).(@ Account)[0];
    }
  }
  else {
    echo(
"GetMessage(Account, DataBase, ID)!");
    return 
false;
  }
}
function 
DeleteMessage(AccountDataBaseID) {
  if (
Account && DataBase) {
    if (
ID 0) {
      
findNPC(DataBase).(@ Account).delete(ID 1);
      return 
true;
    }
    else {
      
findNPC(DataBase).(@ Account).delete(0);
      return 
true;
    }
  }
  else {
    echo(
"DeleteMessage(Account, DataBase, ID)!");
    return 
false;
  }

As I said above, I'm looking for critique ;D

Last edited by fragman85; 03-21-2009 at 09:36 PM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.