@Crazy Ninja, Thanks for the reply.
NWScripting is basically C++ programming but rather than 1 single script with all functions attatched, you have scripts for different events, for instance, there are several script events on creatures, OnDeath event, OnSpawn event etc.. these events fire accordingly depending on the circumstanses (i.e. the creature dies or spawns), when the event is fired the script attatched to it is fired an run to do whatever you coded it to, like give XP to the killer, or create random treasure on the mob, the format is as I said C++, heres an example from my XP system I created for my NWN module that's posted on the NWVault for others to download just to give you an example, this would be fired from the OnDeath event of a creature:
//:://////////////////////////////////////////////
//:: Name: Scarface's XP/GP System V1.9
//:: Filename: SF_XP
//:://////////////////////////////////////////////
/*
Written by Scarface
*/
//////////////////////////////////////////////////
//:: CONSTANTS
//:: You can adjust these constants to suit your module
// XP modifier for adjusting XP reward given - higher means more XP
// Default is 10.
// Setting this to 10 will give a similar XP amount to the default
// bioware XP engines XP Slider.
// Do NOT set this to 0
const int XP_MODIFIER = 10;
// Reward gold to players for killing creatures?
// If TRUE use the GP_REWARD_MULTIPLIER const to multiply amount of gold rewarded
// TRUE = Yes : FALSE = No
const int REWARD_GP = TRUE;
// This will multiply the Gold rewarded if the REWARD_GP const above is set to TRUE
// Default is 1 (1 means equal to the amount of XP given, 2 would mean
// double the amount of gold.
// It basically multiplies the XP reward (GP_REWARD_MULTIPLIER x XP = GP Reward)
const int GP_REWARD_MULTIPLIER = 1;
// Bonus XP/GP reward for the dealing the killing blow to the creature
// Default is 0.1 = 10%
// If the REWARD_GP const above is set to FALSE then ONLY an XP bonus is given
// * Note * Changed so this will only apply if the killer is in party
const float KILLER_XP_GP_BONUS = 0.1;
// This will give an XP/GP bonus per player in the party
// Default is 0.1 = 10% per player
const float PARTY_XP_GP_BONUS = 0.1;
// Display floating text above each party member for XP/GP rewarded
// TRUE = Yes : FALSE = No
const int FLOATING_TEXT = TRUE;
// Distance between each party member and the dead creature to be
// included for XP reward
// Default is 15.0 meters
// I recommend you do NOT set this lower than about 5.0 meters
// otherwise you could end up not getting any XP/GP reward
const float PARTY_DIST = 20.0;
// Party level gap for minimal XP
// If the difference between highest level party member and the lowest
// level party member is greater than this, then XP/GP rewarded will be
// the minumum possible, this helps to stop powerleveling
// Defailt 10 (set to 40 to turn this feature off)
const int MAX_PARTY_GAP = 8;
// XP pentalty for each summon/familiar/henchman in the party within
// the specified distance set by the PARTY_DIST const
// Default 0.2 = 20% penalty per summon/familiar/henchman)
const float SUMMON_PENALTY = 0.2;
// Do you want XP to be divided between all PC's in the party within
// the specified distance set by the PARTY_DIST consts
// If set TRUE then XP will be divided between PC's so if the XP was 200
// and there were 2 PC's they would get 100 XP each
// If set FALSE they would get 200 XP each
// Default TRUE
const int PC_DIVIDE_XP = TRUE;
// Minimum XP possible for all PC's
// Default is 5 XP
// Do NOT set this to 0
const int MIN_XP = 5;
////////////////////////////////////////////////////////////////////////////////
// PC Level Max XP consts
////////////////////////////////////////////////////////////////////////////////
// You can set the maximum XP possible for each PC level for more control
// Do NOT set any of these lower than the MIN_XP const above
// Default is 600 XP max possible for all levels
// * NOTE: This is ONLY a maximum possible, PC's will still get there normal
// XP based on the XP_MODIFIER const.
const int
LEVEL_1_MAX_XP = 100,
LEVEL_2_MAX_XP = 150,
LEVEL_3_MAX_XP = 200,
LEVEL_4_MAX_XP = 300,
LEVEL_5_MAX_XP = 400,
LEVEL_6_MAX_XP = 500,
LEVEL_7_MAX_XP = 600,
LEVEL_8_MAX_XP = 600,
LEVEL_9_MAX_XP = 600,
LEVEL_10_MAX_XP = 600,
LEVEL_11_MAX_XP = 600,
LEVEL_12_MAX_XP = 600,
LEVEL_13_MAX_XP = 600,
LEVEL_14_MAX_XP = 600,
LEVEL_15_MAX_XP = 600,
LEVEL_16_MAX_XP = 600,
LEVEL_17_MAX_XP = 600,
LEVEL_18_MAX_XP = 600,
LEVEL_19_MAX_XP = 600,
LEVEL_20_MAX_XP = 600,
LEVEL_21_MAX_XP = 600,
LEVEL_22_MAX_XP = 600,
LEVEL_23_MAX_XP = 600,
LEVEL_24_MAX_XP = 600,
LEVEL_25_MAX_XP = 600,
LEVEL_26_MAX_XP = 600,
LEVEL_27_MAX_XP = 600,
LEVEL_28_MAX_XP = 600,
LEVEL_29_MAX_XP = 600,
LEVEL_30_MAX_XP = 600,
LEVEL_31_MAX_XP = 600,
LEVEL_33_MAX_XP = 600,
LEVEL_32_MAX_XP = 600,
LEVEL_34_MAX_XP = 600,
LEVEL_35_MAX_XP = 600,
LEVEL_36_MAX_XP = 600,
LEVEL_37_MAX_XP = 600,
LEVEL_38_MAX_XP = 600,
LEVEL_39_MAX_XP = 600,
LEVEL_40_MAX_XP = 600; // No real need for this one.
////////////////////////////////////////////////////////////////////////////////
//:: DO NOT TOUCH ANYTHING BELOW HERE !!!!!
////////////////////////////////////////////////////////////////////////////////
// Declare the functions
int GetMaxXP(object oPC);
int CalculateXP(float fLevel, float fCR);
void GiveXP(object oKiller, int iXP, float fKillerBonus, int iDiff, int iPlayer);
int GetLevelFromXP(object oPC);
void XPDebugMessage(object oPC, float fCR, float fDiff, float fLoLevel,
float fHiLevel, float fAvLevel);
////////////////////////////////////////////////////////////////////////////////
void main()
{
// Define major variables
object oKiller = GetLastKiller();
if (!GetIsPC(oKiller) && !GetIsPC(GetMaster(oKiller))) return;
object oParty = GetFirstFactionMember(oKiller, FALSE);
float fCR = GetChallengeRating(OBJECT_SELF), fDist, fHiLevel = 0.0, fLoLevel = 40.0;
int iPlayer, iSummon, iTotalLevel, iHD;
// Calculate the amount of members oPC's Party
while (GetIsObjectValid(oParty))
{
// Make sure the party member is NOT dead and are within the specified distance
fDist = GetDistanceToObject(oParty);
if (!GetIsDead(oParty) && fDist >= 0.0 && fDist <= PARTY_DIST)
{
// Party member is a player
if(GetIsPC(oParty))
{
// Number of players
iPlayer++;
// Get total level of all PC party members
iTotalLevel = (iTotalLevel + GetLevelFromXP(oParty));
// GetHighest/lowest party members
iHD = GetLevelFromXP(oParty);
if (iHD > FloatToInt(fHiLevel)) fHiLevel = IntToFloat(iHD);
if (iHD < FloatToInt(fLoLevel)) fLoLevel = IntToFloat(iHD);
}
// Party member is a summon/familiar/henchman
else
{
iSummon++;
}
}
oParty = GetNextFactionMember(oKiller, FALSE);
}
// This check is to stop the "DIVIDED BY ZERO" error message
if (iPlayer < 1) iPlayer = 1;
// Get average party level calculate difference between highest and lowest
float fAvLevel = (IntToFloat(iTotalLevel) / iPlayer),
fDiff = fabs(fHiLevel - fLoLevel);
// Calculate XP
int iBaseXP = CalculateXP(fAvLevel, fCR), iXP = ((iBaseXP * XP_MODIFIER) / 10),
// Lets make sure the XP reward is within consts parameters
iMaxXP = GetMaxXP(oKiller), iDiff;
if (fDiff > IntToFloat(MAX_PARTY_GAP))
{
iXP = MIN_XP;
iDiff = TRUE;
}
else if (iXP < MIN_XP)
{
iXP = MIN_XP;
}
else if (iXP > iMaxXP)
{
iXP = iMaxXP;
}
// Calculate Penalties based on consts
float fPenalty = (iXP *(iSummon * SUMMON_PENALTY)),
fPartyBonus, fKillerBonus;
int iXPToGive;
if (PC_DIVIDE_XP)
{
iXPToGive = ((iXP - FloatToInt(fPenalty)) / iPlayer);
}
else
{
iXPToGive = (iXP - FloatToInt(fPenalty));
}
// If there is more than 1 player in the party then calculate
// XP Bonuses based on consts
if (iPlayer > 1)
{
fPartyBonus = (iXP * (PARTY_XP_GP_BONUS * iPlayer));
fKillerBonus = (iXPToGive * KILLER_XP_GP_BONUS);
iXPToGive = FloatToInt(fPartyBonus) + iXPToGive;
}
GiveXP(oKiller, iXPToGive, fKillerBonus, iDiff, iPlayer);
}
// This is my function that calculates the XP reward
int CalculateXP(float fLevel, float fCR)
{
float fXPModifier, fDiff = fabs(fLevel - fCR), fBonus = (((0.1 * fCR) * 10) / 2);
if (fCR >= fLevel)
{
if (fDiff >= 10.0) fXPModifier = 60.0;
else if (fDiff >= 5.0 && fDiff < 10.0) fXPModifier = 60.0;
else if (fDiff >= 4.0 && fDiff < 5.0) fXPModifier = 60.0;
else if (fDiff >= 3.0 && fDiff < 4.0) fXPModifier = 60.0;
else if (fDiff >= 2.0 && fDiff < 3.0) fXPModifier = 60.0;
else if (fDiff >= 1.0 && fDiff < 2.0) fXPModifier = 60.0;
else fXPModifier = 60.0;
}
else if (fCR < fLevel)
{
if (fDiff >= 4.0) fXPModifier = 1.0;
else if (fDiff >= 3.0 && fDiff < 4.0) fXPModifier = 2.5;
else if (fDiff >= 2.0 && fDiff < 3.0) fXPModifier = 5.0;
else if (fDiff >= 1.0 && fDiff < 2.0) fXPModifier = 15.0;
else fXPModifier = 30.0;
}
return FloatToInt((fXPModifier * 10) + fBonus);
}
// This is my function to give XP to each party member within
// the distance specified by the constants
void GiveXP(object oKiller, int iXPToGive, float fKillerBonus, int iDiff, int iPlayer)
{
int iMaxXP;
float fDist;
// Get first party members (Only PC's)
object oParty = GetFirstFactionMember(oKiller);
// Loops through all party members
while (GetIsObjectValid(oParty))
{
// Make sure the party member is NOT dead and are within the specified distance
fDist = GetDistanceToObject(oParty);
if (GetIsPC(oParty))
{
if (!GetIsDead(oParty) && fDist >= 0.0 && fDist <= PARTY_DIST)
{
// Reward the killer with bonus if specified in consts
if (oKiller == oParty && iPlayer > 1)
{
GiveXPToCreature(oParty, (iXPToGive + FloatToInt(fKillerBonus)));
if (iDiff)
{
FloatingTextStringOnCreature("Party level difference is too great", oParty);
}
if (FLOATING_TEXT)
{
if (KILLER_XP_GP_BONUS > 0.0)
{
FloatingTextStringOnCreature("Killer Bonus", oParty, FALSE);
}
FloatingTextStringOnCreature(IntToString(iXPToGive + FloatToInt(fKillerBonus))+"XP", oParty, FALSE);
}
if (REWARD_GP)
{
GiveGoldToCreature(oParty, ((iXPToGive + FloatToInt(fKillerBonus)) * GP_REWARD_MULTIPLIER));
if (FLOATING_TEXT)
{
FloatingTextStringOnCreature(IntToString(((iXPToGive + FloatToInt(fKillerBonus)) * GP_REWARD_MULTIPLIER))+"GP", oParty, FALSE);
}
}
}
// Reward other party members
else
{
iMaxXP = GetMaxXP(oParty);
GiveXPToCreature(oParty, iXPToGive);
if (FLOATING_TEXT)
{
DelayCommand(0.1, FloatingTextStringOnCreature(IntToString(iXPToGive)+"XP", oParty, FALSE));
}
if (REWARD_GP)
{
GiveGoldToCreature(oParty, iXPToGive * GP_REWARD_MULTIPLIER);
if (FLOATING_TEXT)
{
DelayCommand(0.1, FloatingTextStringOnCreature(IntToString(iXPToGive * GP_REWARD_MULTIPLIER)+"GP", oParty, FALSE));
}
}
}
}
}
oParty = GetNextFactionMember(oKiller);
}
}
// This is my function for returning the max XP for the PC's level based on the consts
int GetMaxXP(object oPC)
{
int iMaxXP;
switch(GetLevelFromXP(oPC))
{
case 1: iMaxXP = LEVEL_1_MAX_XP; break;
case 2: iMaxXP = LEVEL_2_MAX_XP; break;
case 3: iMaxXP = LEVEL_3_MAX_XP; break;
case 4: iMaxXP = LEVEL_4_MAX_XP; break;
case 5: iMaxXP = LEVEL_5_MAX_XP; break;
case 6: iMaxXP = LEVEL_6_MAX_XP; break;
case 7: iMaxXP = LEVEL_7_MAX_XP; break;
case 8: iMaxXP = LEVEL_8_MAX_XP; break;
case 9: iMaxXP = LEVEL_9_MAX_XP; break;
case 10: iMaxXP = LEVEL_10_MAX_XP; break;
case 11: iMaxXP = LEVEL_11_MAX_XP; break;
case 12: iMaxXP = LEVEL_12_MAX_XP; break;
case 13: iMaxXP = LEVEL_13_MAX_XP; break;
case 14: iMaxXP = LEVEL_14_MAX_XP; break;
case 15: iMaxXP = LEVEL_15_MAX_XP; break;
case 16: iMaxXP = LEVEL_16_MAX_XP; break;
case 17: iMaxXP = LEVEL_17_MAX_XP; break;
case 18: iMaxXP = LEVEL_18_MAX_XP; break;
case 19: iMaxXP = LEVEL_19_MAX_XP; break;
case 20: iMaxXP = LEVEL_20_MAX_XP; break;
case 21: iMaxXP = LEVEL_21_MAX_XP; break;
case 22: iMaxXP = LEVEL_22_MAX_XP; break;
case 23: iMaxXP = LEVEL_23_MAX_XP; break;
case 24: iMaxXP = LEVEL_24_MAX_XP; break;
case 25: iMaxXP = LEVEL_25_MAX_XP; break;
case 26: iMaxXP = LEVEL_26_MAX_XP; break;
case 27: iMaxXP = LEVEL_27_MAX_XP; break;
case 28: iMaxXP = LEVEL_28_MAX_XP; break;
case 29: iMaxXP = LEVEL_29_MAX_XP; break;
case 30: iMaxXP = LEVEL_30_MAX_XP; break;
case 31: iMaxXP = LEVEL_31_MAX_XP; break;
case 32: iMaxXP = LEVEL_32_MAX_XP; break;
case 33: iMaxXP = LEVEL_33_MAX_XP; break;
case 34: iMaxXP = LEVEL_34_MAX_XP; break;
case 35: iMaxXP = LEVEL_35_MAX_XP; break;
case 36: iMaxXP = LEVEL_36_MAX_XP; break;
case 37: iMaxXP = LEVEL_37_MAX_XP; break;
case 38: iMaxXP = LEVEL_38_MAX_XP; break;
case 39: iMaxXP = LEVEL_39_MAX_XP; break;
case 40: iMaxXP = LEVEL_40_MAX_XP; break;
}
return iMaxXP;
}
// This new function will get the players level determined by XP rather than
// the players level to stop exploiting, also compatible with the Legendary Leveler
int GetLevelFromXP(object oPC)
{
/* Legendary Level amounts
if (iXP >= 1870000) iXP = 60;
else if (iXP >= 1811000) iXP = 59;
else if (iXP >= 1753000) iXP = 58;
else if (iXP >= 1696000) iXP = 57;
else if (iXP >= 1540000) iXP = 56;
else if (iXP >= 1485000) iXP = 55;
else if (iXP >= 1431000) iXP = 54;
else if (iXP >= 1378000) iXP = 53;
else if (iXP >= 1326000) iXP = 52;
else if (iXP >= 1275000) iXP = 51;
else if (iXP >= 1225000) iXP = 50;
else if (iXP >= 1176000) iXP = 49;
else if (iXP >= 1128000) iXP = 48;
else if (iXP >= 1081000) iXP = 47;
else if (iXP >= 1035000) iXP = 46;
else if (iXP >= 990000) iXP = 45;
else if (iXP >= 946000) iXP = 44;
else if (iXP >= 903000) iXP = 43;
else if (iXP >= 861000) iXP = 42;
else if (iXP >= 820000) iXP = 41; */
int iXP = GetXP(oPC);
if (iXP >= 780000) iXP = 40;
else if (iXP >= 741000) iXP = 39;
else if (iXP >= 703000) iXP = 38;
else if (iXP >= 666000) iXP = 37;
else if (iXP >= 630000) iXP = 36;
else if (iXP >= 595000) iXP = 35;
else if (iXP >= 561000) iXP = 34;
else if (iXP >= 528000) iXP = 33;
else if (iXP >= 496000) iXP = 32;
else if (iXP >= 465000) iXP = 31;
else if (iXP >= 435000) iXP = 30;
else if (iXP >= 406000) iXP = 29;
else if (iXP >= 378000) iXP = 28;
else if (iXP >= 351000) iXP = 27;
else if (iXP >= 325000) iXP = 26;
else if (iXP >= 300000) iXP = 25;
else if (iXP >= 276000) iXP = 24;
else if (iXP >= 253000) iXP = 23;
else if (iXP >= 231000) iXP = 22;
else if (iXP >= 210000) iXP = 21;
else if (iXP >= 190000) iXP = 20;
else if (iXP >= 171000) iXP = 19;
else if (iXP >= 153000) iXP = 18;
else if (iXP >= 136000) iXP = 17;
else if (iXP >= 120000) iXP = 16;
else if (iXP >= 105000) iXP = 15;
else if (iXP >= 91000) iXP = 14;
else if (iXP >= 78000) iXP = 13;
else if (iXP >= 66000) iXP = 12;
else if (iXP >= 55000) iXP = 11;
else if (iXP >= 45000) iXP = 10;
else if (iXP >= 36000) iXP = 9;
else if (iXP >= 28000) iXP = 8;
else if (iXP >= 21000) iXP = 7;
else if (iXP >= 15000) iXP = 6;
else if (iXP >= 10000) iXP = 5;
else if (iXP >= 6000) iXP = 4;
else if (iXP >= 3000) iXP = 3;
else if (iXP >= 1000) iXP = 2;
else iXP = 1;
return iXP;
}
void XPDebugMessage(object oPC, float fCR, float fDiff, float fLoLevel, float fHiLevel, float fAvLevel)
{
object oParty = GetFirstFactionMember(oPC);
while (GetIsObjectValid(oParty))
{
SendMessageToPC(oParty, "\nDebug Info"+
"\nCreature CR: "+FloatToString(fCR)+
"\nHighest Level PC: "+FloatToString(fHiLevel)+
"\nLowest Level PC: "+FloatToString(fLoLevel)+
"\nLevel Difference: "+FloatToString(fDiff)+
"\nAverage Party Level: "+FloatToString(fAvLevel));
oParty = GetNextFactionMember(oPC);
}
}
As you can see it's very different from DarkBasic and much less complex but I am eager to learn, so judging by the differences between them, where is the best place for me to start learning DarkBasic?
Regards
§çà®Fãçë™