Skill Boost upon Mob Kill

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Skill Boost upon Mob Kill

Post by Ordos »

edit: Ignore original post. Click here for CURRENT PROGRESS.

(POL093)
When a player kills a monster, I want the combat skill they've used to kill the monster to be boosted depending on a variable I will attach to each mob.

I think it's going to require:
1) Creating a new inc or src (in pkg/opt/newcombat), I'm too newbie to know which.
2) Adding a line to death.src (scripts/misc/death.src)
3) Adding a new variable to each monster in npcdesc.cfg

I've followed this thread closely, since the premise is similar. But I'm quite a newbie and I know I'm going to need help.

1) Here is the (undoubtably lacking in some basic functionality) newcombat file I've created:

Code: Select all

var newcombatskill := 0

//who is attacking
function IdentifyAttacker( who )

	var newcombat_hit_list := GetObjProperty( who, "Hitlist" );

	if( newcombat_hit_list )
		EraseObjProperty( who, "Hitlist" );

		foreach arr in newcombat_hit_list
			if( ReadGameClock() < Cint(arr[3]) + 300 ) // what is this delay meant to do?
				var attacker := SystemFindObjectBySerial( Cint(arr[1]) );
				if( !attacker )
					attacker := SystemFindObjectBySerial( Cint(arr[1]), SYSFIND_SEARCH_OFFLINE_MOBILES );
				endif
				
				if( attacker )
					AffectCombatSkillForKill( attacker, who, CDbl(arr[2]) / Len(newcombat_hit_list) );
				endif
			endif

		endforeach
	endif

endfunction



//define which skill the attacker is using and add the boost
function AffectCombatSkillForKill( attacker , newcombatskill , weapon , skillid )
	if ( attacker )
		if ( newcombatskill != 0 )
			if ( weapon.skillid = SKILLID_FENCING )
				SetRawSkill ( who , SKILLID_FENCING , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_TACTICS , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_PARRY , Cint(rawskill + newcombatskill) );
			endif

			if ( weapon.skillid = SKILLID_MACEFIGHTING )
				SetRawSkill ( who , SKILLID_MACEFIGHTING , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_TACTICS , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_PARRY , Cint(rawskill + newcombatskill) );
			endif

			if ( weapon.skillid = SKILLID_SWORDSMANSHIP )
				SetRawSkill ( who , SKILLID_SWORDSMANSHIP , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_TACTICS , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_PARRY , Cint(rawskill + newcombatskill) );
			endif

			if ( weapon.skillid = SKILLID_WRESTLING )
				SetRawSkill ( who , SKILLID_WRESTLING , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_TACTICS , Cint(rawskill + newcombatskill) );
				SetRawSkill ( who , SKILLID_PARRY , Cint(rawskill + newcombatskill) );
			endif

			if ( weapon.skillid = SKILLID_ARCHERY )
				SetRawSkill ( who , SKILLID_ARCHERY , Cint(rawskill + newcombatskill) );
			endif

		endif

endfunction

2) This is the only line I've added within the npcdeath (corpse) program within death.src

Code: Select all

program npcdeath(corpse)

	var newcombatskill := CInt(GetObjProperty(corpse, "EXP"));    	
	
endprogram
3) I've added the variable "EXP" to some mobs:

Code: Select all

NpcTemplate goldendragon
{
	Name		a Golden Dragon
	script		firebreather

	objtype		0xc
	Color		48
	TrueColor	48
	Gender		0
	STR		200
	INT		200
	DEX		200
	HITS		1000
	MANA		500
	STAM		100
	EXP		5000

	Tactics		150
	MaceFighting	190
	Magery		150
	MagicResistance	100
	Parry		100
	DetectingHidden 200

	spell flamestrike
	spell ebolt
	spell lightning
	spell chainlightning
	spell masscurse
	spell earthquake
	spell manavamp
	spell paralyze

	Equip		goldendragon
	deathsnd	0x16f
	tameskill	160
	alignment	evil
	hostile		1
	virtue		8
	provoke		150
	lootgroup	105
	MagicItemChance	99
	MagicItemLevel	8
	dstart		10
 	CProp	     snoopme i150
 	Cprop	     stealme i150
	CProp 	looter 	s1
	CProp	Type	sDragonkin
	CProp	BaseStrmod	i1050
	CProp	BaseIntmod	i300
	CProp	BaseDexmod	i250
	CProp	Permmr	i6
	CProp	PermPoisonImmunity	i8
	CProp	PermMagicImmunity	i7
	CProp	FireProtection	i4
	CProp	AirProtection	i4
	CProp	EarthProtection	i4
	CProp	WaterProtection	i2
	CProp	BaseHpRegen	i500
	CProp	BaseManaRegen	i500
}
I know I must be approaching some of this from completely the wrong place. I will massively appreciate all your guidance.

Thanks!
Last edited by Ordos on Wed Mar 31, 2010 11:58 am, edited 2 times in total.
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am

Re: Skill Boost upon Mob Kill

Post by xeon »

At a very quick look, the idea is generally correct.

Good luck :)
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Re: Skill Boost upon Mob Kill

Post by Ordos »

Yeah I don't think I'm far off, hopefully. It doesn't work when I compile though.

I'd really like some guidance and possibly someone to look through it and point out what is probably obviously incorrect to experienced scripters. The idea might be ok, but I'm probably missing something fundamental that a newbie like me will miss.

Thx ;)
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Re: Skill Boost upon Mob Kill

Post by Ordos »

(pol093)
OK, I've given this project 3 full days of non-stop scripting, that must be around 30ish hours of work. I have the passion, but need the guidance, it'd be great if someone could point out where I'm going wrong with these scripts. I'd hate to give up.

The files I've scripted are completely different now, here they are:

1) pkg/opt/shilhook/shilcombat.src:

Code: Select all

use uo;
use os;
use math;
use cfgfile;

include "include/skillpoints";

program shilcombat()

	Print( "Using ShilcombatAdvancement..." );
	return 1;

endprogram


exported function ShilCombatAdvancement( attacker, weapon, defender )

	if( weapon )
		AwardStatPoints( attacker, 43 );
		AwardSkillPoints( attacker, weapon.skillid, 20 );
	else
		AwardStatPoints( attacker, 43 );
		AwardSkillPoints( attacker, 43, 20 );
	endif

	AwardStatPoints( attacker, 27 );
	AwardSkillPoints( attacker, 27, 20 );

endfunction

function IdentifyAttacker( who, weapon, attacker, defender )

	var newcombat_hit_list := GetObjProperty( who, "Hitlist" );

	if( newcombat_hit_list )
		EraseObjProperty( who, "Hitlist" );

		foreach arr in newcombat_hit_list
			if( ReadGameClock() < Cint(arr[3]) + 300 ) // what is this delay meant to do?
				var attacker := SystemFindObjectBySerial( Cint(arr[1]) );
				if( !attacker )
					attacker := SystemFindObjectBySerial( Cint(arr[1]), SYSFIND_SEARCH_OFFLINE_MOBILES );
				endif
				
				if( attacker )
					var skillused := GetObjProperty ( who, CInt(weapon.skillid));

					if ( skillused := 42 )
						var rawfencing := GetRawSkill (who, CInt(42));
						
						SetRawSkill ( who, 42, Cint(BaseSkillToRawSkill(rawfencing + expgain)) );
					endif

				endif
			endif

		endforeach
	endif

endfunction
2) scripts/misc/death.src:

Code: Select all

use uo;
use cfgfile;
use os;

include "include/starteqp";
include "include/npcbackpacks";
include "include/eventid";
include "../../pkg/opt/karmafame/karmafame";
include "include/dismount";
include "include/managers";
include "../../pkg/opt/shilhook/newcombat";

program npcdeath(corpse)

	var npccfg := ReadConfigFile(":*:npcdesc");
	var template := GetObjProperty(corpse, "npctemplate");
	var elem := FindConfigElem(npccfg, template);
	if ( elem )
		var expgain := GetConfigInt(elem, EXP);
	endif

endprogram
3) config/npcdesc.cfg is same as the OP version
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Re: Skill Boost upon Mob Kill

Post by Ordos »

Hmm, I had thought these forums were more active than this.

Perhaps people could help me identify exactly what the problem is when I get these errors on compiling:
Image

I've realised that death.src cannot point at another .src file, so I've created a new .inc file: pkg/opt/shilhook/shilcombat.inc. Which again I've mostly re-written.

Code: Select all

use uo;
use os;
use math;
use cfgfile;

include "include/skillpoints";

function IdentifyAttacker( who, weapon, attacker, defender )

	var newcombat_hit_list := GetObjProperty( who, "Hitlist" );

	if( newcombat_hit_list )
		EraseObjProperty( who, "Hitlist" );

		foreach arr in newcombat_hit_list
			if( ReadGameClock() < Cint(arr[3]) + 300 ) // what is this delay meant to do?
				var attacker := SystemFindObjectBySerial( Cint(arr[1]) );
				if( !attacker )
					attacker := SystemFindObjectBySerial( Cint(arr[1]), SYSFIND_SEARCH_OFFLINE_MOBILES );
				endif
				
				if( attacker )
					AffectCombatSkillForKill( attacker, who, CDbl(arr[2]) / Len(hit_list) );
				endif
			endif

		endforeach
	endif

endfunction


function AffectCombatSkillForKill ( attacker, defender, weapon, who )

	var attacker_karma := GetKarma(attacker);
	var defender_karma := GetKarma(defender);
	var rawfencing := GetRawSkill (who, CInt(42));
	var rawmacing := GetRawSkill (who, CInt(42));
	var skillused := GetObjProperty ( who, CInt(weapon.skillid));

		if ( attacker_karma > defender_karma )
			if ( skillused := 42 )
				delta_fencing := expgain
			endif

			if ( skillused := 41 )
				delta_macing := expgain
			endif
		endif

	if ( delta_fencing != 0 )
		AwardFencingSkill ( attacker , delta_fencing );
	endif

	if ( delta_macing  != 0 )
		AwardMacingSkill ( attacker , delta_macing );
	endif
endfunction

function AwardFencingSkill ( who , amt )
	
	SetRawSkill ( who, 42, Cint(BaseSkillToRawSkill(rawfencing + expgain)) );

endfunction

function AwardMacingSkill ( who , amt )
	
	SetRawSkill ( who, 42, Cint(BaseSkillToRawSkill(rawmacing + expgain)) );

endfunction

2) Death.src now includes shilcombat.inc

Code: Select all

use uo;
use cfgfile;
use os;

include "include/starteqp";
include "include/npcbackpacks";
include "include/eventid";
include "../../pkg/opt/karmafame/karmafame";
include "include/dismount";
include "include/managers";
include "../../pkg/opt/shilhook/shilcombat";

program npcdeath(corpse)

	var EXP := 0
	var npccfg := ReadConfigFile("::npcdesc");
	var template := GetObjProperty(corpse, "npctemplate");
	var elem := FindConfigElem(npccfg, template);
	if ( elem )
		var expgain := GetConfigInt(elem, EXP);
	endif

endprogram
3) npcdesc.cfg is the same.
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am

Re: Skill Boost upon Mob Kill

Post by xeon »

It seems that there is an error in your death.src at line 130.
Could you post it?
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Re: Skill Boost upon Mob Kill

Post by Ordos »

Hi Xeon, thanks for replying!

I've since re-scripted my files and I am instead stuck at this error message when I compile (ecompile.txt):
ERROR MESSAGE

Code: Select all

Compiling: ./pkg/opt/shilhook/shilcombat.src
Constant DELAY_TO_GET_COMBATSKILL has already been defined.
Error in const declaration
File: ./pkg/opt/shilhook/shilcombat.inc, Line 8
Compilation failed.
Compiling: ./pkg/opt/shilhook/shilhook.src
Constant DELAY_TO_GET_COMBATSKILL has already been defined.
Error in const declaration
File: ./pkg/opt/shilhook/shilcombat.inc, Line 8
Compilation failed.
Do you know why it says the constant "has already been defined"? I searched through all the files I'm working with and that constant is never defined anywhere else.

SHILCOMBAT.SRC

Code: Select all

use uo;
use os;
use math;
use cfgfile;

include "shilcombat"
include "include/skillpoints";

program shilcombat()

	Print( "Using ShilcombatAdvancement..." );
	return 1;

endprogram


exported function ShilCombatAdvancement( attacker, weapon, defender )

	if( weapon )
		AwardStatPoints( attacker, 43 );
		AwardSkillPoints( attacker, weapon.skillid, 20 );
	else
		AwardStatPoints( attacker, 43 );
		AwardSkillPoints( attacker, 43, 20 );
	endif

	AwardStatPoints( attacker, 27 );
	AwardSkillPoints( attacker, 27, 20 );

endfunction
Here is shilcombat.inc:
SHILCOMBAT.INC

Code: Select all

use uo;
use os;
use math;
use cfgfile;

include "include/skillpoints";

const DELAY_TO_GET_COMBATSKILL := 300;

function IdentifyAttacker( who )

	var newcombat_hit_list := GetObjProperty( who, "Hitlist" );

	if( newcombat_hit_list )
		EraseObjProperty( who, "Hitlist" );

		foreach arr in newcombat_hit_list
			// Specify that you're dealing with the most recent kill on the hitlist
			if( ReadGameClock() < Cint(arr[3]) + DELAY_TO_GET_COMBATSKILL ) 
				var attacker := SystemFindObjectBySerial( Cint(arr[1]) );
				if( !attacker )
					attacker := SystemFindObjectBySerial( Cint(arr[1]), SYSFIND_SEARCH_OFFLINE_MOBILES );
				endif
				
				if( attacker )
					AffectCombatSkillForKill( attacker, weapon.skillid );
				endif
			endif

		endforeach
	endif

endfunction


function AffectCombatSkillForKill ( attacker, defender, weapon )

	var skillused := GetObjProperty ( who, weapon.skillid);
	var delta_expgain := expgain
	var delta_fencing := 0;
	var delta_macing := 0;

		if ( attacker )
			if ( skillused := 42 )
				delta_fencing := delta_expgain;
			endif

			if ( skillused := 41 )
				delta_macing := delta_expgain;
			endif
		endif

	if ( delta_fencing != 0 )
		AwardFencingSkill ( attacker , delta_fencing );
	endif

	if ( delta_macing  != 0 )
		AwardMacingSkill ( attacker , delta_macing );
	endif
endfunction

function AwardFencingSkill ( attacker , amt )
	var rawfencing := GetRawSkill (who, CInt(42));

	SetRawSkill ( attacker , 42, Cint(BaseSkillToRawSkill(rawfencing + delta_expgain)) );

endfunction

function AwardMacingSkill ( who , amt )
	var rawmacing := GetRawSkill (who, CInt(41));

	SetRawSkill ( attacker , 42, Cint(BaseSkillToRawSkill(rawmacing + delta_expgain)) );

endfunction
Death.src no longer gives me error messages, but that's because I've reduced it to:
DEATH.SRC

Code: Select all

use uo;
use cfgfile;
use os;

include "include/starteqp";
include "include/npcbackpacks";
include "include/eventid";
include "../../pkg/opt/karmafame/karmafame";
include "include/dismount";
include "include/managers";
include "../../pkg/opt/shilhook/shilcombat";

program npcdeath(corpse)

        var npc_cfg	:= ReadConfigFile( "::npcdesc" );
        var expgain := npc_cfg[npctemplate].EXP;

endprogram
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am

Re: Skill Boost upon Mob Kill

Post by xeon »

Look in your "include/skillpoints" and in its include, recursing to the top.

The compiler found previously that constant name, and refuses to use it a second time.

Or, remove include "include/skillpoints"; from your .src. That file is included two times, one in the .src and one in your .inc.
User avatar
Ordos
Neophyte Poster
Posts: 33
Joined: Sat Feb 28, 2009 7:20 am

Re: Skill Boost upon Mob Kill

Post by Ordos »

Thanks again Xeon, I'm actually away this weekend, so will get back to you after Tuesday! Happy Easter ;)
Post Reply