Jump to content
MakeWebGames

McC to NWE conversion ?


Xethenic
 Share

Recommended Posts

Hi mwg i have recently purchased nwe. i am not the best coder in the end i class myself a bit of a newbie. i am asking for help and i am struggling with the nwe code.

I am trying to convert a McC v2 mod to work with nwe but my conversion attempt is pretty poor!

I was just wondering if more conversion tutorials i have been using some bits of nw-engine.com

- $userid => $userID

- $ir["something"] => $userStats["something"]->value

- removes the include of global.php

- removes the $h->endpage

- mysql_query("something") => $db->Execute("something")

- $db->query("something") => $db->Execute("something")

- mysql_insert_id => $db->LastId()

- mysql_num_rows($q) => $q->NbRows

- $db->num_rows($q) => $q->NbRows

- item_add(...) => Item::InventoryAdd(...)

- item_remove(...) => Item::InventoryRemove(...)

- event_add(...) => SotrePersonalLog(...)

- Adds the Translate function around the echo and print strings.

 

But with others i am getting stuck

Appreciate your time

Thank you

Link to comment
Share on other sites

Thanks B for your reply

I have been trying to follow horse racing actually

Right i am having trouble with

$_POST['bet']=strip_tags($_POST['bet']);

after the hint " HINT: If you are accessing a GET or POST, make sure to use the isset function." I changed the line to

$_POST['bet']=strip_tags(isset($_POST['bet']);

now i get Error: syntax error, unexpected ';'

HINT: Maybe you forget to put a ; sign at the end of a line.

Not sure what is causing the error as i say i am not a strong coder but i like to try

Thanks

Link to comment
Share on other sites

$userid is $userId (small id) in NWE

This depends on how the query was made.

- mysql_num_rows($q) => $q->NbRows

- $db->num_rows($q) => $q->NbRows

$db->Execute("SELECT username FROM users");

or if using a variable in the query

$db->Execute("SELECT username FROM users WHERE id = ? LIMIT 1", $id);

$db->Execute("UPDATE users SET email = ? WHERE id = ? LIMIT 1", $newemail, $id);

post a snippet, or tell us an example of what you want done

Link to comment
Share on other sites

You are missing an ending ) on your line before the ;

$_POST['bet']=strip_tags(isset($_POST['bet']));

Greg

Yeah that work thanks greg but now i just have a blank page. (My crappy conversion)

 

$userid is $userId (small id) in NWE

This depends on how the query was made.

- mysql_num_rows($q) => $q->NbRows

- $db->num_rows($q) => $q->NbRows

$db->Execute("SELECT username FROM users");

or if using a variable in the query

$db->Execute("SELECT username FROM users WHERE id = ? LIMIT 1", $id);

$db->Execute("UPDATE users SET email = ? WHERE id = ? LIMIT 1", $newemail, $id);

post a snippet, or tell us an example of what you want done

Oh god looking at your exmaple i have made a total shambles of my conversion!

Not sure i want to show you what i have done lol i'm embarrassed

Link to comment
Share on other sites

First of I said small id, I meant small d.

You'd learn more if you rebuilt the module step by step, instead of plain out converting line for line.

Start out with making a module in the admin panel if you have not done so already, then make the look of the page in the created content.php

And perhaps look at how other similar modules to what you are making work.

If you dont manage to overcome the embarrassment you can PM me, and Ill try to help.

Link to comment
Share on other sites

Hey guys, I don't have a NWE license or any of the codes for it, and I've used all the tips in this forum and another, and managed to create a Safe-cracker mod (originally made for MCCodes V2 but converted for NWE by me), I definitely know theres something wrong with it, but I'll leave it up-to you guys, please tell whats wrong and I'll try to adjust it, my first go at it. (:

 

<?php

if(isset($_POST['submit'])) {
$three = rand(100,110);
if($_POST['firstthree'] != $three) {
ErrorMessage(Translate("Error, Wrong Combination!");
exit(0);
}
$two = rand(20,30);
if($_POST['secondtwo'] != $two) {
ErrorMessage(Translate("Error, Wrong Combination!";
   exit(0);
}
$one = rand(1,9);
if($_POST['lastone'] != $one) {
ErrorMessage(Translate("Error, Wrong Combination!");
   exit(0);
}
else if($_POST['firstthree'] == $three && $_POST['secondtwo'] == $two && $_POST['lastone'] == $one) {
echo Translate("You press the numbers [{$_POST['firstthree']}][{$_POST['secondtwo']}][{$_POST['lastone']}]<br />
<font color='green' size='5'>Right Combination! Congratulations!</font>");
$muny=rand(10000,400000);
$crys=rand(20,50);
$db->Execute("UPDATE `users` SET !Currency=!Currency+{$muny},crystals=crystals+{$crys} WHERE userID=$userID");
}
}
else
{
echo "<form action='safecracker.php' method='post'>
First Three: [<input type='text' name='firstthree' length='3' maxlength='3'>] <sup>Hint: 100 - 110</sup><br />
Second Two: [<input type='text' name='secondtwo' length='2' maxlength='2'>] <sup>Hint: 20 - 30</sup><br />
Last One: [<input type='text' name='lastone' length='1' maxlength='1'>] <sup>Hint: 1 - 9</sup><br />
<input type='submit' name='submit' value='Submit!'>
</form>";
}

 

Thanks!

Link to comment
Share on other sites

Hey guys, I don't have a NWE license or any of the codes for it, and I've used all the tips in this forum and another, and managed to create a Safe-cracker mod (originally made for MCCodes V2 but converted for NWE by me), I definitely know theres something wrong with it, but I'll leave it up-to you guys, please tell whats wrong and I'll try to adjust it, my first go at it. (:

Thanks!

 

if(isset($_POST['submit'])) {
$three = rand(100,110);
if($_POST['firstthree'] != $three) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return; //Stop executing content.php
}
$two = rand(20,30);
if($_POST['secondtwo'] != $two) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return;
}
$one = rand(1,9);
if($_POST['lastone'] != $one) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return;
}
else if($_POST['firstthree'] == $three && $_POST['secondtwo'] == $two && $_POST['lastone'] == $one) {
	echo Translate("You press the numbers [{$_POST['firstthree']}][{$_POST['secondtwo']}][{$_POST['lastone']}]
	<font color='green' size='5'>Right Combination! Congratulations!</font>");
	$muny=rand(10000,400000);
	$crys=rand(20,50);
	$userStats['!Currency']->value += $muny;
	$userStats['crystals']->value += $crys; //This assumes that a crystals stat has been made in the user_stat_types table

	// This will not work, stats are not stored that way in NWE
	//$db->Execute("UPDATE `users` SET !Currency=!Currency+{$muny},crystals=crystals+{$cr  ys} WHERE userID=$userID");
}
}
else
{
echo "<form action='safecracker.php' method='post'>
   First Three: [<input type='text' name='firstthree' length='3' maxlength='3'>] <sup>Hint: 100 - 110</sup>
   Second Two: [<input type='text' name='secondtwo' length='2' maxlength='2'>] <sup>Hint: 20 - 30</sup>
   Last One: [<input type='text' name='lastone' length='1' maxlength='1'>] <sup>Hint: 1 - 9</sup>
   <input type='submit' name='submit' value='Submit!'>
   </form>";
}

 

Should perhaps be its own thred, but here is my reply anyways. Added comments where there was problems

EDit: I also see now that the form action points to safecracker.php Sould instead look into using http://www.nw-engine.com/wiki/index.php/SubmitButton

Edited by Someone
Link to comment
Share on other sites

Here is a fully working version, although the html does not fit the default theme 100%

 

print_r($_POST); //Remove or comment out when not testing

if(isset($_POST['firstthree']) && isset($_POST['secondtwo']) && isset($_POST['lastone']) ) {
$three = rand(100,110);
if($_POST['firstthree'] != $three) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return; //Stop executing content.php
}

$two = rand(20,30);
if($_POST['secondtwo'] != $two) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return;
}
$one = rand(1,9);
if($_POST['lastone'] != $one) {
	ErrorMessage(Translate("Error, Wrong Combination!")); // Mising )
	return;
} else if($_POST['firstthree'] == $three && $_POST['secondtwo'] == $two && $_POST['lastone'] == $one) {
	echo Translate("You press the numbers [{$_POST['firstthree']}][{$_POST['secondtwo']}][{$_POST['lastone']}]
	<font color='green' size='5'>Right Combination! Congratulations!</font>");
	$muny=rand(10000,400000);
	$crys=rand(20,50);
	$userStats['!Currency']->value += $muny;
	//$userStats['crystals']->value += $crys; //This assumes that a crystals stat has been made in the user_stat_types table

	// This will not work
	//$db->Execute("UPDATE `users` SET !Currency=!Currency+{$muny},crystals=crystals+{$cr  ys} WHERE userID=$userID");
}
} else {
	echo "<form method='post' name='crack'>
   	First Three: [<input type='text' name='firstthree' length='3' maxlength='3' style='width: 50px;'>] <sup>Hint: 100 - 110</sup>
   	Second Two: [<input type='text' name='secondtwo' length='2' maxlength='2' style='width: 50px;'>] <sup>Hint: 20 - 30</sup>
   	Last One: [<input type='text' name='lastone' length='1' maxlength='1' style='width: 50px;'>] <sup>Hint: 1 - 9</sup>
	</form>";
	SubmitButton('Crack It', 'crack');	
}

 

Cleaned up shorter version

if(isset($_POST['firstthree']) && isset($_POST['secondtwo']) && isset($_POST['lastone']) ) {
$one = rand(1,9);
$two = rand(20,30);
$three = rand(100,110);

if($_POST['firstthree'] != $three || $_POST['secondtwo'] != $two || $_POST['lastone'] != $one){
	ErrorMessage(Translate("Error, Wrong Combination!"));
	return;
} else {
	$muny=rand(10000,400000);
	$crys=rand(20,50);

	echo Translate("You press the numbers [{$_POST['firstthree']}][{$_POST['secondtwo']}][{$_POST['lastone']}]
	<font color='green' size='5'>Right Combination! Congratulations!</font>");

	$userStats['!Currency']->value += $muny;
	//$userStats['crystals']->value += $crys; //This assumes that a crystals stat has been made in the user_stat_types table
	return;
}
} else {
	echo "<form method='post' name='crack'>
   	First Three: [<input type='text' name='firstthree' length='3' maxlength='3' style='width: 50px;'>] <sup>Hint: 100 - 110</sup>
   	Second Two: [<input type='text' name='secondtwo' length='2' maxlength='2' style='width: 50px;'>] <sup>Hint: 20 - 30</sup>
   	Last One: [<input type='text' name='lastone' length='1' maxlength='1' style='width: 50px;'>] <sup>Hint: 1 - 9</sup>
	</form>";
	SubmitButton('Crack It', 'crack');	
}
Edited by Someone
Link to comment
Share on other sites

I would would use the engine features instead of printing out the links ans such. Also you are quiet certainly missing a menu, and maybe a config.xml file ;)

Why not download the free version of the engine and try it yourself?

Okay thanks Someone for fixing and releasing the working copy, another free mod for everyone who use NWE. (:

And I'll definitely try to download a free copy of NWE later on in the day Alain. ;)

Link to comment
Share on other sites

Okay thanks Someone for fixing and releasing the working copy, another free mod for everyone who use NWE. (:

And I'll definitely try to download a free copy of NWE later on in the day Alain. ;)

 

Thanks JamesRage for your attempt on crack the safe

Thanks to someone for fixing james good effort.

The mod works well

Glad to have nice people in the community

Link to comment
Share on other sites

I did not actually mean to release it, and its not, it still needs a config file perhaps with a min and max payout setting, and a menu entry.

Get a dev/full license, and submit it to the marketplace. It will be forgotten when time buries it in this thread.

Not that I edited my last thread with a shorter version.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...