For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Replace starting weapon and IF syntax?

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Replace starting weapon and IF syntax?

Post by GreatEmerald »

I have 2 questions here:
1. How do you replace the starting weapon with another one? When using a simple replace function, it just deletes the weapon you are trying to replace and won't add a new one. That's the code I use:

Code: Select all

          if ( string(Other.Class) ~= "XWeapons.AssaultRifle" )
          {
            ReplaceWith( Other, "XMPWeapons.XMPGrenadeLauncherLight" );
            return false;
          }
2. How come the compiler says that there's a missing ")" character in this line? Maybe the syntax is wrong or something? I'm trying to check if the string "aWMakerOpt" is equal to "Both" or "Lightning Gun":

Code: Select all

if ( ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Both") ) OR ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Lightning Gun") )){
User avatar
Buster
Global Moderator
Posts: 1616
Joined: Wed Jun 08, 2005 3:02 am

Re: Replace starting weapon and IF syntax?

Post by Buster »

The NBSP-Info script (which I extracted from the NBSpecials2) does just that. I lets you drop an actor into your map, and allows you to setup what weapon (or non) that a player spawns into a map with.

http://www.celticwarriors.net/Downloads/Mods/Various/nbsp-info.zip

I believe it's also here at OldUnreal too. Maybe that a look at it, and see how it works. I've used it several times, and it works great. You can even setup custom weapons if you want.

:)
Gatherstone - Unreal by Design
https://gatherstone.oldunreal.com

OK - he falls
Keep it Unreal !!
:-)_~
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Ahhh, it's an .U file... I hate extracting those... Can I get an .UC file out of that?
User avatar
Buster
Global Moderator
Posts: 1616
Joined: Wed Jun 08, 2005 3:02 am

Re: Replace starting weapon and IF syntax?

Post by Buster »

Yup. Just export it.
Gatherstone - Unreal by Design
https://gatherstone.oldunreal.com

OK - he falls
Keep it Unreal !!
:-)_~
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Ummmmm... How? Is there an option to export a single U file as an UC?
User avatar
Bane
OldUnreal Member
Posts: 493
Joined: Sun Mar 03, 2002 6:32 pm

Re: Replace starting weapon and IF syntax?

Post by Bane »

2. How come the compiler says that there's a missing ")" character in this line? Maybe the syntax is wrong or something? I'm trying to check if the string "aWMakerOpt" is equal to "Both" or "Lightning Gun":

Code: Select all

if ( ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Both") ) OR ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Lightning Gun") )){
What game are you using? It doesn't look like U1 or UT. If it isn't then I don't know how accurate the following will be...
I see you wrote out "OR"; Typically a logical or is done with "||". The parenthesis match up fine, so that's the only problem I can see. Of course, if later versions of UScript do allow logical OR to be done with the keyword "OR" then I have absolutely no idea what the problem is there.
Author of Hide and Seek mod, and the NALIBALL mod

Hide and Seek can be downloaded from:
http://HideNSeek.5u.com
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Hmm, thanks! That's really the issue. Yes, that's UScript 2, 2004 build, but a function like that should be in v1 just as well. And you're all a lot more active than the UScript v2 community :)

Hmm, now I'm trying to make a GUI drop-down box, and everything works, just that somehow it doesn't like reading variables correctly...

So I've added this line at the top:

Code: Select all

var() config string WMakerOpt;
Means that the String WMakerOpt is configureable. Is it OK to use strings for drop-down lists?
Now after that I've added this line, it's UT2004 specific:

Code: Select all

    PlayInfo.AddSetting(default.RulesGroup, "WMakerOpt", default.GUIDisplayText[5], 0,  6, "Select", "V_BOTH;Both;V_SNIPER;Classic Sniper Rifle;V_LIGHTNING;Lightning Gun;V_NONE;None");
The things after "Select" means: before the first ";" means what property should the string WMakerOpt get, and after it, what the drop-down list will add to the selection, i.e. text. That goes in pairs.
So now, I use these lines to determine what was selected:

Code: Select all

    if ( ( (MutXMPWeaps(Other).WMakerOpt) ~= ("V_BOTH") ) || ( (MutXMPWeaps(Other).WMakerOpt) ~= ("V_LIGHTNING") )){ //Lightning to WMaker
          if ( string( xWeaponBase(Other).WeaponType ) ~= "XWeapons.SniperRifle" )
          {
            xWeaponBase(Other).WeaponType = class'XMPWeapons.XMPSniperRifle';
            return false;
          }
        }
        if ( ((MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH")) || ((MutXMPWeaps(Other).WMakerOpt) == ("V_SNIPER"))){ //CSniper to WMaker
          if ( string( xWeaponBase(Other).WeaponType ) ~= "UTClassic.ClassicSniperRifle" )
          {
            xWeaponBase(Other).WeaponType = class'XMPWeapons.XMPSniperRifle';
            return false;
          }
        }
You can see that the first line has a ~= symbol, and the second IF has the == symbol. Strangely enough, whatever I select, the IF statement with ~= will always get to TRUE, and the one with == will always get to FALSE. How come? How to make it so it only does the code if the value of WMakerOpt is V_BOTH, V_SNIPER or V_LIGHTNING?
User avatar
Chaos13
OldUnreal Member
Posts: 951
Joined: Sat Feb 16, 2008 10:24 am

Re: Replace starting weapon and IF syntax?

Post by Chaos13 »

2. How come the compiler says that there's a missing ")" character in this line? Maybe the syntax is wrong or something? I'm trying to check if the string "aWMakerOpt" is equal to "Both" or "Lightning Gun":

Code: Select all

if ( ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Both") ) OR ( (MutXMPWeaps(Other).aWMakerOpt) ~= ("Lightning Gun") )){
What game are you using? It doesn't look like U1 or UT. If it isn't then I don't know how accurate the following will be...
I see you wrote out "OR"; Typically a logical or is done with "||". The parenthesis match up fine, so that's the only problem I can see. Of course, if later versions of UScript do allow logical OR to be done with the keyword "OR" then I have absolutely no idea what the problem is there.
[glow=yellow,2,300]XMP[/glow]? Sounds like Unreal 2 XMP.
Skydev = Chaos13 = Dimension4
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Nope :P UTXMP. So that's UT2004.
Now I'm confused, changed all == to ~= and now all the time it outputs false :(
User avatar
Chaos13
OldUnreal Member
Posts: 951
Joined: Sat Feb 16, 2008 10:24 am

Re: Replace starting weapon and IF syntax?

Post by Chaos13 »

I noticed that bug in Unreal1 too. Sometimes ~= fails even if it shouldnt. Try using Caps(...)==Caps(...)
Last edited by Chaos13 on Tue May 20, 2008 7:15 pm, edited 1 time in total.
Skydev = Chaos13 = Dimension4
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

No luck... But the log file says:

Warning: MutXMPWeaps DM-CBP2-Kerosene.MutXMPWeaps (Function XMPWeapons.MutXMPWeaps.CheckReplacement:07ED) Accessed None 'Other'

What could that mean? Current MutXMPWeaps looks like this:

Code: Select all

        if ( ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH") ) || ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_LIGHTNING") )){ //Lightning to WMaker
        log("UTXMP WEAPONS: Attempting to replace Lightning with Widowmaker");
          if ( string( xWeaponBase(Other).WeaponType ) ~= "XWeapons.SniperRifle" )
          {
            log("UTXMP WEAPONS: Found a weapon base with a Lightning");
            xWeaponBase(Other).WeaponType = class'XMPWeapons.XMPSniperRifle';
            return false;
          }
        }
        if ( (Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH")) || (Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_SNIPER"))){ //CSniper to WMaker
        log("UTXMP WEAPONS: Attempting to replace Sniper with Widowmaker");
          if ( string( xWeaponBase(Other).WeaponType ) ~= "UTClassic.ClassicSniperRifle" )
          {
            log("UTXMP WEAPONS: Found a weapon base with a Sniper");
            xWeaponBase(Other).WeaponType = class'XMPWeapons.XMPSniperRifle';
            return false;
          }
        }
And is there any diffrence between these two types of writing:

Code: Select all

if ( ( (MutXMPWeaps(Other).WMakerOpt) ~= ("V_BOTH") ) || ( (MutXMPWeaps(Other).WMakerOpt) ~= ("V_LIGHTNING") )){
   if ( SniperRiflePickup(Other) != None )
            ReplaceWith( Other, "XMPWeapons.XMPSniperRiflePickup");
       if ( SniperAmmoPickup(Other) != None )
            ReplaceWith( Other, "XMPWeapons.XMPSniperRifleAmmoPickup");
      }

Code: Select all

        if ( ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH") ) || ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_LIGHTNING") )){
        log("UTXMP WEAPONS: Attempting to replace Lightning pickup with Widowmaker");
          if ( string(Other.Class) ~= "XWeapons.SniperRiflePickup" )
          {
            log("UTXMP WEAPONS: Found a Lightning Pickup");
            ReplaceWith( Other, "XMPWeapons.XMPSniperRiflePickup" );
            return false;
          }
        }

        if ( ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH") ) || ( Caps(MutXMPWeaps(Other).WMakerOpt) == ("V_LIGHTNING") )){
          log("UTXMP WEAPONS: Attempting to replace Lightning Ammo with Widowmaker Ammo");
          if ( string(Other.Class) ~= "XWeapons.SniperAmmoPickup" )
          {
            log("UTXMP WEAPONS: Found Lightning Ammo");
            ReplaceWith( Other, "XMPWeapons.XMPSniperRifleAmmoPickup" );
            return false;
          }
        }
Last edited by GreatEmerald on Wed May 21, 2008 10:02 am, edited 1 time in total.
User avatar
Chaos13
OldUnreal Member
Posts: 951
Joined: Sat Feb 16, 2008 10:24 am

Re: Replace starting weapon and IF syntax?

Post by Chaos13 »

Warning: MutXMPWeaps DM-CBP2-Kerosene.MutXMPWeaps (Function XMPWeapons.MutXMPWeaps.CheckReplacement:07ED) Accessed None 'Other'
Other have been Destroyed\NULLified before the actual handling? :P

Oh and i see your code is damn unstable, it would cause 1000+1 accessed nones on non MutXPWeaps actors? :P
Skydev = Chaos13 = Dimension4
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Hmm, how and by what? Well, there are quite a lot of these messages there. If you want the full log of that:

Note that 3/4 of the log has been deleted due to duplicated lines, added at some parts, but didn't bother everywhere... So yeah :) Hey, why is my class XMp.XMPGunner? Huh..
And the full code of MutXMPWeaps:
User avatar
.:..:
OldUnreal Member
Posts: 1637
Joined: Tue Aug 16, 2005 4:35 am

Re: Replace starting weapon and IF syntax?

Post by .:..: »

I noticed that bug in Unreal1 too. Sometimes ~= fails even if it shouldnt. Try using Caps(...)==Caps(...)
I never had this problem, gimme an example that fails.
1823223D2A33224B0 wrote:...and now im stuck trying to fix everything you broke for the next 227 release xD :P
(ಠ_ಠ)
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

OK, I'm totally confused.

Code: Select all

        if ( ( (MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH") ) || ( (MutXMPWeaps(Other).WMakerOpt) == ("V_LIGHTNING") )){
        log("UTXMP WEAPONS: Attempting to replace Lightning pickup with Widowmaker");
          if ( string(Other.Class) ~= "XWeapons.SniperRiflePickup" )
          {
            log("UTXMP WEAPONS: Found a Lightning Pickup");
            ReplaceWith( Other, "XMPWeapons.XMPSniperRiflePickup" );
            return false;
          }
        }
That code doesn't work.

Code: Select all

        if ( ( (MutXMPWeaps(Other).WMakerOpt) == ("V_BOTH") ) || ( (MutXMPWeaps(Other).WMakerOpt) == ("V_SNIPER") )){
        log("UTXMP WEAPONS: Attempting to replace Sniper pickup with Widowmaker");
          if ( string(Other.Class) ~= "UTClassic.ClassicSniperRiflePickup" )
          {
            log("UTXMP WEAPONS: Found a Sniper pickup");
            ReplaceWith( Other, "XMPWeapons.XMPSniperRiflePickup" );
            return false;
          }
        }
This code works. Why?
User avatar
Bane
OldUnreal Member
Posts: 493
Joined: Sun Mar 03, 2002 6:32 pm

Re: Replace starting weapon and IF syntax?

Post by Bane »

Just wondering, but why do you keep doing string comparisons to check other's class?
Author of Hide and Seek mod, and the NALIBALL mod

Hide and Seek can be downloaded from:
http://HideNSeek.5u.com
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

How else do you do that?
User avatar
Bane
OldUnreal Member
Posts: 493
Joined: Sun Mar 03, 2002 6:32 pm

Re: Replace starting weapon and IF syntax?

Post by Bane »

You should be able to just do

Code: Select all

 if (other.class == class'Example.SomeClass')
     ...;
I don't know if the UScript dropped that for your version, but I seriously doubt it. You can also check subclasses by using a function with the classes instead of string comparison. ClassIsChildOf in the original unreal is the function name IIRC. Likely the same for your version of UScript.
Author of Hide and Seek mod, and the NALIBALL mod

Hide and Seek can be downloaded from:
http://HideNSeek.5u.com
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Oh, you're talking about this line, right?:

Code: Select all

if ( string(Other.Class) ~= "XWeapons.SniperRiflePickup" )
Well it usually works, this code usually works too:

Code: Select all

  if ( SniperRiflePickup(Other) != None )
            ReplaceWith( Other, "XMPWeapons.XMPSniperRiflePickup");
And you're saying this should work too?

Code: Select all

if (other.class == Class'XWeapons.SniperRiflePickup') ReplaceWith (Class'XMPWeapons.XMPSniperRiflePickup');
Or something else?
User avatar
Bane
OldUnreal Member
Posts: 493
Joined: Sun Mar 03, 2002 6:32 pm

Re: Replace starting weapon and IF syntax?

Post by Bane »

Yes
Author of Hide and Seek mod, and the NALIBALL mod

Hide and Seek can be downloaded from:
http://HideNSeek.5u.com
User avatar
GreatEmerald
OldUnreal Member
Posts: 5347
Joined: Mon May 21, 2007 2:30 pm

Re: Replace starting weapon and IF syntax?

Post by GreatEmerald »

Hmm, so I now have 3 replace types that should work and 3 ways to check the value... 9 recompiles needed to see if it really works or doesn't work...

Now another question: how do you get a variable from another class and use it to define a default property? For example, now I want to make a weapon damage dampening option, so the user configures the variable (DamScaling) in this XMPWeapons.MutXMPWeaps class and I want that another class, for example XMPWeapons.XMPShotgunProj (projectile) would get the value of the variable the user set before and then multiply the usual damage with the scaling, and then apply the new variable to the projectile's default properties. All variables are of type Float.

Return to “UScript Board”