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!!!

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:
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:
Ord1:
Ord2:
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.

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.