This is a tutorial showing how to make a very simple weapon, that when fired, teleports your entire team to your position. For example, you're all alone and low on health trying to capture back your cp
Hidden/Spoiler:
call for backup!
Hidden/Spoiler:
I won't be laying out how this works like in my other tutorials, I'm just going to show you step by step how to do it.
First go into your mod folder-->sides-->common-->odf. Find the file "com_weap_inf_powerup_dispenser" Copy it and rename it to "com_weap_inf_rally". Now open it up and select all the code and delete it. Then copy the code from below and paste it in.
Close and save that file. Now go into the folder your mod folder-->common-->odfs, and find the file "com_item_powerup_dual". Copy it, go to your mod folder-->sides-->common-->odf and paste it. Open it up, delete all the text in it, copy the text below and paste it into it:
This "item" being dropped is what will trigger the teleport, and is very important. Give one of your units the "com_weap_inf_rally" weapon as a secondary weapon, and move onto the next step. Now open your map's script file, any script that has the unit you gave the weapon to. In the function Scriptpostload(), right above the 'end' paste the following code.
--checks for our special powerup every time a powerup is dropped
if GetEntityClass(powerup) == GetEntityClassPtr(TeleportWeapon) then
--this sees which team the person who dropped the powerup was on, that way you won't rally the enemy team to your pos!
if GetCharacterTeam(character) == 1 then
--get the team's size
local size = GetTeamSize( 1 )
--for each team member,
local m = 0
for m = 0, size-1 do
--get a team member's unit
local member = GetTeamMember(1, m)
--make sure the character exists is alive
if member ~= nil then
--make sure the character is not dead
local unit = GetCharacterUnit( member )
if unit ~= nil then
--make sure the teleported unit is NOT human
if not IsCharacterHuman(member) then
--do the teleport
local to = GetEntityMatrix( GetCharacterUnit(character) )
SetEntityMatrix( unit, to )
end
end
end
end
--if it wasn't team 1 that dropped the powerup then it was team 2, so teleport team 2 to whoever's pos
elseif GetCharacterTeam(character) == 2 then
--get the team's size
local size = GetTeamSize( 2 )
--for each team member,
local m = 0
for m = 0, size-1 do
--get a team member's unit
local member = GetTeamMember(2, m)
--make sure the character exists is alive
if member ~= nil then
--make sure the character is not dead
local unit = GetCharacterUnit( member )
if unit ~= nil then
--make sure the teleported unit is NOT human
if not IsCharacterHuman(member) then
--do the teleport
local to = GetEntityMatrix( GetCharacterUnit(character) )
SetEntityMatrix( unit, to )
end
end
end
end
end
end
end
)
--teleport code end -^
--teleport code end -^
--teleport code end -^
That's what does all the work. Munge your unit, your common sides, and your script, play the level, and rally/teleport your whole team to you! This code is written so that both sides can use the weapon simultaneously, and it will not teleport your human teammates when you are playing MP.
Credits:
Me, CavalryCaptainMike
[RDH]Zerted, for sharing the "teleport AI to player" code he made for the fake console.
@Mav
I think you misunderstood what the tutorial is. It's a weapon that when fired, teleports (rallies) your entire team to your position. The FAQ only showed how to spawn units on your position. Additionally, the code I posted here allows both teams to have units with teleport weapons.
Very interesting tutorial. I might actually be able to adopt this for my Combat Drones, hmm...
Off-topic: Could people seriously please stop not posting code in code tags? Code tags retain formatting and indentations, and it's super annoying and really a huge waste of time to have to constantly go in and indent everything manually. Thanks.
CalvaryCptMike wrote:@Mav
I think you misunderstood what the tutorial is. It's a weapon that when fired, teleports (rallies) your entire team to your position. The FAQ only showed how to spawn units on your position. Additionally, the code I posted here allows both teams to have units with teleport weapons.
I didn't misunderstand you. What you did was write a tutorial for a specific kind of lua weapon. The meat of your tutorial is "here's how you spawn people at your location," which is covered in the FAQ topic.