Basically, I'm trying to create a custom UI using Unreal's UI Editor. The player would basically push a button in the UI editor, which would activate an event in a script code to give a weapon to a player. I really don't know where to start. Any thoughts?
Announcement
Collapse
No announcement yet.
UI Kismet to Unreal Script?
Collapse
X
-
All right, did a little research and testing. I'm attempting to change the pawn class of a player once in the game. When they push a UI button, a kismet sequence gets activated which changes that player's class. So, I'm creating a new UISequence Action. Here's some of the script I've got going on right now, I'm not sure why it's not working.
//Title: SB_UISwitchClass.uc
//Author: Shaun Brahmsteadt II
//Date: 1/30/2010
//Description: This changes the class of the player to whatever pawn. This is a UI Sequence Action.
class SB_UISwitchClass extends UIAction;
event Activated()
{
local SeqVar_Object ObjVar;
local UTPawn P;
foreach LinkedVariables(class'SeqVar_Object',ObjVar,"Targe t")
{
P = SB_SniperPawn;
}
Super.ModifyPlayer(SB_SniperPawn);
}
DefaultProperties
{
ObjName = "Change Pawn Class"
ObjCategory = "Player"
bAutoTargetOwner = True
}
//Title: SB_SniperPawn.uc
//Author: Shaun Brahmsteadt II
//Date: 1/30/2010
//Description: This modifies the base pawn to the sniper pawn.
class SB_SniperPawn extends UTPawn;
defaultproperties
{
GroundSpeed = 1000.00
}
-
All right, I took yet another redirection. This is just to change the deault properties of the UTPawn. This will work fine as a regular kismet action, but when brought in the UI kismet, it does not seem to work. I think I need some way of updating the player after clicking the button. Anyways, here's the script, what's wrong with it?
//Title: SB_UISwitchClass.uc
//Author: Shaun Brahmsteadt II
//Date: 1/30/2010
//Description: This changes the class of the player to whatever pawn. This is a UI Sequence Action.
class SB_UISwitchClass extends UIAction;
var() float NewSpeed;
event Activated()
{
local SeqVar_Object ObjVar;
local UTPawn P;
foreach LinkedVariables(class'SeqVar_Object',ObjVar,"Targe t")
{
P = UTPawn( ObjVar.GetObjectValue() );
P.GroundSpeed = NewSpeed;
P.bCanDoubleJump = False;
}
}
DefaultProperties
{
ObjName = "Change Pawn Class"
ObjCategory = "Player"
VariableLinks(1)=(ExpectedType=class'SeqVar_Float' ,LinkDesc="New Speed",PropertyName=NewSpeed)
bAutoTargetOwner = True
NewSpeed = 1000.0
}
Comment
-
You could also create your own kismet action (or script) that uses the following function that I have used to add the weapon.
Code:static function GiveWeapon(UTPawn P, class<Weapon> WeaponClass) { Local Weapon Weap; if (P == None) { return; } Weap = Weapon(P.FindInventoryType(WeaponClass)); if (Weap != None) { return; } P.CreateInventory(WeaponClass); }
Comment
-
Sorry I haven't been on in a while, but I appreciate the help Grosie. Your script really helped, I finally got it to work. Here's the example of the script. Basically, in UI, if the string is called Sniper, it will assign properties to the player and give them my own custom sniper. Is there a way for it to delete the starting inventory of the players when starting out?
//Title: SB_UISwitchClass.uc
//Author: Shaun Brahmsteadt II
//Date: 1/30/2010
//Description: This changes the class of the player to whatever pawn. This is a UI Sequence Action.
class SB_UISwitchClass extends UIAction;
var() string NewClass;
event Activated()
{
local SeqVar_Object ObjVar;
local UTPawn P;
local class<Weapon> WeapSniper;
local string Sniper;
Sniper = "Sniper";
foreach LinkedVariables(class'SeqVar_Object',ObjVar,"Targe t")
{
P = UTPawn( ObjVar.GetObjectValue() );
P.MaxMultiJump = 0;
P.DodgeSpeed = 0;
P.DodgeSpeedZ = 0;
P.WaterSpeed = 200;
P.AirSpeed = 350;
P.JumpZ = 200;
if (NewClass == Sniper)
{
P.GroundSpeed = 280.0;
WeapSniper = class'SB_UISwitchClass.SB_SuperSniper';
P.CreateInventory(WeapSniper);
}
}
}
DefaultProperties
{
ObjName = "Change Pawn Class"
ObjCategory = "Player"
VariableLinks(1)=(ExpectedType=class'SeqVar_String ',LinkDesc="Type of Class",PropertyName=NewClass)
bAutoTargetOwner = True
}
Comment
-
This function (that is similar to that above) should destroy all weapons for a given UTPawn:
Code:static function DestroyAllWeapons(UTPawn P) { local Inventory inv; local Weapon toDestroy; if (P == None) { return; } inv = P.InvManager.InventoryChain; while (inv != None) { if ((Weapon(inv) != None)) { toDestroy = Weapon(inv); toDestroy.ClientWeaponThrown(); toDestroy.StopFire(0); toDestroy.StopFire(1); toDestroy.Destroy(); C.SwitchToBestWeapon(); C.ClientSwitchToBestWeapon(); } inv = inv.Inventory; } }
Comment
Comment