STEAM GROUP
ScrN Balance Fans ScrN-B
STEAM GROUP
ScrN Balance Fans ScrN-B
53
IN-GAME
336
ONLINE
Founded
December 14, 2012
Language
English
Tar May 19, 2023 @ 7:11pm
I need some help with glowsticks
Hey friends, I downloaded some glow sticks, and I want them to be destroyed from inventory when the ammo is 0. But it is not destroyed. Here is the code I used for it.

class GreenGlowstick extends KFWeapon; var bool bBeingDestroyed; // We've thrown the last bomb and this explosive is about to be destroyed simulated function Destroyed() { if( Role < ROLE_Authority ) { // Hack to switch to another weapon on the client when we throw the last pipe bomb out if( Instigator != none && Instigator.Controller != none ) { bBeingDestroyed = true; // THIS DOES NOT WORK Instigator.SwitchToLastWeapon(); //THIS WORKS 100% FINE } } super.Destroyed(); } ...


class GreenGlowstickFire extends KFShotgunFire; #exec OBJ LOAD FILE=KF_AxeSnd.uax function InitEffects(); function Timer() { Weapon.ConsumeAmmo(ThisModeNum, Load); DoFireEffect(); Weapon.PlaySound(Sound'KF_AxeSnd.Axe_Fire',SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false); if( Weapon.ammoAmount(0) <= 0 && Instigator != none && Instigator.Controller != none ) { Weapon.Destroy(); //THIS DOES NOT WORK Instigator.Controller.ClientSwitchToBestWeapon(); //THIS WORKS } } simulated function bool AllowFire() { return (Weapon.AmmoAmount(ThisModeNum) >= AmmoPerFire); } ...

I added these functions but they don't work and I don't know why. On another weapon, throwing knive, it does work, but here, it doesn't. Please help. :(
Last edited by Tar; May 19, 2023 @ 7:14pm
< >
Showing 1-2 of 2 comments
[ScrN]PooSH May 20, 2023 @ 3:34am 
I guess the problem is due to network replication. Weapons must be destroyed server-side. Trying to do so on the client leads to undefined behavior.

Pro-tip: be extremely cautious with WeaponFire classes. WeaponFire is an object (not an actor). Therefore, it CANNOT be replicated. However, it is a native object, where some "magic" happens in C++ code that provides network syncing. However, it is not the same network replication in terms of UnrealScript.

What does that mean? WeaponFire object on the server side and the "same" object on the client are two different objects - they are not simulated. Only actors can be simulated, which WeapnFire isn't. Hence, the keyword "simulated" means nothing inside WeaponFire, and the "replication" statement does not work. To distinguish between the server and the client, check the weapon's role:
if (Weapon.Role == ROLE_Authority) { // this code executes on the server side (or solo) } else { // this code executes on the client side }

I would move the entire "destroy" code into the Weapon class - there is less chance to shoot yourself in the foot. For instance, you can override ConsumeAmmo() to do the check there:
simulated function bool ConsumeAmmo(int Mode, float Load, optional bool bAmountNeededIsMax) { if (!super.ConsumeAmmo(Mode, Load, bAmountNeededIsMax)) { return false; } if (Role == ROLE_Authority && !bDeleteMe && AmmoAmount(0) <= 0 ) { Destroy(); } return true; }
Last edited by [ScrN]PooSH; May 20, 2023 @ 3:35am
Tar May 20, 2023 @ 4:28am 
This works with only the consume ammo function in the weapon class. But, the weapon has 3 glowsticks ammo max. I shoot 2, and when I shoot the third, it is GONE, it is not placed on the map, just gone. So the weapon is destroyed when I consume 2/3 sticks?

I want to consume 3/3 sticks, and then destroyed. How can I do this? I tried with this, and it works, but I don't think this is correct.

if (Role == ROLE_Authority && !bDeleteMe && AmmoAmount(0) <= -1
Last edited by Tar; May 20, 2023 @ 4:30am
< >
Showing 1-2 of 2 comments
Per page: 1530 50