Page 1 of 1

Level System

Posted: Sat Mar 07, 2009 12:31 am
by Energy
Good time of day. How to write a system of levels for the character, with the experience for killing monsters? If there is a claw or the sample script to show you.
Unfortunately I can not very consistent :(
Emulator POL97

Re: Level System

Posted: Sat Mar 07, 2009 2:33 am
by Sadahar
Check the npcdeath script... there you can add a function to give exp to the killer (CProp), and another function to check if player has reached next level (another CProp for level). You should set a config or just another function to check how much exp does the player need to reach next level.

I'd give you an example script but i have lost all my scripts :shame:

Re: Level System

Posted: Sat Mar 07, 2009 2:39 am
by Energy
Thank you for the information. Still, I would like to see how it looks like the whole script. :shame:

Re: Level System

Posted: Sat Mar 07, 2009 5:58 am
by Energy
I want to do so in npcdesc.cfg
Sample:

Code: Select all

Name			IntrinsicWarior
	Script			:brainAI:brain
	ObjType			0x289
	Color			0
	TrueColor		0
	Gender			0
	AR			25
	RunSpeed		200
	Alignment		neutral
	Category		Examples

	// Attributes
	Strength		100
	Intelligence		1
	Dexterity		10

	Wrestling		100

	// Vitals
	HITS			100
	MANA			1
	STAM			100
             EXP                     500
.................
.................
.................
In death.src need to add the following:

Code: Select all

var EXP := CInt(GetObjProperty(corpse, "EXP"));
      SetObjProperty(character, "expe", (expe + EXP));
Or I have something wrong? If yes, how to Give. Emulator POL97
And if there is a claw scripts to send e-mail. Thx

Re: Level System

Posted: Sat Mar 07, 2009 8:42 am
by Sadahar
Umm well yes thats a way to implant it... but you will need the killer reference.. and that would only give the exp to the last hit? nvm
** You have something wrong in the npcdesc, add exp as a CProp, check for a template in the file.

Maybe you could add a SysMessage to tell the player the exp that has earned.. no? :P

After adding the exp you should call a funciton to check if it has enought exp to reach the next level.. and to advance one level if it's so.

I'd say you to set a include file for the level "system" :P

for example (not tested at all):

Code: Select all

//levelSystem.inc
function checkExp(who, exp)
var level := GetObjProperty(who, "level");
var nextLevel := expTable(level);
if(exp < nextLevel)
 return 0;
else
 advanceLevel(who, level);
 return 0;
endif
endfunction

function expTable(level)
var exp;
case( (level + 1) )
 2: exp := 500;
 3: exp := 800;
 4: exp := 1200;
 5: exp := 1500;
 6: exp := 1800;
//...
endcase
return exp;
endfunction

function advanceLevel(who, level)
SetObjProperty(who, "exp", 0);
SetObjProperty(who, "level", (level + 1) );
SendSysMessage(who, "You have reached level "+(level + 1)+"!");
endfunction

Re: Level System

Posted: Sat Mar 07, 2009 9:33 am
by Energy
Hence in npcdesc.cfg you can set it?

Code: Select all

Name		a grizzly bear
	Script		:ai_brain:brain
	ObjType		0xD4
	Color		0
	TrueColor	0
	Gender		0

	STR		100
	INT		40
	DEX		105
	HITS		100
	MANA		0
	STAM		105
	AR		5
	RunSpeed	55

	WAR_Wrestling	65
	Tactics		100

	AttackAttribute	WAR_Wrestling
	AttackSpeed	30
	AttackDamage	3d4
	AttackHitSound	0xA6
	AttackMissSound	0x239
	DeathSound	0xA8
	DamagedSound	0xA7
         СProp                  exp                   50              

But then that should be added to npcdeath.src?

Sorry, head not to know = (I can not understand even started re-teaching guide to scripting

Re: Level System

Posted: Sat Mar 07, 2009 10:18 am
by CWO
I wouldn't add it as a CProp since it takes a lot more memory. The way you had it before was perfectly fine. Leave it as an entry in the cfg without the CProp and then read it straight from there with GetConfigInt();

leave npcdesc.cfg like that...

Code: Select all

Name         IntrinsicWarior
   Script         :brainAI:brain
   ObjType         0x289
   Color         0
   TrueColor      0
   Gender         0
   AR         25
   RunSpeed      200
   Alignment      neutral
   Category      Examples

   // Attributes
   Strength      100
   Intelligence      1
   Dexterity      10

   Wrestling      100

   // Vitals
   HITS         100
   MANA         1
   STAM         100
             EXP                     500
then in the script to read EXP, you would need this code implanted into your script...:
(I didn't test this, I just scripted this on the fly so mistakes are possible)

Code: Select all

use cfgfile;

program npcdeath(corpse)
     ...
     var npccfg := ReadConfigFile(":*:npcdesc");
     var template := GetObjProperty(corpse, "npctemplate");
     var elem := FindConfigElem(npccfg, template);
     if (elem)
          var expgain := GetConfigInt(elem, "EXP");
          if (expgain)
               // You'll have to set the person who last hit this NPC in all hitscripts and spell scripts.
               var pcexp := GetObjProperty(who, "expe");
               SetObjProperty(who, CInt(pcexp) + CInt(expgain));
               SendSysMessage(who, "You have gained " + CStr(CInt(pcexp)) + " experience.");
          endif
     endif
     ...
endprogram

Re: Level System

Posted: Sun Mar 08, 2009 1:10 am
by Energy
Great THX!!!

Re: Level System

Posted: Sun Mar 08, 2009 2:10 am
by Sadahar
Yes, thats the way :)
(Didn't tested it :P)

npcdeath.src

Code: Select all

use cfgfile;
include :death:levelSystem; //Includes the inc file levelSystem (put it in the pkg "Death" in the folder includes)

program npcdeath(corpse)
     ...
     var npccfg := ReadConfigFile(":*:npcdesc");
     var template := GetObjProperty(corpse, "npctemplate");
     var elem := FindConfigElem(npccfg, template);
     if (elem)
          var expgain := GetConfigInt(elem, "EXP");
          if (expgain)
               // You'll have to set the person who last hit this NPC in all hitscripts and spell scripts.
               var pcexp := GetObjProperty(who, "expe");
               SetObjProperty(who, "expe", CInt(pcexp) + CInt(expgain)); // There was an "error" here :P
               SendSysMessage(who, "You have gained " + CStr(CInt(pcexp)) + " experience.");
               checkExp(who, (expe + expgain)); // This checks if player reaches next level or not.
          endif
     endif
     ...
endprogram
levelSystem.inc

Code: Select all

//levelSystem.inc
function checkExp(who, exp)
 var level := GetObjProperty(who, "level");
 if(!level)
  SetObjProperty(who, "level", 1);
 endif
 var nextLevel := expTable(level);
 if(exp < nextLevel)
  return 0;
 else
 advanceLevel(who, level);
  return 0;
 endif
endfunction

function expTable(level)
 var exp;
 case( (level + 1) )
  2: exp := 500;
  3: exp := 800;
  4: exp := 1200;
  5: exp := 1500;
  6: exp := 1800;
  //...
 endcase
 return exp;
endfunction

function advanceLevel(who, level)
 SetObjProperty(who, "expe", 0);
 SetObjProperty(who, "level", (level + 1) );
 SendSysMessage(who, "You have reached level "+(level + 1)+"!");
endfunction
npcdesc.cfg

Code: Select all

Name         IntrinsicWarior
   Script         :brainAI:brain
   ObjType         0x289
   Color         0
   TrueColor      0
   Gender         0
   AR         25
   RunSpeed      200
   Alignment      neutral
   Category      Examples

   // Attributes
   Strength      100
   Intelligence      1
   Dexterity      10

   Wrestling      100

   // Vitals
   HITS         100
   MANA         1
   STAM         100
   EXP                     500

Re: Level System

Posted: Sun Mar 08, 2009 2:20 am
by Energy
Sadahar, many thanks to you!

Know that I would do without you =) ;)

Re: Level System

Posted: Sun Mar 08, 2009 2:29 am
by Energy
By the way Sadahar, not whether you have a full tutorial on eScript?
The one that the site is not complete. Or I am wrong?

Re: Level System

Posted: Sun Mar 08, 2009 3:11 am
by Sadahar
Umm the best way to learn is reading already done scripts :)

Re: Level System

Posted: Sun Mar 08, 2009 6:01 am
by CWO
That's how most of us learned. We sat and looked at other people's scripts and looked at the reference to all the commands in the documentation and the Object hierarchy to figure out what stuff does.

Re: Level System

Posted: Wed Mar 11, 2009 5:19 am
by Energy
Hmmm, with the compilation gives an error in the lines:
if (elem)
if (expgain)
var pcexp := GetObjProperty(who, "expe");

Code: Select all

program core_npcDeath(params)
	var corpse := params[1];

	TS_Death(corpse); // Will still get the PID from the corpse.

        var npccfg := ReadConfigFile(":brainAI:npcdesc");
        var template := GetObjProperty(corpse, "npctemplate");
        var elem := FindConfigElem(npccfg, template);
        
        if (elem)
          var expgain := GetConfigInt(elem, "EXP");
          if (expgain)
               var pcexp := GetObjProperty(who, "expe");
               SetObjProperty(who, "expe", CInt(pcexp) + CInt(expgain)); // There was an "error" here :P
               SendSysMessage(who, "You have gained " + CStr(CInt(pcexp)) + " experience.");
               checkExp(who, (expe + expgain)); // This checks if player reaches next level or not.
          endif

Re: Level System

Posted: Wed Mar 11, 2009 8:39 am
by CWO
Variable "who" is not declared?

That's where I said its going to be a little harder. You have to find out through your scriptbase if there is a prop set for who last hit the NPC. If not, you have to go into all of your damaging scripts like hitscripts and spell scripts and add that. You'll likely need to set the serial number of the person who last hit the NPC as a prop then retrieve it from the corpse and set who to SystemFindObjectBySerial( *serial number of the last person to hit it* );

Re: Level System

Posted: Wed Mar 11, 2009 8:46 am
by Energy
CWO wrote:Variable "who" is not declared?

That's where I said its going to be a little harder. You have to find out through your scriptbase if there is a prop set for who last hit the NPC. If not, you have to go into all of your damaging scripts like hitscripts and spell scripts and add that. You'll likely need to set the serial number of the person who last hit the NPC as a prop then retrieve it from the corpse and set who to SystemFindObjectBySerial( *serial number of the last person to hit it* );

SystemFindObjectBySerial(who.serial, "LastHit");

?

Re: Level System

Posted: Wed Mar 11, 2009 9:49 am
by CWO
if you have a "LastHit" prop set to the NPC then this is easy. Although the format of it could be different. POL itself does not set this prop. This must be set by your scripts when the NPC is hit (within the hitscripts and spell scripts) Just put this before the var pcexp := GetObjProperty(who, "expe");

Code: Select all

var lasthitserial := GetObjProperty(corpse, "LastHit");
var who := SystemFindObjectBySerial(lasthitserial);

so you should end up with

Code: Select all

var lasthitserial := GetObjProperty(corpse, "LastHit");
var who := SystemFindObjectBySerial(lasthitserial);
var pcexp := GetObjProperty(who, "expe");

Re: Level System

Posted: Wed Mar 11, 2009 10:27 am
by Sadahar
Property lastHit its not just the serialof the killer...
you must work out that dictionary, o struct, whatever it is xD
no?

Re: Level System

Posted: Wed Mar 11, 2009 12:37 pm
by CWO
OK I looked up the POL097 distro, the prop is "LastDamage" not "LastHit" and its a struct with a .serial member. Now IF and ONLY IF you're using the POL097 distro scripts (this is seperate from the emulator itself) it would be:

Code: Select all

var lasthit := GetObjProperty(corpse, "LastDamage");
var who := SystemFindObjectBySerial(lasthit.serial);

Re: Level System

Posted: Thu Mar 12, 2009 1:27 am
by Energy
Wonder why it gives an error on line when compiling:
if (elem)
if (expgain)
var pcexp: = GetObjProperty (who, "expe");

Re: Level System

Posted: Thu Mar 12, 2009 6:22 am
by CWO
you're just giving lines. What is the actual error? It should be something like "variable who has not been declared" but the 2 lines I gave you in my last post should be put before that line where it gets the prop "expe" because I declared who on the second line.

Re: Level System

Posted: Thu Mar 12, 2009 8:41 am
by coltain
var pcexp: = GetObjProperty (who, "expe");

as I see You have a space between : and =
: = <-bad
:= <-good

Re: Level System

Posted: Fri Mar 13, 2009 12:35 am
by Energy
CWO, Yesterday compile scripts such as error-free. But was the writing that can not read levelSystem.inc and when you add features Elem EXP 500 (CASE) in npcdesc.cfg, with the murder of a monster do not write that I got experience. Perhaps due to the fact that not work levelSystem.inc?

Re: Level System

Posted: Fri Mar 13, 2009 12:38 am
by Energy
Does someone working example scripts on this theme at least for POL95? Just want to understand the system of writing these scripts.

Re: Level System

Posted: Fri Mar 13, 2009 7:26 am
by *Edwards
found in your npcdeath.src

Code: Select all

program core_npcDeath(params)

        var corpse := params[1];
        var lasthitserial := GetObjProperty( corpse, "LastHit" );
        var who := SystemFindObjectBySerial( lasthitserial );

        var npccfg := ReadConfigFile( ":*:npcdesc" );
        var template := GetObjProperty( corpse, "npctemplate" );
        var elem := FindConfigElem( npccfg, template );
        
        if( elem )
          var expgain := GetConfigInt( elem, "EXP" );
          if ( expgain )
               var mobile_exp := GetObjProperty( who, "XP" );
               SetObjProperty( who, "XP", mobile_exp + expgain );
               SendSysMessage( who, "You have gained "+ expgain +" experience.");
               checkExp( who, ( mobile_exp + expgain ));
          endif
in your npcdesc.cfg every creature should have a property called EXP

Code: Select all

Name         IntrinsicWarior
   Script         :brainAI:brain
   ObjType         0x289
   Color         0
   TrueColor      0
   Gender         0
   AR         25
   RunSpeed      200
   Alignment      neutral
   Category      Examples

   // Attributes
   Strength      100
   Intelligence      1
   Dexterity      10

   Wrestling      100

   // Vitals
   HITS         100
   MANA         1
   STAM         100
   EXP                     500 // This creature gives 500exp

Code: Select all

//levelSystem.inc
function checkExp( who, exp )
var level := GetObjProperty( who, "level" );
var nextLevel := expTable( level );
if( exp < nextLevel )
return 0;
else
advanceLevel( who, level );
return 0;
endif
endfunction

function expTable( level )
var exp;
case( (level + 1) )
2: exp := 500;
3: exp := 800;
4: exp := 1200;
5: exp := 1500;
6: exp := 1800;
//...
endcase
return exp;
endfunction

function advanceLevel( who, level )

var previous_lvl := GetObjProperty( who, ''level'' );
var new_lvl := previous_lvl  +1;
SetObjProperty( who, "XP", 0 );
SetObjProperty(who, "level", new_lvl  );
SendSysMessage(who, "You have reached level "+new_lvl +"!");
endfunction
That shall compile correctly. And you soon figure out how to handle it correctly...