{"id":424,"date":"2015-01-12T10:46:32","date_gmt":"2015-01-12T15:46:32","guid":{"rendered":"http:\/\/blog.scad.edu\/ascarb21\/?p=424"},"modified":"2015-01-12T10:46:32","modified_gmt":"2015-01-12T15:46:32","slug":"php-code-for-the-story-event-creation-ui","status":"publish","type":"post","link":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/2015\/01\/12\/php-code-for-the-story-event-creation-ui\/","title":{"rendered":"PHP code for the Story Event Creation UI"},"content":{"rendered":"<p><code><br \/>\n\/\/1) set specific actions to choose from<br \/>\n\/\/ -fight<br \/>\n\/\/ -clear out (specify item to clear the effect)<br \/>\n\/\/ -get an item from<br \/>\n\/\/Give a list of available items as well<br \/>\n\/\/allow for on the fly item creation (generic icon) - this might wait for future releases<br \/>\n\/\/ -investigate and\/or confirm<br \/>\n\/\/ -listen to conversation<br \/>\n\/\/ - weather related? aka rain spiders, flood of bunnies - this will enable the choose odd weather ui to choose the odd weather elements<\/code><\/p>\n<p>\/\/2) set specific actors to choose from<\/p>\n<p>\/\/3) set reward\/consequence based on action<br \/>\n\/\/ &#8211; does it block the next step? Y\/N<br \/>\n\/\/ &#8211; if chained then the consequence could be fights or whatever!!<\/p>\n<p>\/\/Step one choose actions &#8211; these can CHAIN!!<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Story_Actions WHERE area = $areaid&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n<p>\/\/Step two pull NPCs choices based on area to accomendate the action<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM NPC WHERE area = $areaid&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n<p>\/\/Step three select consequence<br \/>\n\/\/is this based on a previous action?<br \/>\n\/\/does this chain?<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Reward_Punish_Action WHERE area = $areaid&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n<p>\/\/Item Creation<br \/>\n\/\/Need to select what base type whether it is a potion or weapon<br \/>\n\/\/Step One choose item base first<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Items;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<br \/>\n\/\/Step Two select Effect<br \/>\n\/\/Base weapon stats<br \/>\n\/\/Or magical health potion<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Item_effect WHERE itemtype = $itemtype&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n<p>\/\/Step three save new item to DB<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;INSERT INTO Items (colnames) VALUES (values of colnames)&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($conn-&gt;query($sql) === TRUE) {<br \/>\necho &#8220;Success&#8221;;<br \/>\n} else {<br \/>\necho &#8220;Error: &#8221; . $sql . &#8221;<br \/>\n&#8221; . $conn-&gt;error;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n<p>\/\/Odd Weather<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Weather WHERE area = $areaid&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<br \/>\n\/\/Select critter<br \/>\n<!--?php $servername = \"localhost\"; $username = \"username\"; $password = \"password\"; $dbname = \"myDB\"; \/\/ Create connection $conn = new mysqli($servername, $username, $password, $dbname); \/\/ Check connection if ($conn-->connect_error) {<br \/>\ndie(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<\/p>\n<p>$sql = &#8220;SELECT id,name,type FROM Critters WHERE area = $areaid&#8221;;<br \/>\n$results = $conn-&gt;query($sql);<\/p>\n<p>if($result-&gt;num_rows &gt; 0) {<br \/>\n\/\/Build Array<br \/>\nwhile($row = $result-&gt;fetch_assoc()) {<br \/>\necho &#8220;ID: &#8221; . $row[&#8220;id&#8221;] . &#8220;, Name: &#8221; . $row[&#8220;name&#8221;] . &#8220;, Type: &#8221; . $row[&#8220;type&#8221;] . &#8221;<br \/>\n&#8220;;<br \/>\n}<br \/>\n} else {<br \/>\necho &#8220;0 results&#8221;;<br \/>\n}<\/p>\n<p>$conn-&gt;close();<br \/>\n?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/1) set specific actions to choose from \/\/ -fight \/\/ -clear out (specify item to clear the effect) \/\/ -get an item from \/\/Give a list of available items as well \/\/allow for on the fly item creation (generic icon)&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/2015\/01\/12\/php-code-for-the-story-event-creation-ui\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,17],"tags":[],"class_list":["post-424","post","type-post","status-publish","format-standard","hentry","category-continued","category-prototype-continued"],"_links":{"self":[{"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/posts\/424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/comments?post=424"}],"version-history":[{"count":0,"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/posts\/424\/revisions"}],"wp:attachment":[{"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/media?parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/categories?post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgm-thesis.aliciascarborough.com\/blog\/wp-json\/wp\/v2\/tags?post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}