"Potion" Item does not work in multiplayer
by Derrick Austin · in Technical Issues · 01/29/2009 (8:51 pm) · 0 replies
I have made an item "Potion" - in multiplayer, the clients can pickup the item and use it; however, only the server can see the "sparks"
ShellExplosion.cs
Item Declaration in item.cs
And this is in default.bind.cs
Any ideas?
ShellExplosion.cs
Quote:
datablock AudioProfile(SpellSound)
{
fileName = "~/data/sound/fx/spark1.wav";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(SpellExplosionSound)
{
filename = "~/data/sound/Crossbow_explosion.wav";
description = AudioDefault3d;
preload = true;
};
//-----------------------------------------------------------------------------
// Spell bolt projectile particles
datablock ParticleData(SpellBoltParticle)
{
textureName = "~/data/shapes/particles/smoke";
dragCoeffiecient = 0.0;
gravityCoefficient = -0.2; // rises slowly
inheritedVelFactor = 0.00;
lifetimeMS = 500; // lasts 0.7 second
lifetimeVarianceMS = 150; // ...more or less
useInvAlpha = false;
spinRandomMin = -30.0;
spinRandomMax = 30.0;
colors[0] = "0.56 0.36 0.26 1.0";
colors[1] = "0.56 0.36 0.26 1.0";
colors[2] = "0 0 0 0";
sizes[0] = 0.25;
sizes[1] = 0.5;
sizes[2] = 1.0;
times[0] = 0.0;
times[1] = 0.3;
times[2] = 1.0;
};
datablock ParticleEmitterData(SpellBoltEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 5;
ejectionVelocity = 0.25;
velocityVariance = 0.10;
thetaMin = 0.0;
thetaMax = 90.0;
particles = SpellBoltParticle;
};
//-----------------------------------------------------------------------------
// Projectile Explosion
datablock ParticleData(SpellExplosionParticle)
{
textureName = "~/data/shapes/particles/smoke";
dragCoefficient = 2;
gravityCoefficient = 0.2;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 1000;
lifetimeVarianceMS = 150;
colors[0] = "0.002362 0.010866 0.700000 0.370079";
colors[1] = "0.000000 0.102362 0.800000 0.740157";
sizes[0] = 0.5;
sizes[1] = 1.0;
};
datablock ParticleEmitterData(SpellExplosionEmitter)
{
ejectionPeriodMS = 7;
periodVarianceMS = 0;
ejectionVelocity = 2;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 60;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
particles = "SpellExplosionParticle";
};
datablock ParticleData(SpellExplosionSmoke)
{
textureName = "~/data/shapes/particles/smoke";
dragCoeffiecient = 100.0;
gravityCoefficient = 0;
inheritedVelFactor = 0.25;
constantAcceleration = -0.80;
lifetimeMS = 1200;
lifetimeVarianceMS = 300;
useInvAlpha = true;
spinRandomMin = -80.0;
spinRandomMax = 80.0;
colors[0] = "0.56 0.36 0.26 1.0";
colors[1] = "0.2 0.2 0.2 1.0";
colors[2] = "0.0 0.0 0.0 0.0";
sizes[0] = 1.0;
sizes[1] = 1.5;
sizes[2] = 2.0;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(SpellExplosionSmokeEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 4;
velocityVariance = 0.5;
thetaMin = 0.0;
thetaMax = 180.0;
lifetimeMS = 250;
particles = "SpellExplosionSmoke";
};
datablock ParticleData(SpellExplosionSparks)
{
textureName = "~/data/shapes/particles/spark";
dragCoefficient = 1;
gravityCoefficient = 0.0;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 500;
lifetimeVarianceMS = 350;
colors[0] = "0.60 0.40 0.30 1.0";
colors[1] = "0.60 0.40 0.30 1.0";
colors[2] = "1.0 0.40 0.30 0.0";
sizes[0] = 0.5;
sizes[1] = 0.25;
sizes[2] = 0.25;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(SpellExplosionSparkEmitter)
{
ejectionPeriodMS = 3;
periodVarianceMS = 0;
ejectionVelocity = 13;
velocityVariance = 6.75;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 180;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = true;
lifetimeMS = 100;
particles = "SpellExplosionSparks";
};
datablock ExplosionData(SpellSubExplosion1)
{
offset = 1.0;
emitter[0] = SpellExplosionSmokeEmitter;
emitter[1] = SpellExplosionSparkEmitter;
};
datablock ExplosionData(SpellSubExplosion2)
{
offset = 1.0;
emitter[0] = SpellExplosionSmokeEmitter;
emitter[1] = SpellExplosionSparkEmitter;
};
datablock ExplosionData(SpellExplosion)
{
soundProfile = SpellExplosionSound;
lifeTimeMS = 1200;
// Volume particles
particleEmitter = SpellExplosionEmitter;
particleDensity = 80;
particleRadius = 1;
// Point emission
emitter[0] = SpellExplosionSmokeEmitter;
emitter[1] = SpellExplosionSparkEmitter;
// Sub explosion objects
subExplosion[0] = SpellSubExplosion1;
subExplosion[1] = SpellSubExplosion2;
// Camera Shaking
shakeCamera = true;
camShakeFreq = "10.0 11.0 10.0";
camShakeAmp = "1.0 1.0 1.0";
camShakeDuration = 1.5;
camShakeRadius = 50.0;
// Dynamic light
lightStartRadius = 6;
lightEndRadius = 3;
lightStartColor = "0.5 0.5 0";
lightEndColor = "0 0 0";
};
Item Declaration in item.cs
Quote:
datablock ItemData(Potion){
category = "Potion";
shapeFile = "~/data/shapes/items/potion/potion.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
respawnTime = 600000;
maxInventory = 2;
pickupName = "a magic potion";
};
function Potion::onUse(%this,%user){
//Takes the potion out of inventory.
%user.decInventory(%this,1);
// Variables for creating the explosion/projectile
%radiusDamage = 30.0;
%radius = 5;
%client = %user.client;
%pos = %client.player.getTransform();
%x = getWord(%pos, 0);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);
// adjust z value a bit...
%z += 2.0;
%finalPos = %x SPC %y SPC %z;
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 20);
%finalPos = vectorAdd(%finalPos, %vec);
// Checks collisions
%RayCast=containerraycast(vectoradd(%client.player.getposition(),"0 0 2.5"),%finalPos,$TypeMasks::WaterObjectType |
$TypeMasks::WaterObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::VehicleBlockerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::ShapeBaseObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::StaticObjectType |
$TypeMasks::StaticShapeObjectType,%player);
if(%RayCast){
%x = getword(%RayCast,1);%y = getword(%RayCast,2);%z = getword(%RayCast,3);
%finalpos = %x SPC %y SPC %z;
}
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
client = %user.client;
};
MissionCleanup.add(%p);
// Apply Damage.
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
}
And this is in default.bind.cs
Quote:
function usePotion(%val){
commandToServer('use',"Potion");
}
moveMap.bind(keyboard, "2", usePotion);
Any ideas?
About the author