[Help CoEmu V2] Lil help on a code

07/07/2009 17:38 xellios#1
Im still new to this but im creating an npc and i want to learn how to let it show text based on your level like:

Level 1 :
Hello lvl 1

Level 2:
Hello lvl 2

Level 3 :
Hello lvl 3

And no i dont want it like this:
Hello + CSocket.Client.Name


Question 2 :
[Only registered and activated users can see links. Click Here To Register...]

I want it to check if its Level 1 or 2 or 3 or 4 or 5 etc...
and i already tried
if (CSocket.Client.Level == 1)
if (CSocket.Client.Level == 2)
if (CSocket.Client.Level == 3)
07/07/2009 18:01 n0mansland#2
Well if you mean like an NPC that tells what level you want then that'd be possible but just really really long.. (Depends on how many levels you have in your server)

Example
Code:
case Bla://LVL NPC
{
if (LinkBack == 0)
{
if (CSocket.Client.Level == 1) <--- not sure :p
{
    Text("You are level 1", CSocket);
     Link("Duhh", 1,CSocket);
     End(CSocket);
}
if (LinkBack == 0)
{
if (CSocket.Client.Level == 2)
{
  Text("You are level 2", CSocket);
  Link("Duhh", 2, CSocket);
  End(CSocket);
}
break;
}
if that's what you mean.. I made that in like a second.. I'm sure there's a lot easier way like "You are CHARLEVEL" but don't feel like figuring it out..
07/07/2009 18:41 xellios#3
Quote:
Originally Posted by n0mansland View Post
Well if you mean like an NPC that tells what level you want then that'd be possible but just really really long.. (Depends on how many levels you have in your server)

Example
Code:
case Bla://LVL NPC
{
if (LinkBack == 0)
{
if (CSocket.Client.Level == 1) <--- not sure :p
{
    Text("You are level 1", CSocket);
     Link("Duhh", 1,CSocket);
     End(CSocket);
}
if (LinkBack == 0)
{
if (CSocket.Client.Level == 2)
{
  Text("You are level 2", CSocket);
  Link("Duhh", 2, CSocket);
  End(CSocket);
}
break;
}
if that's what you mean.. I made that in like a second.. I'm sure there's a lot easier way like "You are CHARLEVEL" but don't feel like figuring it out..
Nope it's for the db lvler:P
07/07/2009 18:59 n0mansland#4
I'm not really sure how to do Unknown man yet.. I mean I could if I sat down and worked on it..
07/07/2009 19:50 Jay1029#5
I tried making an Npc like that using your example n0mansland, when I finished everything looked good except the word default; on the line below it was underlined in red and idk why. Maybe my code is not positioned right or something?
07/07/2009 21:03 pro4never#6
Quote:
Originally Posted by n0mansland View Post
I'm not really sure how to do Unknown man yet.. I mean I could if I sat down and worked on it..
I have it done, and as for your script you listed you could do it without an if for each level

simply use

Text("You are level" + CSocket.Client.Level + " currently", CSocket);

close your quotes, put in a + and you can add the function directly into the npc script


Then instead of using a 'if level == number (you have to use ==, that's saying is equal to, = means you are saying this = this (setting it as something)) you can also use a

if (CSocket.Client.Level >= 1 && CSocket.Client.Level <= 100)

&& means and also

so if level is between 1 and 100 then the section below runs, you can use segments like that instead of coding for each level

Also fyi you could use

if (CSocket.Client.Level == 1 || CSocket.Client.Level == 2)

|| means or basically or, so if EITHER of those are true it does section below.


Hope that helps you with some of your functions
07/07/2009 21:22 danielachraf#7
in loft
Quote:
SendPacket(General.MyPackets.NPCSay("Hello " + MyChar.Name + " You are level " + MyChar.Level + " .. Stop Posting threads"));
SendPacket(General.MyPackets.NPCLink("Ok .. .", 255));
SendPacket(General.MyPackets.NPCSetFace(30));
SendPacket(General.MyPackets.NPCFinish());
07/07/2009 21:58 xellios#8
You all understand me wrong i just wanted an example so i could work on the db lvler.
BUT! Now who can help me on question 2?
07/07/2009 22:40 pro4never#9
Quote:
Originally Posted by xellios View Post
You all understand me wrong i just wanted an example so i could work on the db lvler.
BUT! Now who can help me on question 2?
What I posted is what you would use for a db lvler

You simply have it check inventory for an item, if it does then have it take the item and add a level

If you want other checks such as level being less then something just use

if (CSocket.Client.Level <= level you want less then)

For db check I suggest you look at the metbank npc, it checks for mets/db's in it's script so just look for where it counts how many there are

+ it's a good script to learn from cause it does a few different things including storing a new value under character data, loading that data, using/checking/saving it in a npc command, counting/removing/checking items in inventory and a few other things.

All very useful sections of code that can be applied to just about any npc idea you have

[Only registered and activated users can see links. Click Here To Register...]

All you have to do is read it/understand what the coding means and you can alter it to apply to just about anything, that thread is a great place to start for that.


Thanks if it helps :O
07/07/2009 22:43 xellios#10
Ok but now question 1 is answered who can help me on question 2!
07/07/2009 22:58 pro4never#11
Quote:
Originally Posted by xellios View Post
Ok but now question 1 is answered who can help me on question 2!
oops, I didn't see question 2 srry.


Hmmm, for the php side I'd just google something to use php to add something to a mysql database (or just look at how it's done in a registration page)

For the client side that part I can do.


Personally I'd put it under characters (so it's saved to their character, not an individual table just for donation)

Add a field to character database calling it what you want, for example donation


Again, using sections from Metbank npc (credit to them obviously

bottom of chat.cs

Code:
   public static void Donation(int value, ClientSocket CSocket)
        {
            CSocket.Client.Donation += value;
            CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Donation, Struct.StatusTypes.Donation));
        }
database.cs (where the other ones like it are, search for the wh money one just like in metbank

Code:
Client.Donation = Convert.ToInt32(DR["Donation"]);
database.cs

Code:
        public static void SaveDonation(ClientSocket CSocket)
        {
            MySqlCommand Cmd = new MySqlCommand("UPDATE `characters` SET `Donation` = " + CSocket.Client.Donation + " WHERE `CharID` = " + CSocket.Client.ID + "", DatabaseConnection.NewConnection());
            Cmd.ExecuteNonQuery();
            Cmd.Connection.Close();
            Cmd.Connection.Dispose();
            Cmd.Dispose();
        }
statustype.cs

Code:
  donation= 33,//??
character.cs

Code:
  public int Donation = 0;

Then for the npctalk part just do something like

Code:
if (CSocket.Client.Donation = value wanted)
{ Text("You can claim your donation reward" , CSocket);
other options here (such as what is rewarded)
Donation(NumberRemoved, CSocket);
Database.Database.SaveDonation(CSocket);
}

else
Text("You do not have a donation to claim" , CSocket);
Obviously not a working npctalk but that's how you would do it, the php side just needs to add a value to the character table to set it to whatever it needs to be
07/08/2009 10:01 xellios#12
The client side is working now thanks but i cant work it out with the php side cuz im not that well at combining mysql&php like i told you