Page 1 of 1

Talking Weapon

Posted: Thu Jan 24, 2013 2:16 pm
by kelly1111
Hello There,

I'm pretty new at scripting. And have a question about generating a talking weapon. When I say pretty new. I mean : I don't have to faintest idea how to start :)

I want to create a weapon that talks to the player when it is equiped. Do I use a onequiphook?
And what kind of script would I make (and where to place it) to get the talking part completly random (every once in a while)

Can u guys get me started with an example ? ... I would love to puzzel with it myself if I get a head start :)

Re: Talking Weapon

Posted: Thu Jan 24, 2013 3:17 pm
by Neikun
I think.. you could use the onEquip hook to activate a timer with a lengthy interval that activates a random phrase script. You could use the onUnequip hook to deactivate the timer.

Re: Talking Weapon

Posted: Thu Jan 24, 2013 4:51 pm
by Komag
You would probably want to put all the phrases into a big table talkTable = { }, then whenever the timer fires off have the script pull a random table element and hudPrint it
hudPrint(talkTable[math.random(1,#talkTable)])

Re: Talking Weapon

Posted: Sat Jan 26, 2013 10:30 pm
by kelly1111
Thanks. so far I tried this for testing. but it gives an error.
what does this error mean. ive linked it to a presure plate to test it

error: attempt to get a lenght of a global 'talktable' (a nil value) X

function talkingweapon()

talkTable = {"kill kill kill", "hate hate hate", "pain pain pain" },
hudPrint(talkTable[math.random(1,#talkTable)])

end

Re: Talking Weapon

Posted: Sun Jan 27, 2013 12:07 am
by Komag
maybe that extra comma at the end of the table line is causing the problem. Also, if the table isn't going to change, you might want to put it outside the function, like right before it, so it gets defined at map start.