Page 1 of 1

A weapon that dispenses AI? [Solved]

Posted: Thu Apr 17, 2008 10:59 pm
by woner11
I'm not sure how many of you have played negative zone city or whatever, but I noticed a weapon which puzzled me how to make. The wampa on there had a weapon which when pressed made four unplayer controlled wampas spawn around him and I was wondering how it was done. Thanks in advance.

Off topic: 10,000th topic!!! :D :runaway: :lol:

Re: A question...

Posted: Thu Apr 17, 2008 11:18 pm
by Maveritchell
What you do is insert coding similar to this:

Code: Select all

TroopSpawnerWeapon = "rep_item_powerup_cura"

   OnCharacterDispensePowerup(
      function(character,powerup)
         if GetEntityClass(powerup) == GetEntityClassPtr(TroopSpawnerWeapon) then
            local SupportTeam = 3 --Team the new spawned character is in (change this)
            local teamSize = GetTeamSize(SupportTeam)
            for i = 0, teamSize-1 do
               local characterIndex = GetTeamMember(SupportTeam, i)
               local charUnit = GetCharacterUnit(characterIndex)
               if not charUnit then
                  local destination = GetEntityMatrix(GetCharacterUnit(character))
                  SpawnCharacter(characterIndex,destination)
               end
            end
         end
      end
	   --User team (change this)
      )
Into the ScriptPostLoad of your .lua. Then add a third team with the to-be-spawned unit, like this:

Code: Select all

    SetTeamName (3, "summon")
    AddUnitClass (3, "rep_inf_ep2rifleman", 3,4)
    SetClassProperty("rep_inf_ep2rifleman", "AddHealth", -100)
    SetUnitCount (3, 4)
    AddAIGoal(3, "Deathmatch", 100)
    SetTeamAsFriend(ATT,3)
    SetTeamAsFriend(3,ATT)
    SetTeamAsEnemy(DEF,3)
    SetTeamAsEnemy(3,DEF)
    SetTeamName(3, ATT)
Then create a null dispenser weapon (note that the weapon is called rep_weap_summon, but it's the powerup that it dispenses - rep_item_powerup_cura - that triggers the actual code) - it does nothing, it's just used to trigger the .lua code above.
rep_weap_summon.odf wrote:[WeaponClass]
ClassLabel = "dispenser"

[Properties]
//IconTexture = "HUD_powerup_icon"

//MuzzleFlash = "small_muzzle_flash"
//Discharge = "small_smoke_effect"
HUDTag = ""

GeometryName = ""

RoundsPerClip = "1"
ReloadTime = "1.0"
LockOnRange = "80.0"
LockTime = "0.4"

HeatPerShot = "0.25" // only allow player to fire every 5 seconds
HeatRecoverRate = "0.033"
HeatThreshold = "0.5"
HideOnFire = 0

InstantPlayFireAnim = 1
OffhandWeapon = 1

TrackingSound = ""

WEAPONSECTION = 1

ModeTexture = "HUD_weap_health"
ReticuleTexture = "reticule_00"
OrdnanceName = "rep_item_powerup_cura"

ShotDelay = "0.0"
MaxItems = "4.0"

AutoAimSize = "1.0"

SalvoCount = "1"
SalvoDelay = "0.0"
InitialSalvoDelay = "0.5"

MinStrength = "0.3"
MaxStrength = "0.4"
MaxPressedTime = "0.0"

FireSound = "com_weap_throw"
FireEmptySound = "com_weap_inf_ammo_empty"
FireLoopSound = ""
ReloadSound = "com_weap_inf_equip_sm"
ChargeSound = ""
ChangeModeSound = "com_weap_inf_equip_sm"
WeaponChangeSound = "com_weap_inf_equip_sm"
JumpSound = "com_weap_inf_pistol_mvt_jump"
LandSound = "com_weap_inf_pistol_mvt_land"
RollSound = "com_weap_inf_pistol_mvt_roll"
//ProneSound = "com_weap_inf_pistol_mvt_lie"
SquatSound = "com_weap_inf_pistol_mvt_squat"
//StandSound = "com_weap_inf_pistol_mvt_getup"
rep_item_powerup_cura wrote:[GameObjectClass]
ClassLabel = "powerupitem"
GeometryName = "ffx_weap_inf_grenadethermal.msh"
GeometryScale = 0.15

[Properties]
GeometryName = "ffx_weap_inf_grenadethermal"
SoldierHealth = 0
SoldierAmmo = 0
Lifespan = 0.1

Powerupsound = "com_weap_powerup_pickup defer"

Velocity = "0.0"
Gravity = "1.0"
Rebound = "0.0"
Friction = "1.0"

//CollisionOtherSound = "com_weap_mine_land defer"
And voila:
Image

It's not difficult to do, if you can get around the several things you need to do to make it work. It's discussed at great length in this thread:
http://www.gametoast.com/forums/viewtop ... =27&t=6916

Re: A question...

Posted: Fri Apr 18, 2008 9:35 pm
by woner11
Thanks, I just have one more question. How do I make a weapon that heals the users freinds as it hurts the enemy. I tried, and here are my odfs.

The original odf:
Hidden/Spoiler:
[WeaponClass]

ClassLabel = "cannon"

[Properties]
HUDTag = "hud_force_push"
GeometryName = ""
HighResGeometry = ""

RoundsPerClip = "0"
ReloadTime = "0.3"
HeatRecoverRate = "0.2"
HeatThreshold = "0.0"

OrdnanceName = "sit_weap_inf_force_push_ord"

TriggerSingle = "1"
ShotDelay = "0.5"
HeatPerShot = "0.0"
MaxPressedTime = "0.0"

LockOnRange = "64.0"
LockTime = "0.0"
AutoAimSize = "2.0"

SalvoCount = "1"
ShotsPerSalvo = "1"
SalvoDelay = "0.0"
SalvoTime = "0.0"
InitialSalvoDelay = "0.5" // must have one or no animation - Mike Z

EnergyDrain = 70.0
InstantPlayFireAnim = 1
OffhandWeapon = 1

SecondaryOrdnanceName = "sit_weap_inf_force_pull_ord"
SecondaryOrdnancePeriod = 1


TargetEnemy = "1"
TargetNeutral = "0"
TargetFriendly = "1"

TargetPerson = "1"
TargetAnimal = "1"
TargetDroid = "1"
TargetVehicle = "0"
TargetBuilding = "0"

AITargetPerson = "1"
AITargetAnimal = "1"
AITargetDroid = "1"
AITargetVehicle = "0"
AITargetBuilding = "0"

//SOUND
FireSound = "force_push_fire"
//ReloadSound = ""
WeaponChangeSound = ""
ChangeModeSound = ""
FireEmptySound = ""
ChargeSound = ""
ChargeSoundPitch = "0.05"
OverheatSound = ""
OverheatSoundPitch = "0.5"
OverheatStopSound = ""
Ord1:
Hidden/Spoiler:
[OrdnanceClass]

ClassLabel = "emitterordnance"

[Properties]
Explosion = "sit_weap_inf_force_push_exp"

ConeLength = "40"
ConeAngle = "150"
FirstRadius = "0.0"
MaxTargets = "10" // Max number of targets to hit. Chaining is off so the damage will be split between the number of targets
NoChaining = "0" // No chaining - all bolts coming from the attacker

//OrdnanceSound = "com_weap_launcher_energy_dumbfire"

Damage = "100" // This is the min damage. Even if the initial damage is split between the number of targets, it will never go below this number for each target
MaxDamage = "550" // This is the max damage
JumpDeduction = "0" // No jump deduction. This is for chaining only
DamageThreshold = "0" // Always do damage (no threshold)
MaxJumpDistance = "0" // No max jump distance because the chaining is off

TargetEnemy = "1"
TargetNeutral = "0"
TargetFriendly = "0"

VehicleScale = "0.0"
ShieldScale = "0.3"
PersonScale = "3.0"
AnimalScale = "100.0"
DroidScale = "0.01"
BuildingScale = "0.0"

Push = "20.2"

AffectFriends = "0"

//LightningEffect = ""
//LightningEffectScale = "0.25"
//NoTargetLightningEffectCount = "5" // The number of ligthning effects to display when the ordinance has no targets to hit
//NoTargetLightningEffectRandomSpread = "0.4" // The random rotation spread the ligthning effects does when the ordinance has no targets to hit
Ord2:
Hidden/Spoiler:
[OrdnanceClass]

ClassLabel = "emitterordnance"

[Properties]
Explosion = "sit_weap_inf_force_push_exp"

ConeLength = "40"
ConeAngle = "150"
FirstRadius = "0.0"
MaxTargets = "1" // Max number of targets to hit. Chaining is off so the damage will be split between the number of targets
NoChaining = "0" // No chaining - all bolts coming from the attacker

OrdnanceSound = "com_weap_launcher_energy_dumbfire"

Damage = "-100" // This is the min damage. Even if the initial damage is split between the number of targets, it will never go below this number for each target
MaxDamage = "-550" // This is the max damage
JumpDeduction = "0" // No jump deduction. This is for chaining only
DamageThreshold = "0" // Always do damage (no threshold)
MaxJumpDistance = "0" // No max jump distance because the chaining is off

TargetEnemy = "0"
TargetNeutral = "0"
TargetFriendly = "1"


VehicleScale = "0.0"
ShieldScale = "1.0"
PersonScale = "1.0"
AnimalScale = "1.0"
DroidScale = "1.0"
BuildingScale = "0.0"

Push = "-70.0"

AffectFriends = "1"

//LightningEffect = ""
//LightningEffectScale = "0.25"
//NoTargetLightningEffectCount = "0" // The number of ligthning effects to display when the ordinance has no targets to hit
//NoTargetLightningEffectRandomSpread = "0.4" // The random rotation spread the ligthning effects does when the ordinance has no targets to hit

Re: A question...

Posted: Fri Apr 18, 2008 11:01 pm
by MasterSaitek009

Code: Select all

OnObjectDamage(
         function(object, damager)
             if damager == nil then return end
             if GetCharacterTeam(damager) == DEF then
                 if GetCharacterClass(damager) == 2 then
                     local unit = GetCharacterUnit(damager)
                     if unit == nil then return end
                     SetProperty(unit, "CurHealth", GetObjectHealth(unit) + 1)
                 end
             end
         end
            )
http://www.gametoast.com/forums/viewtop ... 01#p204201

Something like that? Except you would need to change the team condition to a GetLastHitWeapon() condition.

Re: A question...

Posted: Fri Apr 18, 2008 11:12 pm
by woner11
Does this still do damage to the target, because if so, then its perfect!

Re: A question...

Posted: Fri Apr 18, 2008 11:33 pm
by MasterSaitek009
You set the damage in your ODF.
Make sure to credit Zerted for it. He really did most of it. :wink:

Re: A question...

Posted: Fri Apr 18, 2008 11:53 pm
by woner11
I'll give it a try and see how it all works out. Just a few quick questions about it as I am not good with most of this lua stuff other than characters, mainly because I hardly ever do it.
What does the 2 part mean?
MasterSaitek009 wrote: if GetCharacterClass(damager) == 2 then
Whre in the whole code do I insert my character name? Lets say its cis_hero_darth and he is the sniper does it work like this?

Code: Select all

[quote="MasterSaitek009"]OnObjectDamage(
         function(object, damager)
             if damager == nil then return end
             if GetCharacterTeam(cis_hero_darth) == DEF then
                 if GetCharacterClass(cis_hero_darth) == 2 then
                     local unit = GetCharacterUnit(cis_hero_darth)
                     if unit == nil then return end
                     SetProperty(unit, "CurHealth", GetObjectHealth(unit) + 1)
                 end
             end
         end
            )[/quote]

Re: A question...

Posted: Sat Apr 19, 2008 12:35 am
by MasterSaitek009

Code: Select all

OnObjectDamage(
         function(object, damager)
             if damager == nil then return end
             if GetCharacterTeam(damager) == DEF then
                 if GetCharacterClass(damager) == 2 then
                     local unit = GetCharacterUnit(damager)
                     if unit == nil then return end
                     SetProperty(unit, "CurHealth", GetObjectHealth(unit) + 1)
                 end
             end
         end
            )
The function OnObjectDamage receives the damaging unit which it contains in the variable damager.

Code: Select all

if GetCharacterTeam(damager) == DEF then
This check if the damager is on the DEF team. Change it to the team that your unit is on.

Code: Select all

if GetCharacterClass(damager) == 2 then
This checks the index of the damagers class. The number should be how far down(starting at 1) on the team setup the unit is.
I had this setup for a unit with only one weapon, so I didn't have to check for the last hit weapon. You'll have to.
Try this:

Code: Select all

OnObjectDamage(
         function(object, damager)
             if damager == nil then return end
             if GetObjectLastHitWeaponClass(object) ~= "YOUR_WEAPON_NAME" then return end   -- ~= means not equal to
                     local unit = GetCharacterUnit(damager)
                     if unit == nil then return end
                     SetProperty(unit, "CurHealth", GetObjectHealth(unit) + 1) --adjust + 1 to your preference
          end
            )

Re: A question...

Posted: Sat Apr 19, 2008 12:57 am
by woner11
Okay, I think I got it, I'll try it.