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:
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)
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?
Re: Making Random Conversations
Posted: Sun Jan 17, 2016 6:30 pm
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:
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]
Re: Making Random Conversations
Posted: Sun Jan 17, 2016 7:12 pm
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]
Re: Making Random Conversations
Posted: Sun Jan 17, 2016 7:18 pm
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
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?
Re: Making Random Conversations [Solved]
Posted: Sun Jan 31, 2016 1:22 pm
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):
local friendCheck = false
friend = OnObjectKill(
function(object, killer)
if friendCheck then return else
<the rest of your friend function stuff>
friendCheck = true
end
end
)
Re: Making Random Conversations [Solved]
Posted: Sun Jan 31, 2016 8:30 pm
by razac920
Much more efficient would be to instead write:
ReleaseObjectKill(friend) when you want 'friend' to stop checking for object kills.