GetCharacterUnit is troubling me and pinging weapon [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: GetCharacterUnit is troubling me

Post by Noobasaurus »

Thanks. I used that, changed it a bit, but it doesn't like my ending ). And then if I remove it, it wants the ) back. Here's what I have:
Hidden/Spoiler:
[code] pingmaker = OnObjectDamage(function(object, damager)
-- if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" and GetObjectTeam(object) == 2 then
if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" then
--When the weapon is fired:
minChange = 300 --or whatever distance you want to search
x, y, z = GetWorldPosition(damager)
playerPos = {x, y, z}

for i, v in pairs(unitsAlive) do
local x, y, z = GetWorldPosition(unit)
searchingPos = {x, y, z}

if math.abs(searchingPos[1] - playerPos[1]) < minChange
and math.abs(searchingPos[2] - playerPos[2]) < minChange
and math.abs(searchingPos[3] - playerPos[3]) < minChange
and playerTeam == 2 then
ShowMessageText("level.0CW.ping")
pingcount = pingcount + 1;
CreateEntity("com_item_null", GetEntityMatrix(object), "ping"..pingcount)
MapAddEntityMarker("ping"..pingcount, "hud_objective_icon1", 5.0, 1, "BLUE", true, true, true)
if pingcount == 1 then
StartTimer(ping1)
end
if pingcount == 2 then
StartTimer(ping2)
end
if pingcount == 3 then
StartTimer(ping3)
end
if pingcount == 4 then
StartTimer(ping4)
end
if pingcount == 5 then
StartTimer(ping5)
end
if pingcount == 6 then
StartTimer(ping6)
end
if pingcount == 7 then
StartTimer(ping7)
end
if pingcount == 8 then
StartTimer(ping8)
end
if pingcount == 9 then
StartTimer(ping9)
end
if pingcount == 10 then
StartTimer(ping10)
end
if pingcount == 11 then
StartTimer(ping11)
end
if pingcount == 12 then
StartTimer(ping12)
end
if pingcount == 13 then
StartTimer(ping13)
end
if pingcount == 14 then
StartTimer(ping14)
end
if pingcount == 15 then
StartTimer(ping15)
end
if pingcount == 16 then
StartTimer(ping16)
end
if pingcount == 17 then
StartTimer(ping17)
end
if pingcount == 18 then
StartTimer(ping18)
end
if pingcount == 19 then
StartTimer(ping19)
end
if pingcount == 20 then
StartTimer(ping20)
end
if pingcount == 21 then
StartTimer(ping21)
end
if pingcount == 22 then
StartTimer(ping22)
end
if pingcount == 23 then
StartTimer(ping23)
end
if pingcount == 24 then
StartTimer(ping24)
end
if pingcount == 25 then
StartTimer(ping25)
end
if pingcount == 26 then
StartTimer(ping26)
end
if pingcount == 27 then
StartTimer(ping27)
end
if pingcount == 28 then
StartTimer(ping28)
end
if pingcount == 29 then
StartTimer(ping29)
end
if pingcount == 30 then
StartTimer(ping30)
end
if pingcount == 31 then
StartTimer(ping31)
end
if pingcount == 32 then
StartTimer(ping32)
end
if pingcount == 33 then
StartTimer(ping33)
end
if pingcount == 34 then
StartTimer(ping34)
end
if pingcount == 35 then
StartTimer(ping35)
end
if pingcount == 36 then
StartTimer(ping36)
end
if pingcount == 37 then
StartTimer(ping37)
end
if pingcount == 38 then
StartTimer(ping38)
end
if pingcount == 39 then
StartTimer(ping39)
end
if pingcount == 40 then
StartTimer(ping40)
end
if pingcount == 41 then
StartTimer(ping41)
end
if pingcount == 42 then
StartTimer(ping42)
end
if pingcount == 43 then
StartTimer(ping43)
end
if pingcount == 44 then
StartTimer(ping44)
end
if pingcount == 45 then
StartTimer(ping45)
end
if pingcount == 46 then
StartTimer(ping46)
end
if pingcount == 47 then
StartTimer(ping47)
end
if pingcount == 48 then
StartTimer(ping48)
end
if pingcount == 49 then
StartTimer(ping4)
end
if pingcount == 50 then
StartTimer(ping50)
end
end
end
end)[/code]
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: GetCharacterUnit is troubling me

Post by Locutus »

You're missing an "end" at the end.
Hidden/Spoiler:
[code]pingmaker = OnObjectDamage(
function(object, damager)
if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" then
minChange = 300 --or whatever distance you want to search
x, y, z = GetWorldPosition(damager)
playerPos = {x, y, z}

for i, v in pairs(unitsAlive) do
local x, y, z = GetWorldPosition(unit)
searchingPos = {x, y, z}

if math.abs(searchingPos[1] - playerPos[1]) < minChange
and math.abs(searchingPos[2] - playerPos[2]) < minChange
and math.abs(searchingPos[3] - playerPos[3]) < minChange
and playerTeam == 2 then
ShowMessageText("level.0CW.ping")
pingcount = pingcount + 1;
CreateEntity("com_item_null", GetEntityMatrix(object), "ping"..pingcount)
MapAddEntityMarker("ping"..pingcount, "hud_objective_icon1", 5.0, 1, "BLUE", true, true, true)
if pingcount == 1 then
StartTimer(ping1)
--[2...49]
elseif pingcount == 50 then
StartTimer(ping50)
end
end
end
end
end
)[/code]
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: GetCharacterUnit is troubling me

Post by LRKfm946 »

Also, you need to get unit and playerTeam again each time you do an iteration of the for loop. So it would look something like this:
Hidden/Spoiler:
[code]pingmaker = OnObjectDamage(
function(object, damager)
if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" then
minChange = 300 --or whatever distance you want to search
x, y, z = GetWorldPosition(damager)
playerPos = {x, y, z}

for i, v in pairs(unitsAlive) do
unit = GetCharacterUnit(i) --**Add these lines**
playerTeam = GetCharacterTeam(i) --"
local x, y, z = GetWorldPosition(unit)
searchingPos = {x, y, z}


if math.abs(searchingPos[1] - playerPos[1]) < minChange
and math.abs(searchingPos[2] - playerPos[2]) < minChange
and math.abs(searchingPos[3] - playerPos[3]) < minChange
and playerTeam == 2 then
ShowMessageText("level.0CW.ping")
pingcount = pingcount + 1;
CreateEntity("com_item_null", GetEntityMatrix(object), "ping"..pingcount)
MapAddEntityMarker("ping"..pingcount, "hud_objective_icon1", 5.0, 1, "BLUE", true, true, true)
if pingcount == 1 then
StartTimer(ping1)
--[2...49]
elseif pingcount == 50 then
StartTimer(ping50)
end
end
end
end
end
)[/code]

You could also try changing all of these:

Code: Select all

if pingcount == 1 then
                  StartTimer(ping1)
to just this:

Code: Select all

StartTimer(ping..pingcount)
I'm not 100% sure if it'll work but it's worth a try.
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: GetCharacterUnit is troubling me

Post by Noobasaurus »

Thanks for the responses guys! I added another end and put in those extra lines. Unfortunately, I still get errors.

Code: Select all

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\LuaCallbacks_Mission.cpp(635)
Entity "0" not found

Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to perform arithmetic on field `?' (a nil value)
stack traceback:
	(none): in function <(none):37>
And here's what I currently have.
Hidden/Spoiler:
[code]
unitsAlive = {}

unitSpawn = OnCharacterSpawn(
function(character)
playerInfo = {playerUnit = GetCharacterUnit(character), playerTeam = GetCharacterTeam(character)--, this comma is only necessary if you add more info
--any other info you want to record
}
unitsAlive[character] = playerInfo
end)


pingcount = 0;
pingmaker = OnObjectDamage(function(object, damager)
-- if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" and GetObjectTeam(object) == 2 then
if GetObjectLastHitWeaponClass(object) == "imp_weap_inf_wrist_rocket" then
--When the weapon is fired:
minChange = 300 --or whatever distance you want to search
x, y, z = GetWorldPosition(damager)
playerPos = {x, y, z}

for i, v in pairs(unitsAlive) do
unit = GetCharacterUnit(i) --**Add these lines**
playerTeam = GetCharacterTeam(i) --"
local x, y, z = GetWorldPosition(unit)
searchingPos = {x, y, z}

if math.abs(searchingPos[1] - playerPos[1]) < minChange
and math.abs(searchingPos[2] - playerPos[2]) < minChange
and math.abs(searchingPos[3] - playerPos[3]) < minChange
and playerTeam == 2 then
ShowMessageText("level.0CW.ping")
pingcount = pingcount + 1;
CreateEntity("com_item_null", GetEntityMatrix(object), "ping"..pingcount)
MapAddEntityMarker("ping"..pingcount, "hud_objective_icon1", 5.0, 1, "BLUE", true, true, true)
if pingcount == 1 then
StartTimer(ping1)
end
-- pings in here
if pingcount == 50 then
StartTimer(ping50)
end
end
end
end
end)
[/code]
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: GetCharacterUnit is troubling me

Post by LRKfm946 »

Entity '0' not found means you input a character number (in this case the player, character 0) into a function that was expecting an object or entity (Unit, EntityPtr, etc.).

As for the second error, what's line 37 in the script?
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: GetCharacterUnit is troubling me

Post by Noobasaurus »

Line 37 is the line with pingcount = 0; on it.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: GetCharacterUnit is troubling me

Post by LRKfm946 »

Aaaaah that line shouldn't have a semicolon at the end of it.
Hidden/Spoiler:
You've been doing some C++ haven't you? :P
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: GetCharacterUnit is troubling me

Post by Noobasaurus »

lolwut no

Well, I guess I have been doing some stuff with C++ in terms of server emulation, but I didn't write any of it.

Now I get the same error but it's in the pingmaker function (somewhere in the whole thing).
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: GetCharacterUnit is troubling me

Post by LRKfm946 »

Woops, that first GetWorldPosition should take Unit as an argument, not Character. That was my bad in the code I gave you. I think that will fix both errors.

Code: Select all

minChange = 300 --or whatever distance you want to search
  x, y, z = GetWorldPosition(damager) --<<<<<Change this to damager's unit.
  playerPos = {x, y, z}
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: GetCharacterUnit is troubling me

Post by Noobasaurus »

YES! IT WORKS! Thank you all so much for helping me!

And yay, I finally did something right, I used GetCharacterUnit woooooo!
Post Reply