Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

MMORPG Toolkit patch beta 0.1 -> beta 0.2

Hugh Perkins
Junior Member
Join date: 26 Nov 2003
Posts: 25
11-30-2003 04:41
New this version:

New features:
- projectile weapon modules added

Bug fixes:
- settext for monster corpse based on object name now instead of owner

Enjoy. Make sure to send me bug reports and requests for change!

Hugh Perkins
Hugh Perkins
Junior Member
Join date: 26 Nov 2003
Posts: 25
Projectileweapon module
11-30-2003 04:44
Projectileweapon module

The projectileweapon module allows you to integrate projectile weapons into an MMORPG Toolkit virtual game.

To make a projectile weapon:

- make a projectile
- add the projectile module (see below)

- make a gunlike attachment
- add this script
- add the projectile object

Now you just made yourself an MMORPG Toolkit compatible projectile weapon!

Your rights to use this code:

You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.

Hugh Perkins

CODE

// The Weapon module is responsible for responding to player commands to attack another player or monster
//
// This weapons module is optimized for projectile-style weapons.
// Use it in guns or similar
//
// Players will need in addition:
// - to be wearing a CombatSystems GRI object (eg appropriately scripting bracelet)
// - other players to attack, or monsters
//
// Optional other items for plqyers:
// - shield object
//
// Roles and responsibilities:
// The Weapon module is responsible for:
// - responding to player commands asking it to attack something
// - definition of attack type, power and so on
// - enforcement of charge time, recharge time, and charge limitations, as required by weapon designer
//
// Parameters:
// ChannelWpn - make sure this is the same as what is on the SendDmg module of your CS GRI
//
// Public interface:
//
// Methods:
// Player controls weapon via attachment interface. No explicit methods
//
// Events:
//
// Attack:
// llWhisper( ChannelWpn, "ATTACK-=-<Target key>-=-<AttackType>-=-<AttackVector>-=-<Power>-=-<CoolDown>"
// Swords send this to the SendDmg module to attack other avatars or monsters
//
// (note <param> means "the value of parameter param")
//
//
// Detail on attacks
// =================
//
// - AttackType, AttackVector and Power are defined by the CS GRI REceiveDmg module. See ReceiveDmg module
// documentation for more info
// - Cooldown is used to enforce a delay between attacks with the weapon
// - Currently Cooldown is enforced by the weapon, but this will be migrated to the SendDmg module, in order
// to allow enforcement of the AttackSpeed stat
//
// Your rights to use this code:
// =============================
//
// You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.
//
// Hugh Perkins
//

integer ChannelWpn = 4;
integer ChannelProjectile = 6;

string AttackType = "DirectDamage";
string AttackVector = "PROJECTILE";
integer AttackPower = 20;
float CoolDown = 0.5;
integer IdealProjectileSpeed = 15;

string ProjectileObjectName = "Projectile";

string PlayerName;
key Playerid;

float LastAttack = 0;
integer have_permissions = FALSE;
integer Message2displayed = FALSE;

float LauncherHeightOffset = 0.8;

TellPlayer( string Message )
{
llWhisper(0,PlayerName + ", " + Message );
}

Debug( string message )
{
llWhisper( 0, llGetScriptName() + ": " + message );
}

Fire()
{
rotation AvatarRot;
vector AvatarForwardVector;
vector LauncherPos;
vector ProjectileVelocity;

AvatarRot = llGetRot();
AvatarForwardVector = llRot2Fwd(AvatarRot);
LauncherPos = llGetPos() + AvatarForwardVector;
LauncherPos.z = LauncherPos.z + LauncherHeightOffset;
ProjectileVelocity = AvatarForwardVector * IdealProjectileSpeed;
llRezObject(ProjectileObjectName, LauncherPos, ProjectileVelocity, AvatarRot, TRUE);
}

GenericInit()
{
Playerid = llGetOwner();
PlayerName = llKey2Name( Playerid );
PlayerName = llGetSubString( PlayerName, 0, llSubStringIndex( PlayerName, " ") );

TellPlayer( "Switch to mouselook to attack!" );
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
// llPreloadSound( "swordhit" );
llPreloadSound( "shoot" );

Message2displayed = FALSE;
llSetTimerEvent(5.0);
}

default
{
state_entry()
{
Debug( "Compile completed" );
llListen( ChannelWpn, "","","" );
llListen( ChannelProjectile, "","","" );
GenericInit();
}
on_rez(integer startparam)
{
GenericInit();
}

timer()
{
llSay(0, "Use me wisely, " + PlayerName + "!");
llSetTimerEvent(0.0);
Message2displayed = TRUE;
}
run_time_permissions(integer perms)
{
if(perms & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN | CONTROL_ML_LBUTTON, TRUE, TRUE);
have_permissions = TRUE;
}
}

attach(key attachedAgent)
{
if (attachedAgent != NULL_KEY)
{
Playerid = llGetOwner();
llRequestPermissions(Playerid,
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{
if (have_permissions)
{
llReleaseControls();
have_permissions = FALSE;
}
}
}

control(key name, integer levels, integer edges)
{
if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{
if( LastAttack < llGetTimeOfDay() - CoolDown )
{
LastAttack = llGetTimeOfDay();
Fire();
llPlaySound("shoot",1.0 );
}
}
}

listen( integer channel, string name, key id, string message )
{
if( channel == ChannelProjectile )
{
// Debug( "Struck received" );
list Arguments;
Arguments = llParseString2List( message, ["-=-"], [] );

string Command;
Command = llList2String( Arguments, 0 );

if( Command == "TARGETSTRUCK" )
{

key FirerId;
FirerId = (key)llList2String( Arguments, 1 );

if( FirerId == Playerid )
{

key Targetid;
Targetid = (key)llList2String( Arguments, 2 );

llWhisper( ChannelWpn, "ATTACK" + "-=-" + (string)Playerid + "-=-" + (string)Targetid + "-=-" + AttackType + "-=-" + AttackVector + "-=-" + (string)AttackPower + "-=-" + (string)CoolDown );
}
}
}
}
}
Hugh Perkins
Junior Member
Join date: 26 Nov 2003
Posts: 25
Projectile module
11-30-2003 04:46
Projectile module

Use this to make an MMORPG Toolkit compatible projectile for use in MMORPG Toolkit compatible projectile weapons!

Your rights to use this code:

You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.

Hugh Perkins

CODE

// Projectile module
// Use this to make an MMORPG Toolkit compatible projectile for use in
// MMORPG Toolkit compatible projectile weapons!
//
// Your rights to use this code:
// =============================
//
// You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.
//
// Hugh Perkins
//

integer ChannelProjectile = 6;

integer bArmed = FALSE;

Debug( string message )
{
llWhisper( 0, llGetScriptName() + ": " + message );
}

default
{
on_rez(integer param)
{
llSetStatus(STATUS_DIE_AT_EDGE, TRUE);
llSetBuoyancy(1.0);
if (param)
{
bArmed = TRUE;
}
}

collision_start(integer total_number)
{
if (bArmed)
{
key Targetid;
Targetid = llDetectedKey(0);
// Debug( (string)Targetid );
llShout( ChannelProjectile, "TARGETSTRUCK-=-" + (string)llGetOwner() + "-=-" + (string)Targetid );
llDie();
}
}
land_collision_start(vector pos)
{
if (bArmed)
{
llDie();
}
}
}
Hugh Perkins
Junior Member
Join date: 26 Nov 2003
Posts: 25
Patch: new Stats module
11-30-2003 04:48
Patch: new Stats module

Patched so that when monsters die, the corpse uses the monster's name instead of the owner's name.

Your rights to use this code:

You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.

Hugh Perkins

CODE

// The Stats module is responsible for storing stats for the Avatar, such as life, mana, and so on
//
// It forms part of the CombatSystems GRI (CS GRI) and should be combined with the other CombatSystems GRI modules
// into something like a bracelet that all game participants will wear
//
// You will need in addition:
// - a weapon object / magical stave / wand - make this using the Weapons module
// - other players to attack, or monsters
//
// The CombatSystems GRI modules are:
// - ReceiveDmg
// - SendDmg
// - SecureComms
// - Stats
//
// Roles and responsibilities:
// Stats is responsible for:
// - Storing current avatar stats
// - responding to stat update messages ("SETSTAT", "RAISESTAT")
// - Letting other CS GRI modules know when a stat has changed
// - Displaying stats to user
//
// Parameters:
// - no parameters, it learns everything from other modules
// - you can set initial values for avatar statistics here if you want
//
// Public interface:
//
// Methods:
//
// Modify statistics:
// llLinkedMessage( "RAISESTAT-=-<Stat Name>-=-<Amount to add to statistic>" ); // can be negative
// llLinkedMessage( "SETSTAT-=-<Stat Name>-=-<New value for stat>" ); // negative numbers will be floored to zero
// llLinkedMessage( "PINGSTATS" ); // asks stats module to send all known stats (in statupdate messages)
//
// Events:
//
// Stats update:
// llLinkedMessage( "STATUPDATE-=-<Stat Name>-=-<New value for stat>" ); // let other CS GRI modules know a stat
// has changed
//
// (note <param> means "the value of parameter param")
//
// Your rights to use this code:
// =============================
//
// You can freely use and derive from this code as long as you dont affect my ability or rights to do so myself.
//
// Hugh Perkins
//

integer Life = 100;
integer AttackSpeed = 100; // percent of norm
integer MoveSpeed = 100; // percent of norm
integer Mana = 100;
integer AttackRange = 100; // percent of norm
integer AttackPower = 100; // percent of norm

vector GREEN = <0,4,0>;
vector RED = <4,0,0>;
vector ORANGE = <4,0.5,0>;
vector YELLOW = <4,4,0>;
vector BLUE = <0,0,4>;

SetText( string text, vector color )
{
llSetText( text, color,1.0 );
}

ShowLife()
{
if( Life > 50 )
{
SetText( "Life: " + (string)Life, GREEN );
}
else if( Life > 10 )
{
SetText( "Life: " + (string)Life, ORANGE );
}
else if( Life > 0 )
{
SetText( "Life: " + (string)Life, RED );
}
else
{
if( llGetAttached() != 0 )
{
SetText( "-- " + llKey2Name(llGetOwner() ) + "'s Corpse --", RED );
}
else
{
SetText( "-- " + llGetObjectName() + "'s Corpse --", RED );

}
}
}

SendStat( string StatName )
{
if( StatName == "Life" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-Life-=-" + (string)Life, "" );
}
else if( StatName == "AttackSpeed" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-AttackSpeed-=-" + (string)AttackSpeed, "" );
}
else if( StatName == "MoveSpeed" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-MoveSpeed-=-" + (string)MoveSpeed, "" );
}
else if( StatName == "Mana" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-Mana-=-" + (string)Mana, "" );
}
else if( StatName == "AttackRange" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-AttackRange-=-" + (string)AttackRange, "" );
}
else if( StatName == "AttackPower" )
{
llMessageLinked( LINK_SET, 0, "STATUPDATE-=-AttackPower-=-" + (string)AttackPower, "" );
}
}

BroadcastStats()
{
SendStat( "Life" );
SendStat( "AttackSpeed" );
SendStat( "MoveSpeed" );
SendStat( "Mana" );
SendStat( "AttackRange" );
}

integer GetStat( string StatName )
{
if( StatName == "Life" )
{
return Life;
}
else if( StatName == "AttackSpeed" )
{
return AttackSpeed;
}
else if( StatName == "MoveSpeed" )
{
return MoveSpeed;
}
else if( StatName == "Mana" )
{
return Mana;
}
else if( StatName == "AttackRange" )
{
return AttackRange;
}
else if( StatName == "AttackPower" )
{
return AttackRange;
}
return 0;
}

SetStat( string StatName, integer StatValue )
{
if( StatValue < 0 )
{
StatValue = 0;
}

if( StatName == "Life" )
{
Life = StatValue;
ShowLife();
}
else if( StatName == "AttackSpeed" )
{
AttackSpeed = StatValue;
}
else if( StatName == "MoveSpeed" )
{
MoveSpeed = StatValue;
}
else if( StatName == "Mana" )
{
Mana = StatValue;
}
else if( StatName == "AttackRange" )
{
AttackRange = StatValue;
}
else if( StatName == "AttackPower" )
{
AttackPower = StatValue;
}
SendStat( StatName );
}

default
{
state_entry()
{
ShowLife();
}
on_rez( integer param )
{
ShowLife();
}
link_message( integer sendernum, integer num, string message, key id )
{
list Arguments;
Arguments = llParseString2List( message, ["-=-"], [] );

string Command;
Command = llList2String( Arguments, 0 );

string StatName;
StatName = llList2String( Arguments, 1 );

integer StatValue;
StatValue = (integer)llList2String( Arguments, 2 );

integer CurrentStat;

if( Command == "SETSTAT" )
{
SetStat( StatName, StatValue );
}
else if( Command == "RAISESTAT" )
{
CurrentStat = GetStat( StatName );
SetStat( StatName, CurrentStat + StatValue );
}
else if( Command == "MINSTAT" )
{
// MinStat( StatName, StatValue );
}
else if( Command == "MAXSTAT" )
{
// MaxStat( StatName, StatValue );
}
else if( Command == "PINGSTATS" )
{
BroadcastStats();
}
}
}