Level System

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Level System

Post 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
User avatar
Sadahar
Adept Poster
Posts: 81
Joined: Mon Dec 03, 2007 11:15 am

Re: Level System

Post 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:
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post by Energy »

Thank you for the information. Still, I would like to see how it looks like the whole script. :shame:
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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
User avatar
Sadahar
Adept Poster
Posts: 81
Joined: Mon Dec 03, 2007 11:15 am

Re: Level System

Post 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
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post by Energy »

Great THX!!!
User avatar
Sadahar
Adept Poster
Posts: 81
Joined: Mon Dec 03, 2007 11:15 am

Re: Level System

Post 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
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post by Energy »

Sadahar, many thanks to you!

Know that I would do without you =) ;)
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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?
User avatar
Sadahar
Adept Poster
Posts: 81
Joined: Mon Dec 03, 2007 11:15 am

Re: Level System

Post by Sadahar »

Umm the best way to learn is reading already done scripts :)
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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.
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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* );
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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");

?
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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");
User avatar
Sadahar
Adept Poster
Posts: 81
Joined: Mon Dec 03, 2007 11:15 am

Re: Level System

Post by Sadahar »

Property lastHit its not just the serialof the killer...
you must work out that dictionary, o struct, whatever it is xD
no?
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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);
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post by Energy »

Wonder why it gives an error on line when compiling:
if (elem)
if (expgain)
var pcexp: = GetObjProperty (who, "expe");
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Level System

Post 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.
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: Level System

Post by coltain »

var pcexp: = GetObjProperty (who, "expe");

as I see You have a space between : and =
: = <-bad
:= <-good
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post 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?
Energy
New User
Posts: 14
Joined: Fri Feb 27, 2009 2:22 am

Re: Level System

Post by Energy »

Does someone working example scripts on this theme at least for POL95? Just want to understand the system of writing these scripts.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: Level System

Post 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...
Post Reply