Jump to content

Random innocent/traitor message


frankvg

Recommended Posts

Hello people.

I need some help.

Lately I wanted to do Trouble in Terrorist Town with some friends but we wanted to remake it on MTA.

I've made a nice map to use for it but now we've still got a problem left since we all can't script.

I wanted to know if it is hard to make like a (random) innocent/traitor script, so that if there are 4 people, 1 will be assigned as traitor and the rest innocent, and that noone can see it from each other, so each will get private message like: "You are innocent" or "You are the traitor".

I don't know if this is hard to make or really simple, it would be totally awesome if someone would have time to script it really "fast and simple" for us.

Regards.

Frank.

Link to comment

Use the function getRandomPlayer. This function will get 1 random player, then store the returned value(player element) in a variable. For example;

randomTerrorist = getRandomPlayer() 

Then you make a for loop for all players, and make a basic comparsion;

local randomTerrorist = getRandomPlayer() 
local allPlayers = getElementsByType("player") -- Can also use getAlivePlayers 
for k, v in ipairs(allPlayers) do 
    if(v ~= randomTerrorist) then   -- If the player is NOT the player stored in randomTerrorist, continue. 
        outputChatBox("You are innocent!", v, 0, 187, 0, true) 
    elseif(v == randomTerrorist) then -- Else if the player IS the terrorist, do this; 
        outputChatBox("You are the terrorist!", v, 187, 0, 0, true) 
    end 
end 

Then when you execute this is for you to figure out what suits you best. If you need any further help, don't hesitate to ask!

Link to comment

Wel I havent been able to test dealman yet, the problem is that I cannot make scripts and he only gave me info about a meta.xcl and now I need a serverside lua script to create it as a resource but don't know what to put in it.

The Meta.xcl won't run without a lua file.

Link to comment

@Et-win, thats how noob I am ;)

Well,l I want a script to put in a resource, so I can start the resource by typing in the server log.

I want it to be like when the resource is started and I typ /start or /ttt or whatever that everyone gets a private message with "You are innocent" and "You are the traitor".

I want it that one person can get the traitor message and the rest will get the innocent message.

I mostly got around 5 players on my server, and they're all friends of mine so...

I don't want it to run all the time, it should be in a resource so I can start it myself when I want to, so that I can start the resource myself.

Link to comment

Just make these files and you will be fine :)

script-server.lua file:

function sendTraitor() 
    local gRandomPlayer = getRandomPlayer() 
    outputChatBox("You are the traitor, "..getPlayerName(gRandomPlayer).."!", gRandomPlayer, 255, 255, 255, true) 
    local gPlayers = getElementsByType("player") 
    for placeNumber, playerData in ipairs(gPlayers) do 
        if (playerData ~= gRandomPlayer) then 
            outputChatBox("You are innocent! "..getPlayerName(gRandomPlayer).." is the traitor!", playerData, 255, 255, 255, true) 
        end 
    end 
end 
  
addCommandHandler("ttt", sendTraitor) --Change 'ttt' if you want another command, or just add another 'addCommandHandler'! 

meta.xml file:

<meta> 
    <info name="Random Traitor" author="Et-win (For frankvg)" version="1.0" description="Makes some random player a traitor!" /> 
    <script src="script-server.lua" type="server" 
</meta> 

(Not tested, typed everything out of my head)

EDIT: If you want, there can be put a timer on.

Link to comment

Hey ,Et-win I made the files and put the meta.xml and the lua script in a resource, but when I turn the server on it gives me this message about the resource:

ERROR: Couldn't parse meta file for resource 'terroristtown'

Loading of resource 'terroristtown' failed

I called the lua file script-server.lua

and the meta.xml is just meta.xml

and these two are inside the map named terroristtown

Link to comment
Nevermind, I fixed it, you forgot the /> after the last sentence in the meta file.

Hehe :P

I got it working now, but do you happen to know if its also possible for a small square to pop up in the right beneath corner which says: Innocent - or - traitor.

Like here, in the left corner beneath.

traitors.jpg

dxDrawText --With: 
onClientRender 
--Or something with GUI, like: 
guiCreateLabel 
--But I recommend dxDrawText 
  

Is it also possible to give the traitor a knife..

I guess I need something to add beneath the local gRandomPlayer = getRandomPlayer() part or something?

Yup:

giveWeapon 

function sendTraitor() 
    local gRandomPlayer = getRandomPlayer() 
    outputChatBox("You are the traitor, "..getPlayerName(gRandomPlayer).."!", gRandomPlayer, 255, 255, 255, true) 
    giveWeapon(gRandomPlayer, 4) 
    local gPlayers = getElementsByType("player") 
    for placeNumber, playerData in ipairs(gPlayers) do 
        if (playerData ~= gRandomPlayer) then 
            outputChatBox("You are innocent! "..getPlayerName(gRandomPlayer).." is the traitor!", playerData, 255, 255, 255, true) 
        end 
    end 
end 
  
addCommandHandler("ttt", sendTraitor) --Change 'ttt' if you want another command, or just add another 'addCommandHandler'! 

Link to comment

Wow, thanks, and how hard is it, to add a detective in that script with a deagle.

I know that the deagle ID is 24 so: giveWeapon(gRandomPlayer, 24)

But I don't know how to add a detective. (Like one player could be a detective, kinda just like the traitor)

And where would I paste this? And what to write? :)

dxDrawText --With: 
onClientRender 

man im annoying asking so much shit.

Link to comment

So about the text:

  
local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
  
    -- Draw zone name text's shadow. 
    dxDrawText ( ??????????, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
    -- Draw zone name text. 
    dxDrawText ( ??????????, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )  
end 
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
end 
  

So I found this kinda almost ready script on the wiki, but how do I make an individual text for the traitor AND the innocent.

So that it shows innocent for the innocent, and traitor for the traitor.

So that if I typ the command /ttt and that it gives us a message what we are, traitor or innocent that it also shows a text in the bottom of the screen somewhere, or the upper left which says "Innocent (if you are innocent") and "Traitor"(if you are traitor).

I also would like that the innocent text is displayed in white, and the traitor text in red.

I'm also still wondering about how to add an extra message like "You are the detective" (and that that person gets a deagle as weapon)

Link to comment

If you read it on the wiki, you see it triggers from serverside to clients. You can easily add it:

triggerClientEvent(gRandomPlayer, "OnYourCodeHereStuffStart", getRootElement()) 

After the 'for' loop, you can do the same for all the other players. (playerData)

You can edit dxDrawText however you want. Also the Font.

Link to comment

Hm, well I can't seem to get the text working.

So the last thing I'll need to know is, how to add another message to the script

  
function sendTraitor() 
    local gRandomPlayer = getRandomPlayer() 
    outputChatBox("You are the traitor, "..getPlayerName(gRandomPlayer).."!", gRandomPlayer, 255, 255, 255, true) 
    giveWeapon(gRandomPlayer, 4) 
    local gPlayers = getElementsByType("player") 
    for placeNumber, playerData in ipairs(gPlayers) do 
        if (playerData ~= gRandomPlayer) then 
            outputChatBox("You are innocent! "..getPlayerName(gRandomPlayer).." is the traitor!", playerData, 255, 255, 255, true) 
        end 
    end 
end 
  
addCommandHandler("ttt", sendTraitor) --Change 'ttt' if you want another command, or just add another 'addCommandHandler'! 

So I want a new message in this one, we now got traitor and innocent, but I wanted to add a detective message myself (also for 1 player only, just like traitor) but it seemed harder than i expected and I failed in it.

I also wanted to give the detective weapon id 24, the deagle.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...