PDA

View Full Version : Problem with realistic weapon tutorial script....



Stromberg90
11-11-2009, 06:32 PM
Hy there, i am having a problem with this part of the script, it only happend after adding this part.

--------------------------------------
simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
/Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}
-----------------------------------------------

When compiling i do get a "Error Bad or missing expression in "IF"


Please give me some help, this tutorial is written for UT3 btw, and i know there is some differences, but since i am not realy good in scripting, i need some help from you :)

Here is the tutorial i am following: http://utforums.epicgames.com/showthread.php?t=704840&page=2

Blaaguuu
11-11-2009, 10:21 PM
Perhaps if you posted the whole class code that you have sofar, if it isnt too massive. Also, if you paste it inside of ["CODE"]["/CODE"] tags (minus the "s ofcourse) it will be formatted correctly in your post.

SlimeMeteor
11-11-2009, 10:36 PM
/Stop firing the weapon <<-- lost one " / " at home?
StopFire(0);

chrustec
11-12-2009, 01:19 AM
/Stop firing the weapon <<-- lost one " / " at home?
StopFire(0);

Yup I concur I think this might be it

Also you might want to space out your code a little so its cleaner to read. Instead of this;


--------------------------------------
simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
/Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}
----------------------------------------

try this;


--------------------------------------
simulated function InstantFire()
{
// If we have bullets then fire
if (BulletCount > 0)
{
// Deduct 1 from our BulletCount var
BulletCount -= 1;

// Fire the bullet
super.instantFire();
}
else
{
// If we don't have bullets then reload
// Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}
----------------------------------------

Just makes for an easier read :) - Also make sure when posting code snippits in the forums use the "[ CODE]Paste your code here...[/CODE ]" so that your code formatting is retained :)

Hope this helps.

Solid Snake
11-12-2009, 01:25 AM
Either that or BulletCount doesn't exist perhaps?

Blaaguuu
11-12-2009, 01:26 AM
Also, what are you using to edit your scripts? I'm guessing if something as simple as a missing / got past you, you aren't using something with syntax highlighting... I highly recommend getting a better editor such as Context, WOTgreal, or nFringe.

Solid Snake
11-12-2009, 01:27 AM
Visual Studio 2008 Express vanilla is just fine. Just parse Unrealscript like C++ and you get most of the definitions. Add some Unrealscript ones and you get a nifty one for free.

Stromberg90
11-12-2009, 04:06 AM
Thanks everyone, altough adding the / to the right place dosnt seam to help.
Still get the "if" error.

I am using conTEXT btw, and i have syntax highlighting on... but since i am not any good at coding yet, i am trying to learn as much as i can.

The code was to long to be posted here:p
You can check the tutorial to see what i am working on here, page 2 is where i get my problem.


simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
//Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}

Malachor
11-12-2009, 04:32 AM
When compiling i do get a "Error Bad or missing expression in "IF"
What about the rest of the error? It tells you what line the error occurs, and while unlikely, it may not be what you've posted. Unless of course, you've already checked that.
Also have you added:

// Holds the amount of bullets in our gun
var int BulletCount;
just under your class declaration? Which would look something like this:

class MyWeapon extends UTWeap_Sniperrifle;
And have you added:

BulletCount=6
to your defaultproperties?
NB: This is pretty much what SolidSnake has suggested, just a bit expanded.

Stromberg90
11-12-2009, 05:43 AM
Malachor: Thanks for helping me :)

I think i have written the whole error on the first page.

First it's the path and then it says : Error, bad or missing expression in 'if'
It just tells me what file it is in, not what line, unless i am missing something.


This is my Ak code so far.


//================================================
// Ak 47 Realistic Reaload :)
//================================================

class UTWeap_Ak47 extends UTWeap_LinkGun;

//Holds the ammount of bullets in our gun
var int BulletCount;

exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon has:"$BulletCount);

Defaultproperties
{
FireInterval(0)=+0.5
BulletCount=30
ShotCost(0)=0
ShotCost(1)=0
}

exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast (self, "Reload");
}

The other code i posted is in the link gun code, copying what he has done in the tutorial since he does add it to the sniper rifle from what i understand, please correct me if i am wrong.

Stromberg90
11-12-2009, 06:04 AM
Here is something that can be the line the error is on it says "(774) : Error, bad or missing expression in 'if'"

Can the (774) be the line that the error is on?

Yepp it was, but still the same problem, line 774 is
if(BulletCount > 0)

Blaaguuu
11-12-2009, 11:07 AM
Two issues I noticed... maybe they will fix it.

You are missing the closing brace on MyDebug(), and I believe the defaultproperties has to be the very last block of code in the class... so move RealReload() up above it.

Jezcentral
11-12-2009, 11:43 AM
You are missing the closing brace on MyDebug().
True, this is why chrustec's advice is so good. Indenting code prevents this from happening. (Most of the time :rolleyes: ).

Makaze
11-12-2009, 01:19 PM
I'd also suggest that InstantFire() is the wrong place to be subtracting a bullet. The current implementation uses up ammo in FireAmmunition(). This has the advantage of working for instant, projectile, and custom weapons. You'd be better off subtracting from your weapons clip there and then from the main ammo pool in the reload function.

Stromberg90
11-12-2009, 02:35 PM
Hy again, i am realy hoping we can get this to work.

I have done what you said still not working.... get the same error.
I know there is something wrong with the
if(BulletCount > 0) cause it says so when i compile :p

Makaze: I dont realy know coding that why i am following this tutorial to get a grasp of it... if you can guide me trough some of it i would be realy greatfull :)

Blaaguuu
11-12-2009, 10:31 PM
A shot in the dark, since you still haven't posted the whole class in its entirety... but did you possibly define InstantFire() above the "var int BulletCount;" line, rather than below it?

Stromberg90
11-13-2009, 09:36 AM
Blaaguuu: Hy there, thanks for helping :)
About that those 2 lines are not in the same script....
InstantFire() is in the UTWeap_LinkGun.uc and the
var int BulletCount is in the UTWeap_Ak47.
Like the guy in the tutorial said, atleast from what i understand, i could be horrible wrong..:p

Swordy
11-13-2009, 10:01 AM
Sorry if this is a silly question, but in this tutorial it states that I should replace the Impact Hammer to get my weapon in the game.

I've found the ReplaceWeapon() function in Weapon Locker, but I'm not quite sure where to use it, and the tutorials I can find on it seem to be focused on mutators rather a new GameType extending from UTDeathmatch.

Where would I use this or how would I script my weapon in to the game?

johanz
11-13-2009, 10:07 AM
If you use UDK, there is no impact hammer, is there?

Swordy
11-13-2009, 10:09 AM
If you use UDK, there is no impact hammer, is there?

Well no, but sticking the weapon at Index 0 of the Weapons array should have the same effect I would imagine :D

The problem I'm having is finding the actual code that supplies the default weapons at the start of the game, so I can override it. I would prefer to do it by giving it to the user at the start of the level, rather than a pickup to be honest.

Am I even on the right track here? In UTGame, AddDefaultInventory() seems to grant a collection of weapons at the start of the game, and on respawns and uses a Weapon Locker to hold these weapons.

So my thought is to create a new Weapon Locker with my weapon included within it, as it includes an array of Weapons of UTWeapon type, which mine is, but I just cannot see where the array is being populated from.

Parsing the ini files maybe?

Stromberg90
11-13-2009, 10:45 AM
Hy again, for some reason the
if[BulletCount > 0) does not work, someone must know why it dosnt work... please?:D

I have been trying to get this to work for sevral days now...

Xendance
11-13-2009, 10:51 AM
Hy again, for some reason the
if[BulletCount > 0) does not work, someone must know why it dosnt work... please?:D

I have been trying to get this to work for sevral days now...

Now I only have coded in java, but have you declared the type of BulletCount somewhere? (I don't know if this is needed with unreal script)

Stromberg90
11-13-2009, 11:38 AM
Xendance: Hy, i guess i have... cause i am just following a tutorial and i have done exactly what he has... i have a feeeling that the "if" function may have changed from UT3 to UDK..
Thanks for trying to help anyway ;)

Xendance
11-13-2009, 11:44 AM
Sorry, I missed the "var int BulletCount;" part :P

Swordy
11-13-2009, 11:45 AM
Did you change your code to make it better formatted like posted before?

Stromberg90
11-13-2009, 12:11 PM
It was formated, it just diddint show up here.

Jezcentral
11-13-2009, 12:15 PM
Where did that square bracket come from?

Stromberg90
11-13-2009, 12:55 PM
Jezcentral: Where? I cant find any...

Swordy
11-13-2009, 01:17 PM
Well no, but sticking the weapon at Index 0 of the Weapons array should have the same effect I would imagine :D

The problem I'm having is finding the actual code that supplies the default weapons at the start of the game, so I can override it. I would prefer to do it by giving it to the user at the start of the level, rather than a pickup to be honest.

Am I even on the right track here? In UTGame, AddDefaultInventory() seems to grant a collection of weapons at the start of the game, and on respawns and uses a Weapon Locker to hold these weapons.

So my thought is to create a new Weapon Locker with my weapon included within it, as it includes an array of Weapons of UTWeapon type, which mine is, but I just cannot see where the array is being populated from.

Parsing the ini files maybe?

I'm still struggling on this is anybody can help me please?
I'm trying to work out where the default weapons are given in the code.

Blaaguuu
11-13-2009, 09:38 PM
DefaultInventory is an array of Inventory derived classes located in your GameInfo class... So put something like this in your game type's default props:

DefaultInventory(0)=class'MyGame.NeatoWeapon'
DefaultInventory(1)=class'MyGame.NeaterWeapon'

And back on the original subject of this thread... Stromberg90, you said that the "InstantFire()" and "var int BulletCount" lines are in two different files? All of your code for the weapon should be in the UTWeap_Ak47.uc file. You should NOT be editing the UTWeap_LinkGun.uc if that is what you did.

Again... if you can post your entire UTWeap_Ak47.uc file, I'm 99% sure we could help you out immediately, but as it stands, we are all just guessing as to what exactly you did. use this site if you cant fit it all here: http://unreal.pastebin.com/

Stromberg90
11-13-2009, 10:19 PM
Blaaguuu: Thanks i will try that when i get to school tomorrow.. :)

I know i should not be editing the orginal files but i am just following a tutorial and he said we need to overwrite a function inside the weapon we extends our weapon from, he uses the sniper rifle wich is not included in the udk.

And i have posted the whole UTWeap_Ak47.uc file before.
But here we go once more, this is what i have so far from following the tutorial.


//================================================
// Ak 47 Realistic Reaload :)
//================================================

class UTWeap_Ak47 extends UTWeap_LinkGun;

//Holds the ammount of bullets in our gun
var int BulletCount;

exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon has:"$BulletCount);

Defaultproperties
{
FireInterval(0)=+0.5
BulletCount=30
ShotCost(0)=0
ShotCost(1)=0
}

exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast (self, "Reload");
}

Stromberg90
11-13-2009, 10:21 PM
Maybe i did find it, could this be it?


exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self,"Weaponhas:"$BulletCount);


Should be.


exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self,"Weaponhas:"$BulletCount);
}

Stromberg90
11-13-2009, 10:23 PM
Ah.. you told me before ;)
I just did misunderstand you, i though you meant i had "MyDebug(" and not "MyDebug()".

Guess that will fix it? :)

Malachor
11-14-2009, 03:45 AM
So is this in UTWeapLinkgun.uc?

simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
//Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}
And this is in UTWeap_Ak47.uc?

//================================================
// Ak 47 Realistic Reaload :)
//================================================

class UTWeap_Ak47 extends UTWeap_LinkGun;

//Holds the ammount of bullets in our gun
var int BulletCount;

exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon has:"$BulletCount);

Defaultproperties
{
FireInterval(0)=+0.5
BulletCount=30
ShotCost(0)=0
ShotCost(1)=0
}

exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast (self, "Reload");
}

I think I know why you're getting that error: var int BulletCount; is in the wrong class. It should be declared in the parent class, or, in the actual class you need it to be in.
Try:

//================================================
// Ak 47 Realistic Reload :)
//================================================

class UTWeap_Ak47 extends UTWeap_LinkGun;

//Holds the amount of bullets in our gun
var int BulletCount;

exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon has:"$BulletCount);
}

simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
//Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}

exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast (self, "Reload");
}

Defaultproperties
{
FireInterval(0)=+0.5
BulletCount=30
ShotCost(0)=0
ShotCost(1)=0
}
One thing I forgot to ask was, "What class had the error?" Since you mentioned that "InstantFire" had the error, I assumed that "var int BulletCount;" and "BulletCount=30" were in the same class as "InstantFire".
Having said that, the error should also tell you the class the error occurs in.

A couple of quick points, Defaultproperties should be the last thing in your class, so it's right down the bottom. And don't directly modify an epic class. Always extend from one. Even if you just copy the file, that's close to what you want, to your mod's classes folder, rename it, then remove any code you don't need. And then remember to change the class declaration from epic's to yours, which you did for the UTWeap_Ak47, so that's good.
I hope this helps :)
And I hope I didn't forget anything ;)

Blaaguuu
11-14-2009, 07:03 AM
I know i should not be editing the orginal files but i am just following a tutorial and he said we need to overwrite a function inside the weapon we extends our weapon from, he uses the sniper rifle wich is not included in the udk.


I think you misunderstood what the tutorial was getting at. the InstantFire() function exists in the weapon you are extending from, so if you 'overwrite' it in your own class, yoru weapon will behave like the linkgun, except for the functions/variables that you overwrite. There is absolutely no reason why you should ever edit the Epic classes, unless you are into some really serious modding and have come across a very unique problem. It looks like Malachor is right on target... You are introducing the BulletCount variable in your extended class, but the function that uses it is in a class before it in the hierarchy, so LinkGun has no idea that the BulletCount variable exists. Just move all of your code to the ak47 class, and make sure you have the order right, and everything should work fine.

Stromberg90
11-14-2009, 09:40 AM
Thanks both of you will try all of this very soon and tell you how it goes;)

Malachor: The class the error was in was the UTWeap_Linkgun.uc and this
if(BulletCount > 0) line in the code.

Stromberg90
11-14-2009, 11:10 AM
I have been trying it now, and i remember i did this before actualy.

It compiles fine but the problem is it's not working, when i write MyDebug in the console it says "Bullet Count: 30" but even if i shot some it dosnt change, and i tought if i type it again maybe it will refresh, but still says 30.

Thanks for helping me out :)

kyoryu
11-14-2009, 05:39 PM
Hy again, for some reason the
if[BulletCount > 0) does not work, someone must know why it dosnt work... please?:D

I have been trying to get this to work for sevral days now...

Any kind of grouping symbol (parentheses, brackets, curly braces, etc.) must match.

You've got a square bracket on the left, and a paren on the right. They should both be parens.

Stromberg90
11-14-2009, 11:04 PM
Ah.. there we go, that can be it.
Since it does match the line of error aswell :)
I will try that as soon as i wake up tomorrow, thanks alot ;)

Stromberg90
11-15-2009, 05:47 PM
Ahh.. wrong again, it's right in the script i just wrote it wrong here..
So back to square one again:p

Thanks for trying to help :)
I hope we can figure this out....

Here is the code:

//================================================
// Ak 47 Realistic Reload :)
//================================================

class UTWeap_Ak47 extends UTWeap_RealisticWeaponBase;

//Holds the amount of bullets in our gun
var int BulletCount;

exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon has:"$BulletCount);
}

simulated function InstantFire()
{
//If we have bullets then fire
if(BulletCount > 0)
{
//deducts 1 from our bulletcount
BulletCount -= 1;

//Shots the bullet
super.instantFire();
}
// if we dont have bullets then reload
else
{
//Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}

exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast (self, "Reload");
}

Defaultproperties
{
FireInterval(0)=+0.5
BulletCount=30
ShotCost(0)=0
ShotCost(1)=0
}

Malachor
11-16-2009, 03:01 AM
There's only 1 thing I can think of, but I haven't looked at much script for a few months.
maybe if you change:
var int BulletCount;
to:
var() int BulletCount;

Kohan
11-16-2009, 03:03 AM
There's only 1 thing I can think of, but I haven't looked at much script for a few months.
maybe if you change:
var int BulletCount;
to:
var() int BulletCount;

No, that would just make the value editable from the Editor, but it's not a placeable class anyway.

Stromberg90
11-20-2009, 01:57 AM
Have tried all the suggestions, nothing of it does work so far... if anyone know please help :)

Blaaguuu
11-20-2009, 02:16 AM
I recommend finding a different tutorial...

marilol
11-20-2009, 12:59 PM
Try >= 1

I've been learning how to make games in flash in the past couple of days. Even though the whole < is a valid comparison flash wouldn't accept it for some reason. No errors or warnings, the code just got ignored.

And if that doesn't work make it a float, that really shouldn't have any affect on the script?

FlamingRain
01-09-2010, 12:48 PM
I'm also having a problem with this.

I was able to get this exact same script working in UT3, but not UDK. I copied the script but extended the Link Gun instead of the sniper rifle.

The weapon goes ingame fine, but if i type MyDebug into the console, nothing shows up.

E: Also, it still deducts from AmmoCount that is displayed in the HUD on screen.



class WP_SMGs extends UTWeap_LinkGun;

// Holds the amount of bullets in our gun
var int BulletCount;
var float ReloadTime;
var bool bReloading;

exec function RealReload()
{
// If we are reloading or out of ammo then dont do anything
if(bReloading || AmmoCount <= 0)
{
return;
}

// Not allow reloading
bReloading = true;

// report that we managed to go into reload state
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Reloading");

// Handle Animations
PlayWeaponAnimation(WeaponPutDownAnim, ReloadTime);
PlayArmAnimation(ArmsPutDownAnim, ReloadTime);


// Delay before we refill the ammo
setTimer(ReloadTime, false, 'RefillAmmo');
}




simulated function RefillAmmo()
{
// if we have enough or more ammo than the weapon needs
if(AmmoCount >= Default.BulletCount)
{
// Set our bullet count back to default value
BulletCount = Default.BulletCount;

// subtrack the ammo from our inventory
AmmoCount -= BulletCount;
}
else
{
// set the bullets to how many we have left
BulletCount = AmmoCount;

// empty our inventory from bullets
AmmoCount = 0;
}

// Allow reloading again
bReloading = false;
}






simulated function InstantFire()
{
// If we have bullets then fire
if(BulletCount > 0)
{
// deducts 1 from our bulletcount
BulletCount -= 1;

// Shots the bullet
super.InstantFire();
}
// if we dont have bullets then reload
else
{
// Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}






exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon Has:"$BulletCount);
}


simulated function bool AllowSwitchTo(Weapon NewWeapon)
{
if(bReloading)
{
return false;
}

return true;
}


defaultproperties
{
FireInterval(0)=+0.15
BulletCount=60
AmmoCount=180
MaxAmmoCount=360
ReloadTime=2.0
ShotCost(0)=0
ShotCost(1)=0
}

geodav
02-06-2010, 03:30 PM
ok this Tutorial works but if you try to change the values it plays up won't reload and runs out of ammo.
what i've done is to use Ace's code as a base for my weapons to extend from as i would like this function on all my weapons.
here's what i have so far

UTWeap_UT40kWeapon.uc

/**
* Copyright 1998-2007 Epic Games, Inc. All Rights Reserved.
*
* Bogded by Geodav 02.2010 with the help of Acecutter69
*/

class UTWeap_UT40kWeapon extends UTWeapon;

// Holds the amount of bullets in our gun
var int BulletCount;
var float ReloadTime;
var bool bReloading;

/*
exec function RealReload()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Reload");
}
*/

exec function RealReload()
{
// If we are reloading or out of ammo then dont do anything
if(bReloading || AmmoCount <= 0)
{
return;
}

// Not allow reloading
bReloading = true;

// report that we managed to go into reload state
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Reloading");

// Handle Animations
PlayWeaponAnimation(WeaponPutDownAnim, ReloadTime);
PlayArmAnimation(ArmsPutDownAnim, ReloadTime);

// Delay before we refill the ammo
setTimer(ReloadTime, false, 'RefillAmmo');
}

simulated function RefillAmmo()
{
// if we have enough or more ammo than the weapon needs
if(AmmoCount >= Default.BulletCount)
{
// Set our bullet count back to default value
BulletCount = Default.BulletCount;

// subtrack the ammo from our inventory
AmmoCount -= BulletCount;
}
else
{
// set the bullets to how many we have left
BulletCount = AmmoCount;

// empty our inventory from bullets
AmmoCount = 0;
}

// Allow reloading again
bReloading = false;
}


simulated function InstantFire()
{
// If we have bullets then fire
if(BulletCount > 0)
{
// deducts 1 from our bulletcount
BulletCount -= 1;

// Shots the bullet
super.InstantFire();
}
// if we dont have bullets then reload
else
{
// Stop firing the weapon
StopFire(0);

// Run the reload function
RealReload();
}
}


simulated function bool AllowSwitchTo(Weapon NewWeapon)
{
if(bReloading)
{
return false;
}

return true;
}



exec function MyDebug()
{
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Weapon Has:"$BulletCount);
}


defaultproperties
{
fireinterval(0) = 1.5
BulletCount=6

ShotCost(0)=0
ShotCost(1)=0

ReloadTime=2.0
}

UTWeap_SMBolter.uc

/**
* Copyright 1998-2007 Epic Games, Inc. All Rights Reserved.
*
* Bogded by Geodav 05.2008
*/
class UTWeap_SMBolter extends UTWeap_UT40kWeapon;

var ParticleSystemComponent PrimaryMuzzleFlashPSC;

var MaterialInstanceConstant WeaponMaterialInstance;

simulated function PostBeginPlay()
{
Super.PostBeginPlay();

// Atttach the muzzle flash
SkeletalMeshComponent(Mesh).AttachComponentToSocke t(PrimaryMuzzleFLashPSC, MuzzleFlashSocket);
}

simulated function SetSkin(Material NewMaterial)
{
Super.SetSkin(NewMaterial);
if( WorldInfo.NetMode != NM_DedicatedServer )
{
WeaponMaterialInstance = Mesh.CreateAndSetMaterialInstanceConstant(1);
}
}

//-----------------------------------------------------------------
// AI Interface

function float GetAIRating()
{
local UTBot B;

B = UTBot(Instigator.Controller);
if ( (B== None) || (B.Enemy == None) )
return AIRating;

if ( !B.LineOfSightTo(B.Enemy) )
return AIRating - 0.15;

return AIRating * FMin(Pawn(Owner).GetDamageScaling(), 1.5);
}

/* BestMode()
choose between regular or alt-fire
*/
function byte BestMode()
{
local float EnemyDist;
local UTBot B;

if ( IsFiring() )
return CurrentFireMode;

B = UTBot(Instigator.Controller);
if ( (B == None) || (B.Enemy == None) )
return 0;

EnemyDist = VSize(B.Enemy.Location - Instigator.Location);
if ( EnemyDist < 2000 )
return 0;
return 1;
}

defaultproperties
{
// Weapon SkeletalMesh
Begin Object class=AnimNodeSequence Name=MeshSequenceA
End Object

// Weapon SkeletalMesh
Begin Object Name=FirstPersonMesh
SkeletalMesh=SkeletalMesh'WP_SMUM_Bolter.Mesh.SK_W P_SMBolter_1st'
AnimSets(0)=AnimSet'WP_SMUM_Bolter.Anim.K_WP_SMBol ter_1st_Base'
Animations=MeshSequenceA
// Rotation=(Yaw=-16384)
FOV=60.0
End Object

AttachmentClass=class'UT40k.UTAttachment_SMBolter'

Begin Object Name=PickupMesh
SkeletalMesh=SkeletalMesh'WP_SMUM_Bolter.Mesh.SK_W P_SMBolter_3rd'
Translation=(X=0.0,Y=20.0,Z=0.0)
Scale=1.25
End Object

PivotTranslation=(X=-8.0,Y=0.0)

// Muzzle Flashes

Begin Object Class=ParticleSystemComponent Name=MuzzleFlashComponent
bAutoActivate=FALSE
Template=particleSystem'WP_SMUM_Bolter.Effects.P_W P_Bolter_Muzzle_Flash'
DepthPriorityGroup=SDPG_Foreground
SecondsBeforeInactive=1.0f
End Object
PrimaryMuzzleFlashPSC=MuzzleFlashComponent

InstantHitMomentum(0)=+60000.0

WeaponFireTypes(0)=EWFT_InstantHit
WeaponFireTypes(1)=EWFT_None
WeaponProjectiles(1)=class'UTProj_ShockBall'

InstantHitDamage(0)=25
// FireInterval(0)=+0.33
// FireInterval(1)=+0.6
InstantHitDamageTypes(0)=class'UTDmgType_SMBolter'
InstantHitDamageTypes(1)=None

WeaponFireSnd[0]=SoundCue'A_UT40k_WeaponSound.Weapon_2.Bolter4_Cue '
WeaponFireSnd[1]=SoundCue'A_UT40k_WeaponSound.Weapon_2.Bolter4_Cue '

WeaponPutDownSnd=SoundCue'A_UT40k_WeaponSound.Weap on_2.boltforward_Cue'
WeaponEquipSnd=SoundCue'A_UT40k_WeaponSound.Weapon _2.boltforward_Cue'
PickupSound=SoundCue'A_UT40k_WeaponSound.Weapon_2. boltforward_Cue'

MaxDesireability=0.65
AIRating=0.65
CurrentRating=0.65
bInstantHit=true
bSplashJump=false
bRecommendSplashDamage=false
bSniping=true
ShouldFireOnRelease(0)=0
ShouldFireOnRelease(1)=1

// ShotCost(0)=1
// ShotCost(1)=1

FireOffset=(X=5,Y=0)
PlayerViewOffset=(X=17,Y=10.0,Z=-14.0)

AmmoCount=20
LockerAmmoCount=30
MaxAmmoCount=60

// WeaponRange=11000 //// 22000
WeaponRange=2000

fireinterval(0) = 0.5
BulletCount=6


FireCameraAnim(1)=CameraAnim'Camera_FX.ShockRifle. C_WP_ShockRifle_Alt_Fire_Shake'

WeaponFireAnim(1)=WeaponAltFire

MuzzleFlashSocket="MF"
MuzzleFlashPSCTemplate=ParticleSystem'WP_SMUM_Bolt er.Effects.P_WP_Bolter_Muzzle_Flash'
MuzzleFlashAltPSCTemplate=WP_ShockRifle.Particles. P_ShockRifle_MF_Alt
MuzzleFlashColor=(R=200,G=120,B=255,A=255)
MuzzleFlashDuration=0.33
// MuzzleFlashLightClass=class'UTWeap_SMBolterMuzzleF lashLight'
CrossHairCoordinates=(U=256,V=0,UL=64,VL=64)
LockerRotation=(Pitch=32768,Roll=16384)

IconCoordinates=(U=728,V=382,UL=162,VL=45)

QuickPickGroup=0
QuickPickWeight=0.9

WeaponColor=(R=160,G=0,B=255,A=255)

InventoryGroup=2
GroupWeight=0.5

IconX=400
IconY=129
IconWidth=22
IconHeight=48

Name="SM Bolter"
// PickupMessage="SM Bolter"
}


anybody any idea's why it doesn't work right

canow
02-07-2010, 08:44 AM
I m working with link gun (with your Tutorial Geodav). And game crush?

geodav
02-07-2010, 02:39 PM
@canow don't use the linkgun as it has to much native code, use the shockrifle to start with, once you get that to work give my a shout on this thread
http://utforums.epicgames.com/showthread.php?t=706668

canow
02-07-2010, 07:18 PM
@Geodav : I did your custom weapon tutorials with shock rifle. My second try is link gun. I want make machine gun . I think delete some codes :) ...I m trying. If I succes, than try reload part :) ...

Arixsus
03-04-2010, 03:08 AM
Hmph. Well I've attempted this myself being the novice I am to actual programming, and I was able to slap it together. I've ran into my problems which I cant seem to work around.


Weapon continues to fire/make sounds during reload time
auto-reload cutting the animation short


I dunno...

Tagotis
03-25-2010, 12:37 PM
Hmph. Well I've attempted this myself being the novice I am to actual programming, and I was able to slap it together. I've ran into my problems which I cant seem to work around.


Weapon continues to fire/make sounds during reload time
auto-reload cutting the animation short


I dunno...

Same problems here, spent some time checking UTWeapon and Weapon classes code but I was unable to find why is not working properly...

he3117
02-05-2011, 06:12 PM
my reloadable weapon class with recoil function. if any one interested:


class ReloadableWeapon extends UTWeapon
abstract;


var int BulletCount;// Holds the amount of bullets in our gun
var float ReLoadTime;//How much take to fill the gun
var bool bReloading;

var int RecoilAmount;//amount of recoil

/** Weapon animations for use while reload */
var(Animations) name WeaponReloadAnim;

/** Arm animations for use while reload */
var(Animations) name ArmReloadAnim;

/** sound for use while reload */
var SoundCue ReloadSound,EmptyMagSound;

/////////////////////////////////////////////////////
simulated function Reload()
{
// If we are reloading or out of ammo then dont do anything
if(bReloading || AmmoCount <= 0 || Default.BulletCount == BulletCount)
{
return;
}

// Not allow reloading
bReloading = true;

// report that we managed to go into reload state
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Reloading");

// Handle Animations
PlayWeaponAnimation(WeaponReloadAnim, ReloadTime);
PlayArmAnimation(ArmReloadAnim, ReloadTime);

PlaySound(ReloadSound, true);
MakeNoise( 0.1);

// Delay before we refill the ammo
setTimer(ReloadTime, false, 'RefillAmmo');
}

simulated function RefillAmmo()
{
// how many Bullet we need?
local int Bulletneed;
Bulletneed=Default.BulletCount-BulletCount;
// if we have enough or more ammo than the weapon needs
if(AmmoCount >= Bulletneed)
{
// Set our bullet count back to default value
BulletCount = Default.BulletCount;

// subtrack the ammo from our inventory
AddAmmo(-Bulletneed);
}
else
{
// set the bullets to how many we have left
BulletCount = AmmoCount;

// empty our inventory from bullets
AddAmmo(-AmmoCount);
}

// Allow reloading again
bReloading = false;
}
//////////////////////
/**
* Consumes some of the ammo
*/
function ConsumeAmmo( byte FireModeNum )
{
Recoil();
// Subtract the Ammo
BulletCount-=ShotCost[FireModeNum];
//super.ConsumeAmmo( FireModeNum );
//if(BulletCount<=0)
//{
// BulletCount=0;
// AddAmmo(-ShotCost[FireModeNum]*default.BulletCount);
//}
}
////////////////////
simulated function bool HasAmmo( byte FireModeNum, optional int Amount )
{
if(BulletCount > 0)
{
return super.HasAmmo( FireModeNum, Amount );
}
if(AIController(Instigator.Controller)!= none)
{
SetTimer(0.1,false,'Reload');
//return super.HasAmmo( FireModeNum, Amount );
}

PlaySound(EmptyMagSound);
MakeNoise(0.05);
return false;
}
////////////////////
/**
* returns true if this weapon has any ammo
*/
simulated function bool HasAnyAmmo()
{
if(BulletCount>0)
return true;
return super.HasAnyAmmo();
}

///////////////////////////
simulated function bool AllowSwitchTo(Weapon NewWeapon)
{
if(bReloading)
{
return false;
}

return super.AllowSwitchTo(NewWeapon);
}
/////////////////////////////////////
simulated function StartFire(byte FireModeNum)
{
if(bReloading)
{
return ;
}
super.StartFire(FireModeNum);
}
///////////////////////
simulated function Recoil()
{
local rotator ViewRotation;
local vector X,Y,Z;

////////////
if(RecoilAmount==0 || AIController(Instigator.Controller)!= none)
{
return;//dont use recoil for AI
}

GetAxes(Instigator.Rotation,X,Y,Z);
ViewRotation = Instigator.GetViewRotation();

//if (AmIZoomed == true)
//RecoilAmount = RecoilAmount * 0.75;
RecoilAmount = RandRange(RecoilAmount*0.75,RecoilAmount);

//if (AmIZoomed == false)
//RecoilAmount = RecoilAmount * 0.75;

ViewRotation.Pitch += RecoilAmount;
RecoilAmount = RecoilAmount * 0.25;
ViewRotation.Yaw += RecoilAmount;
UTPlayerController(Instigator.Controller).SetRotat ion(ViewRotation);
RecoilAmount = default.RecoilAmount;
}
/////////////////////////

defaultproperties
{
RecoilAmount=0
ReLoadTime=0.5
BulletCount=6
ShotCost(0)=1
ShotCost(1)=1
WeaponReloadAnim=WeaponReload
}



and put:


exec function RealReload()
{
local ReloadableWeapon rw;
rw=ReloadableWeapon(Pawn.Weapon);
if(rw != none)
{
rw.Reload();
}
}

in your playercontroller.

julianbraso
02-23-2011, 07:49 PM
he3117 it didn't work for me :S

he3117
02-24-2011, 07:30 AM
Why?what is the problem?

scottellison92
07-03-2011, 03:01 AM
Hasnt worked for me either, my problem is i cant reload
once i shoot 6 times thats it

g3n3fYp
11-09-2011, 03:02 AM
he3117, thanks for posting the code, I was looking one with recoil function with it as well. Going to test the code now. :o
Just to ask, so far has it work for anybody yet? ;)


EDIT: OK, I'm not sure if its working but this line:


// report that we managed to go into reload state
WorldInfo.Game.BroadcastHandler.Broadcast(self, "Reloading");

- it did appear on the screen. However, although it appears whether or not I press my keybind, I don't see any indication that its reloading the weapon...
- also there is a lag in the decrease in the ammo as shown on the screen even though I can still shoot like normal.

fyi, I'm using UDK's ShockRifle for the moment for test.

Please help and thanks in advance.:)