Page 1 of 1
Scripted Weapons Post!!!
Posted: Mon Nov 05, 2007 3:40 pm
by fps
ok, this post is for people working on scripted weapons for there games.
I'm going to start by describing (because i dont have my script with me) what i am doing with my first scripted weapon to Juutis because his weapons seem to actually work.
I am working on a scripted m16a4 (first person), the semi auto and burst version of m16. mine has a scope.
in the game I am looking to use it as a light supporting sniper rifle.
the clip holds 18 5.56 nato rounds.
the two fire modes are, semi (every click fires once), and burst (every click fires 3 times in rapid procession).
the scope is a basic crosshair with 1 level of zoom.
ok, i will have to edit this later.
class it starting.
thanks,
fps
Posted: Mon Nov 05, 2007 8:20 pm
by fps
ok here is my code so far.
i dont get an error message but the pawn does not render at any point in testing. is there anything wrong with my setup code?
Code: Select all
{
//*********** ***** **** aka “FPS”
//started 11-2-07 3:20pm
//Scripted M16A4 Scoped Rifle
//declare variables
//ammo, clip size, projectile, damage attribute
PROJECTILE = 5.56
CLIPSIZE = 18
AMMUNITION = 5.56
DAMAGEATTRIBUTE = health
DAMAGEMAX = 70
DAMAGEMIN = 50
//sounds, animations
FIRESOUND = Weapon\m16a4\fire.wav
EMPTYSOUND = Weapon\dryfire_rifle.wav
RELOADSOUND = Weapon\rifle_reload.wav
ARMSOUND = Player\drawrifle1.wav
ARMANIMATION = draw
IDLEANIMATION = idle
FIREANIMATION = shoot1
WALKANIMATION = idle
DRYFIREANIMATION = idle
RELOADANIMATION = reload
KEYRELOADANIMATION = reload
//stored values
//spawn
Spawn[ ()
{
Console(true);
Gravity(false);
SetNoCollision();
//no need to show up on radar because this is just the first person display
HideFromRadar(true);
BoxWidth(0);
BoxHeight(20);
LowLevel(“Setup”);
} ]
//setup
Setup[ ()
{
self.ThinkTime = 0;
//weapon inactive so hide from world
PawnRender(false);
If(getAttribute(“m16a4scoped”, “Player”) = 1)
{
Debug(“obtained the scoped m16a4”);
self.think = “inactive”
}
} ]
inactive[ ()
{
self.ThinkTime = 0.1;
debug(“player is carrying the m16a4, current weapon is”);
debug(self.player_weapon);
if(self.player_weapon = 1)
{
PawnRender(true);
debug(“scoped m16a4 arming”);
AnimateHold(ARMANIMATION);
PlaySound(ARMSOUND);
//self.think = “arm”;
Return 0;
}
} ]
}
Posted: Tue Nov 06, 2007 5:18 pm
by Juutis
The problem with the script is that there are tons of errors.
First of all, variables are defined in the beginning of the script this way:
Not:
Later in the script you can set the value of the variable in the latter way.
There's something in the comments before the variable definitions that causes a script reader error. Try to avoid the special symbols in comments, like : * " , etc.
There's also a lot of capital letters where there should be a normal letter and vice versa. Always check carefully that the commands are spelled properly.
I fixed the errors, this version worked for me:
Code: Select all
{
// Scripted M16A4 Scoped Rifle
// declare variables
// ammo clip size projectile damage attribute
PROJECTILE [5.56]
CLIPSIZE [18]
AMMUNITION [5.56]
DAMAGEATTRIBUTE [health]
DAMAGEMAX [70]
DAMAGEMIN [50]
// sounds animations
FIRESOUND [Weapon\m16a4\fire.wav]
EMPTYSOUND [Weapon\dryfire_rifle.wav]
RELOADSOUND [Weapon\rifle_reload.wav]
ARMSOUND [Player\drawrifle1.wav]
ARMANIMATION [draw]
IDLEANIMATION [idle]
FIREANIMATION [shoot1]
WALKANIMATION [idle]
DRYFIREANIMATION [idle]
RELOADANIMATION [reload]
KEYRELOADANIMATION [reload]
Spawn[ ()
{
Console(true);
Gravity(false);
SetNoCollision();
HideFromRadar(true);
//no need to show up on radar because this is just the first person display
BoxWidth(0);
BoxHeight(20);
LowLevel("Setup");
} ]
//setup
Setup[ ()
{
self.ThinkTime = 0;
//weapon inactive so hide from world
PawnRender(false);
if(GetAttribute("m16a4scoped", "Player") = 1)
{
debug("obtained the scoped m16a4");
self.think = "inactive";
}
} ]
inactive[ ()
{
self.ThinkTime = 0.1;
debug("player is carrying the m16a4, current weapon is");
debug(self.player_weapon);
if(self.player_weapon = 1)
{
PawnRender(true);
debug("scoped m16a4 arming");
AnimateHold(ARMANIMATION);
PlaySound(ARMSOUND);
//self.think = "arm";
return 0;
}
} ]
}
Posted: Tue Nov 06, 2007 8:43 pm
by fps
thanks man,
when i get home i will try it.
i used the microsoft word program to retype the script on this computer. it changes some of the capitalization.
thanks,
fps
Posted: Wed Nov 14, 2007 9:59 pm
by fps
i finally got around to testing this and the weapon still doesent show up in the enviroment.
i used the exact script just like you typed.
i am at a loss to understand what i am doing wrong.
Posted: Thu Nov 15, 2007 9:54 am
by Juutis
fps wrote:i finally got around to testing this and the weapon still doesent show up in the enviroment.
i used the exact script just like you typed.
i am at a loss to understand what i am doing wrong.
Does the console show up?
Posted: Thu Nov 15, 2007 2:44 pm
by fps
nope.
Posted: Thu Nov 15, 2007 5:06 pm
by Juutis
Then the script doesn't run at all... Try removing all the comments (I know, they shouldn't affect anything but sometimes I get weird errors when there's comments) and make sure everything is like they should be in the level editor. The name of the script is correct, the starting order is correct etc.
Posted: Mon Nov 19, 2007 3:45 pm
by fps
i got the script to work for the arming part. now all i need for now is to get the other basic functions of the weapon to work.
next i will setup a function that is executed with other orders that keeps the gun aligned with the player basic camera.
how would you suggest i do this?
i am not even sure i can do this with the basic player.
i believe you used a scripted player in your game juttis.
will i need to do this for mine to work??
Posted: Tue Nov 20, 2007 9:39 am
by Juutis
Yes, I used a scripted player, but I think it's possible with the built-in player too. The manual:
PositionToPlayer(float OffsetX, float OffsetY, float OffsetZ );
Move the pawn's actor to the location of the player actor and apply the offsets to that location.
This command lets you move the pawn with the player very easily.
Also...
self.player_animation
Returns the current player animation.
With some tricks you can use this variable to check if the player is crouched. If you give all of the player's crouching/crawling animations names something in common, like a prefix 'crouch_' ('crouch_idle', 'crouch_move' etc.), you can write
Code: Select all
if(LeftCopy(self.player_animation,6) = StringCopy("crouch"))
to see whether the player is standing or crouching.