From: Luca P. <lpa...@us...> - 2004-10-07 13:56:23
|
Update of /cvsroot/planeshift/planeshift/www/serverconsole/npcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20008/npcs Modified Files: npc_actions.php Log Message: improved support for scripts in responses Index: npc_actions.php =================================================================== RCS file: /cvsroot/planeshift/planeshift/www/serverconsole/npcs/npc_actions.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** npc_actions.php 24 Sep 2004 09:10:41 -0000 1.10 --- npc_actions.php 7 Oct 2004 13:50:22 -0000 1.11 *************** *** 527,534 **** echo 'Available responses. One will be chosen randomly each time the NPC answers.<br>'; ! echo "You can use also variables: \$playername, \$race<br><br>"; - echo "<FORM action=index.php?page=npc_actions&operation=editresponse&responseid=$respid&area=$area&type=$type METHOD=POST><TABLE>"; while ($line = mysql_fetch_array($result, MYSQL_NUM)){ echo "<TR><TD><b>Response 1:</b></TD><TD><textarea name=response1 rows=2 cols=50>$line[0]</textarea></TD></TR>"; echo "<TR><TD><b>Response 2:</b></TD><TD><textarea name=response2 rows=2 cols=50>$line[1]</textarea></TD></TR>"; --- 527,537 ---- echo 'Available responses. One will be chosen randomly each time the NPC answers.<br>'; ! echo "You can use also variables: \$playername, \$race.<br><br>"; ! while ($line = mysql_fetch_array($result, MYSQL_NUM)){ + + // edit responses + echo "<FORM action=index.php?page=npc_actions&operation=editresponse&responseid=$respid&area=$area&type=$type METHOD=POST><TABLE>"; echo "<TR><TD><b>Response 1:</b></TD><TD><textarea name=response1 rows=2 cols=50>$line[0]</textarea></TD></TR>"; echo "<TR><TD><b>Response 2:</b></TD><TD><textarea name=response2 rows=2 cols=50>$line[1]</textarea></TD></TR>"; *************** *** 536,541 **** echo "<TR><TD><b>Response 4:</b></TD><TD><textarea name=response4 rows=2 cols=50>$line[3]</textarea></TD></TR>"; echo "<TR><TD><b>Response 5:</b></TD><TD><textarea name=response5 rows=2 cols=50>$line[4]</textarea></TD></TR>"; ! echo "<TR><TD><b>Script :</b></TD><TD><textarea name=script rows=2 cols=50>$line[5]</textarea></TD></TR>"; ! echo '<TR><TD><input TYPE=SUBMIT NAME=submit VALUE=edit></TD><TD></TD></TR>'; } echo '</TABLE></FORM>'; --- 539,581 ---- echo "<TR><TD><b>Response 4:</b></TD><TD><textarea name=response4 rows=2 cols=50>$line[3]</textarea></TD></TR>"; echo "<TR><TD><b>Response 5:</b></TD><TD><textarea name=response5 rows=2 cols=50>$line[4]</textarea></TD></TR>"; ! echo '<TR><TD><input TYPE=SUBMIT NAME=submit VALUE="save responses"></TD><TD></TD></TR></TABLE></FORM>'; ! ! // edit script ! echo "<TABLE><TR><TD><BR><BR><FORM action=index.php?page=npc_actions&operation=editresponsescript&responseid=$respid&area=$area&type=$type METHOD=POST></TD></TR>"; ! echo '<TH>action</TH><TH>use only for train</TH><TH>quest name</TH><TH>items id given</TH><TH>exp given</TH><TR><TD>'; ! ! echo '<SELECT NAME=scriptelem>'; ! echo '<OPTION value="respond">Say one response</OPTION>'; ! echo '<OPTION value="animgreet">Play greet animation</OPTION>'; ! echo '<OPTION value="train">Train player</OPTION>'; ! echo '<OPTION value="assignquest">Assign quest</OPTION>'; ! echo '<OPTION value="completequest">Complete quest</OPTION>'; ! echo '<OPTION value="offeritem">Give Item</OPTION>'; ! echo '<OPTION value="giveexp">Give Exp</OPTION>'; ! ! echo '</SELECT></TD>'; ! ! // skill field ! $query2 = 'select skill_id,name from skills '; ! $result2 = mysql_query2($query2); ! echo '<TD><SELECT name=skillname>'; ! echo '<OPTION value="empty"></OPTION>'; ! while ($line2 = mysql_fetch_array($result2, MYSQL_NUM)){ ! echo "<OPTION value=\"$line2[1]\">$line2[1]</OPTION>"; ! } ! echo '</SELECT></td>'; ! ! // quest, items, exp fields ! echo '<td><input TYPE=text NAME=questname></td><td><input TYPE=text NAME=offeritem></td><td><input TYPE=text NAME=giveexp></td></TR>'; ! ! echo '<TR><TD><input TYPE=SUBMIT NAME=submit VALUE="add action to script"></TD><TD></TD></TR></FORM>'; ! ! // delete script ! echo "<FORM action=index.php?page=npc_actions&operation=editresponsedelscript&responseid=$respid&area=$area&type=$type METHOD=POST><TABLE>"; ! ! echo '<TR><TD><BR><BR><input TYPE=SUBMIT NAME=submit VALUE="delete script"></TD><TD></TD></TR>'; ! ! echo "<TR><TD><b>Current Script <br>(just for reference) :</b></TD><TD><textarea edit=false name=script rows=3 cols=50>$line[5]</textarea></TD></TR>"; ! } echo '</TABLE></FORM>'; *************** *** 554,565 **** $response4 = $_POST['response4']; $response5 = $_POST['response5']; - $script = $_POST['script']; ! $query = "update npc_responses set response1='$response1', response2='$response2', response3='$response3', response4='$response4', response5='$response5', script='$script' where id=$responseid"; $result = mysql_query2($query); ! echo "$query"; // redirect redirectOnType($type, $area); } function viewka(){ /** --- 594,689 ---- $response4 = $_POST['response4']; $response5 = $_POST['response5']; ! $query = "update npc_responses set response1='$response1', response2='$response2', response3='$response3', response4='$response4', response5='$response5' where id=$responseid"; $result = mysql_query2($query); ! echo "$query"; // redirect redirectOnType($type, $area); } + + function editresponsescript(){ + /** + * edit script response of an NPC + */ + $responseid = $_GET['responseid']; + $type = $_GET['type']; + $area = $_GET['area']; + + $scriptelem = $_POST['scriptelem']; + $skillname = $_POST['skillname']; + $questname = $_POST['questname']; + $offeritem = $_POST['offeritem']; + $giveitem = $_POST['giveitem']; + + // get current script + $query = "select script from npc_responses where id=$responseid"; + $result = mysql_query2($query); + $line = mysql_fetch_array($result, MYSQL_NUM); + $script = $line[0]; + + // remove last part + if ($script=="") { + $script = '<response>'; + } else { + $pos = strpos($script, "</response>"); + $script = substr($script,0,$pos); + } + + if ($scriptelem=='respond') { + $script = $script . "<respond/>"; + } else if ($scriptelem=='animgreet') { + $script = $script . "<action anim=\"greet\"/>"; + } else if ($scriptelem=='train') { + $script = $script . "<train skill=\"$skillname\"/>"; + } else if ($scriptelem=='assignquest') { + $script = $script . "<assign q1=\"$questname\"/>"; + } else if ($scriptelem=='completequest') { + $script = $script . "<complete q1=\"$questname\"/>"; + } else if ($scriptelem=='offeritem') { + $script = $script . "<offer>"; + if (strpos($offeritem, ",")) { + $tok = strtok($offeritem, ","); + $script = $script . "<item id=".$tok.">"; + while ($tok = strtok(",")) + $script = $script . "<item id=".$tok.">"; + } else + $script = $script . "<item id=".$offeritem.">"; + $script = $script . "</offer>"; + + } else if ($scriptelem=='giveexp') { + $script = $script . "<complete q1=\"$questname\"/>"; + } + + $script = $script . "</response>"; + + $query = "update npc_responses set script='".$script."' where id=$responseid"; + //echo "$query"; + $result = mysql_query2($query); + + // redirect on same page + echo "<SCRIPT language=\"javascript\">"; + echo " this.location = \"index.php?page=npc_actions&operation=viewresponse&prior=0&responseid=$responseid&type=$type&area=$area\";"; + echo " </script>"; + } + + function editresponsedelscript(){ + /** + * delete script response of an NPC + */ + $responseid = $_GET['responseid']; + $type = $_GET['type']; + $area = $_GET['area']; + + $query = "update npc_responses set script='' where id=$responseid"; + //echo "$query"; + $result = mysql_query2($query); + + // redirect on same page + echo "<SCRIPT language=\"javascript\">"; + echo " this.location = \"index.php?page=npc_actions&operation=viewresponse&prior=0&responseid=$responseid&type=$type&area=$area\";"; + echo " </script>"; + + } + function viewka(){ /** *************** *** 1263,1266 **** --- 1387,1394 ---- }else if ($operation == 'editresponse'){ editresponse(); + }else if ($operation == 'editresponsescript'){ + editresponsescript(); + }else if ($operation == 'editresponsedelscript'){ + editresponsedelscript(); }else if ($operation == 'viewka'){ viewka(); |