Making Random Conversations [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

Post Reply
thelegend
Sith
Sith
Posts: 1433
Joined: Thu Jan 23, 2014 6:01 am
Projects :: Star Wars - Battlefront III Legacy
Games I'm Playing :: Swbf GTA CoD LoL KH
xbox live or psn: El_Fabricio#
Location: Right behind you :)

Making Random Conversations [Solved]

Post by thelegend »

I am trying to make dynamic/random conversations when you talk to a character (just destroying a static prop). The functon I needed itself worked great. i had no troubles after a few tries.... But how do I make random conversations after I certain object has been destroyed?

Here's an example code I use to show up a conversation:

Code: Select all

ShowObjectiveTextPopup("level.sod.characters.friends.best.1a", ATT)

   The other three:
ShowObjectiveTextPopup("level.sod.characters.friends.best.1b", ATT)
ShowObjectiveTextPopup("level.sod.characters.friends.best.1c", ATT)
ShowObjectiveTextPopup("level.sod.characters.friends.best.1d", ATT)
After killing one prop, a text should appear. This worked so far. But I want to make the game to choose between four different Popup Screens. I consider using math.random or any timers. But I have no idea how to make a fuction read another function.

Here's that bit of my lua with that conversation function:
Hidden/Spoiler:
[code]
friend = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "talk_box_friend1" then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1a", ATT)

--ShowObjectiveTextPopup("level.sod.characters.friends.best.1b", ATT)

SetClassProperty("hero_character_01", "NoEnterVehicles", 0)
SetProperty("talk_box_friend1", "CurHealth", 50)
SetProperty("talk_box_friend1", "MaxHealth", 50)

end
end
)
[/code]
Oh an by the way. I am using talk boxes as "destructablebuildings". I would like to use the collisions of animated props but I didn't find the right ClassLabel for destructable animated props. I tried AnimatedBuilding, ArmedAnimatedBuilding and various other ones. I also don't want to use standing Bots instead of animated props since I need all 8 avaiable teams.

I also wonder how many animated props can be placed on one single map just btw?
Last edited by thelegend on Sun Jan 17, 2016 7:18 pm, edited 1 time in total.
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Making Random Conversations

Post by AQT »

thelegend wrote:I consider using math.random or any timers. But I have no idea how to make a fuction read another function.
All you have to do is nest your randomization function within your current function. Simply stick the whole thing in right after the line:

Code: Select all

SetProperty("talk_box_friend1", "MaxHealth", 50)
thelegend
Sith
Sith
Posts: 1433
Joined: Thu Jan 23, 2014 6:01 am
Projects :: Star Wars - Battlefront III Legacy
Games I'm Playing :: Swbf GTA CoD LoL KH
xbox live or psn: El_Fabricio#
Location: Right behind you :)

Re: Making Random Conversations

Post by thelegend »

Thank you for your reply, AQT :)

I did what you said but now the entire function (OnObjectKill etc.) is gone in-game. I put this right under function ScriptPostLoad():

Code: Select all

friendtalk = math.random(1,4)
friend1()
And this is how that part is looking now:
Hidden/Spoiler:
[code]
friend = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "talk_box_friend1" then

SetClassProperty("hero_character_01", "NoEnterVehicles", 0)
SetProperty("talk_box_friend1", "CurHealth", 50)
SetProperty("talk_box_friend1", "MaxHealth", 50)

function friend1()
if friendtalk == 1 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1a", ATT)

elseif friendtalk == 2 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1b", ATT)

elseif friendtalk == 3 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1c", ATT)

elseif friendtalk == 4 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1d", ATT)
end
end
end
end
)[/code]
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Making Random Conversations

Post by AQT »

Hmm, you probably don't need the part you put under function ScriptPostLoad(). But you were on the right track; I'm pretty sure the following modification of the code you posted should work.
Hidden/Spoiler:
[code]friend = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "talk_box_friend1" then
SetClassProperty("hero_character_01", "NoEnterVehicles", 0)
SetProperty("talk_box_friend1", "CurHealth", 50)
SetProperty("talk_box_friend1", "MaxHealth", 50)

friendtalk = math.random(1,4)

if friendtalk == 1 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1a", ATT)
elseif friendtalk == 2 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1b", ATT)
elseif friendtalk == 3 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1c", ATT)
elseif friendtalk == 4 then
ShowObjectiveTextPopup("level.sod.characters.friends.best.1d", ATT)
end
end
end
)[/code]
thelegend
Sith
Sith
Posts: 1433
Joined: Thu Jan 23, 2014 6:01 am
Projects :: Star Wars - Battlefront III Legacy
Games I'm Playing :: Swbf GTA CoD LoL KH
xbox live or psn: El_Fabricio#
Location: Right behind you :)

Re: Making Random Conversations

Post by thelegend »

Thanks a lot, AQT. It's working now. The function returned and everything else works fine. You helped me a lot with your help :D

EDIT: This might be off-topic but how is it possible to "kill" a function. I put this function (the one from above) inside Objective1. But when the Object has finished I want to remove that function. So no text would appear after the talk-box has been "destroyed" through my lua. In general; how to activate and de-activate functions?
jedimoose32
Field Commander
Field Commander
Posts: 938
Joined: Thu Jan 24, 2008 12:41 am
Projects :: Engineering Degree
Location: The Flatlands of Canada

Re: Making Random Conversations [Solved]

Post by jedimoose32 »

Late reply: Why not nest the contents of your function inside something that checks whether the function has already run? Something like this (forgive me, my Lua is a bit rusty):

Code: Select all

local friendCheck = false

friend = OnObjectKill(
  function(object, killer)
    if friendCheck then return else
      <the rest of your friend function stuff>
      friendCheck = true
    end
  end
)
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Making Random Conversations [Solved]

Post by razac920 »

Much more efficient would be to instead write:

ReleaseObjectKill(friend) when you want 'friend' to stop checking for object kills.
Post Reply