NPC-Chatsystem + BugfixNachdem ja nun längere Zeit nichts wirklich neues mehr von mir hier erschienen ist, gibt es jetzt das frisch überarbeitet NPC-Chatsystem.
Nur um gleich Missverständnisse auszuschließen: Es handelt sich hier nicht um Chatbots öder ähnliches, sondern von Usern per Chat-Kommando gesteuerte Figuren.Teff machte mich auf ein paar Fehler aufmerksam, unter anderem wurde nicht richtig abgerechnet und die Weitergabe von NPCs funktionierte nicht. Die neue Version ist nun hier verfügbar.
Doch zunächst die
Vorraussetzungen:Im Gegenzug auch gleich die
Features:(Texte in blau sind in erster Linie für den Admin interessant) Chatten über andere Figuren als den eigenen Charaker durch NPCs
Eigene Bio mit Name, Spielern, Avatar und Beschreibung für jeden NPC
Erschaffen von NPC-Figuren gegen Punkte
Jederzeit mögliches Abändern der Werte des NPCs gegen Punkte
Gemeinsame Nutzung der NPCs von mehreren Spielern (share)
Cheatschutz-Systeme gegen Namenstäuschung (Danke an Harthas)
Punkte sind Wahlweise RP-Punkte oder Donation-Points
Frei wählbare Preise für die Änderung von Name, Bscheibung, Avatar und Share der NPCs
Und schlussendlich noch ausstehende
ToDos:
Automatische Generierung von NPCs als Kinder in -Doms Kindermod
Standard Chat-Farben auch für NPCs
Unterstüttzung der NPC-Anzeige schon im JS-Preview
InstallationNachdem alle Vorrausstzungen erfüllt sind, geht es nun an die Installation.
Zunächst die Datei npc.class.php in das lib-Verzeichnis hochgeladen werden, die npc.php kommt ins LotgD-Root.
Nun muss noch folgender SQL-Query ausgeführt ...
$this->bbcode_second_pass_code('', 'ALTER TABLE `accounts` ADD npc BOOLEAN NOT NULL;
ALTER TABLE `commentary` ADD control TINYINT NOT NULL;
CREATE TABLE `npc` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`text` text character set utf8 collate utf8_unicode_ci,
`ersteller` int(10) unsigned NOT NULL default '0',
`avatar` varchar(255) default NULL,
`vater` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB;
CREATE TABLE `z_npc` (
`user_id` int(10) unsigned NOT NULL default '0',
`npc_id` smallint(5) unsigned NOT NULL default '0',
KEY `user_id` (`user_id`)
) ENGINE=InnoDB;
')
...Und ein paar Dateien verändert werden:
prefs.phpPHP:
// Suche:
$form=array(
"Einstellungen,title"
...
);
// Füge danach ein:
if($session['user']['npc']) {
require_once "lib/npc.class.php";
//$npcs = getUsrNPCsData($session['user']['acctid']);
$npcs = npc::getAllOf($session['user']['acctid'],false);
$text = "Der NPC den du im moment verwenden möchtest,enum";
foreach($npcs as $npc) {
$text .= ",".$npc->getId().",".$npc->getName();
}
} else {
$text = "Leider hast du noch keine NPCs,viewonly";
}
$form['akt_npc'] = $text;
lib/commentary.phpPHP:
// Suche:
# Einstellungen
// Füge danach ein:
require_once 'npc.class.php';
function beginsWith($in,$with) {
// Kleine Funktion für netteren Code by Auric
return (strtolower(substr($in,0,strlen($with)))===$with?true:false);
}
// Suche: [function Add()]
// Emotecheck
$emote = 0;
if(substr($commentary,0,2) === '::') {
$commentary = $this->coloremote.substr($commentary,2);
$emote = 1;
}
elseif(substr($commentary,0,1) === ':') {
$commentary = $this->coloremote.substr($commentary,1);
$emote = 1;
}
elseif(strtolower(substr($commentary,0,3)) === '/me') {
$commentary = $this->coloremote.substr($commentary,3);
$emote = 1;
}
elseif(strtolower(substr($commentary,0,3)) === '/em') {
$commentary = $this->color3person.substr($commentary,3);
$emote = 2;
}
elseif(strtolower(substr($commentary,0,2)) === '/x') {
$commentary = $this->color3person.substr($commentary,2);
$emote = 2;
}
elseif(strtolower(substr($commentary,0,3)) === '/ms') {
$commentary = $this->coloremote.substr($commentary,3);
$emote = 3;
}
else {
$commentary = $this->colorspeak.$commentary;
}
// Ersetze mit:
// Emotecheck
$emote = 0;
if(beginsWith($commentary,'::')) {
$commentary = $this->coloremote.substr($commentary,2);
$emote = 1;
} elseif(beginsWith($commentary,':')) {
$commentary = $this->coloremote.substr($commentary,1);
$emote = 1;
} elseif(beginsWith($commentary,'/me')) {
$commentary = $this->coloremote.substr($commentary,3);
$emote = 1;
} elseif(beginsWith($commentary,'/em')) {
$commentary = $this->color3person.substr($commentary,3);
$emote = 2;
} elseif(beginsWith($commentary,'/x')) {
$commentary = $this->color3person.substr($commentary,2);
$emote = 2;
} elseif(beginsWith($commentary,'/ms')) {
$commentary = $this->coloremote.substr($commentary,3);
$emote = 3;
// Erweiterte Überprüfung für NPCs by Auric:
} elseif(beginsWith($commentary,'/npc')) {
$commentary = $this->colornpc.substr($commentary,5);
$emote = 5;
} else {
$commentary = $this->colorspeak.$commentary;
}
// Suche: [function Insert()]
$sql = 'INSERT INTO `commentary` (`author`,`comment`,`section`,`emote`,`postdate`) '
// Ersetze mit:
$sql = 'INSERT INTO `commentary` (`author`,`comment`,`section`,`emote`,`postdate`'.($this->emote==5?',`control`':'').') '
// Suche: [function Insert()]
.'"'.$this->emote.'",'
.'NOW()'
// Füge danach ein:
.($this->emote==5?", '".npc::getActOf($author)."'":'')
// Suche:
if(NOBIO === false) {
$linktemplate = '`0<a href="bio.php?char={$LOGIN}&ret={$REQUESTURI}" style="text-decoration: none">'.endl.'`&{$NAME}`0</a>'.endl;
}
else {
$linktemplate = '{$NAME}';
}
// Ersetze mit:
if(NOBIO === false) {
$linktemplate = '`0<a href="bio.php?char={$LOGIN}&ret={$REQUESTURI}" style="text-decoration: none" title="{$STATUSRP}">'.endl.'`&{$NAME}`0</a>'.endl;
$npclinktemplate = '`0<a href="npc.php?op=bio&id={$ID}&ret={$REQUESTURI}" style="text-decoration: none">'.endl.'`&{$NPC}`0</a>'.endl;
} else {
$linktemplate = '{$NAME}';
$npclinktemplate = '{$NPC}';
}
$sea4linktemplateN = array('{$ID}','{$REQUESTURI}','{$NPC}');
// Suche:
switch($row['emote']) {
// Füge Danach ein:
case 5: // NPC-Erweiterung von Auric
$npcsql = "SELECT `id`, `name` FROM `npc` WHERE `id`=".$row["control"]." LIMIT 1";
$npcres = db_query($npcsql) or die(db_error(LINK));
$npc = db_fetch_assoc($npcres);
$rep4linktemplateN = array($npc['id'],RawURLEncode($REQUEST_URI),$npc['name']);
$row['npc'] = str_replace($sea4linktemplateN,$rep4linktemplateN,$npclinktemplate);
$npclink = str_replace($sea4linktemplateN,$rep4linktemplateN,'npc.php?op=bio&id={$ID}&ret={$REQUESTURI}');
addnav('',$npclink);
$comments[] = $prefix.str_replace($search,$replace,'`&'.$row['npc'].' '.$this->nl2paragraph($row['comment'])."`0\r\n");
break;
configuration.phpPHP:
// Suche:
"oldmail"=>"Alte Nachrichten automatisch löschen nach x Tagen. x =,int",
// Füge danach ein:
'NPC-Settings (NPC-System by Auric),title',
'NPC_CURRENCY' => 'Währung zum Kauf von NPCs,enum,dp,Donationpoints,rp,RP-Punkte',
'NPC_COST_ACTIVATE' => 'Kosten zum Freischalten des NPC-Modus (Standard RP:20; DP:100),int',
'NPC_COST_BUY' => 'Kaufpreis eines NPCs (Standard RP:20; DP:100),int',
'NPC_COST_NAME' => 'Preis zum Umbenennen eines NPCs (Standard RP:10; DP:50),int',
'NPC_COST_TEXT' => 'Preis zum Ändern der NPC-Beschreibung (Standard RP:3; DP:15),int',
'NPC_COST_AVATAR' => 'Preis zum Ändern des NPC-Avatars (Standard: 0),int',
'NPC_COST_GRANT' => 'Preis für eine NPC-Freigabe (Standard RP:12; DP:60),int',
'NPC_GRANT_MAX' => 'Maximale Anzahl von Spielern pro NPC (Standard: 5),int',
Speichern und HochladenSchlussendlich müsst ihr nur noch irgendwo (village.php oder so) auf die npc.php verlinken.
So, nun müsst ihr noch einmal in den Spieleinstellungen vorbeischauen und dort in den soeben angelegten Konfigurationsfeldern eure gewünschten Preise für die einzelnen Operationen angeben.
Das Wärs dann auch, euer NPC-System sollte nun lauffähig sein.
Bedenkt, das sich eure Spieler noch für einen gewissen Betrag für den NPC-Modus freischalten müssen.
Viel Spass damit,
Auric