Welcome to Open Carnage

A resource for gamers and technology enthusiasts, with unique means of rewarding content creation and support. Have a wander to see why we're worth the time!

Weyland

Toggle rprint message on and off

Hi,

 

I have a basic script below I'm using to create player commands that rprint custom messages with info/content to the console i.e Discord link, YouTube channel link

 

Would anyone be able to help embellish it so the message stays on screen until the command is executed again?

So the command essentially toggles the message on and off.

I've seen it done on a few servers, so I'm hoping one of you legends has something sitting around.

Best,
Weyland

 

api_version = "1.9.0.0"

function OnScriptLoad()
		 register_callback(cb['EVENT_COMMAND'],"OnCommand")
end
function OnCommand(PlayerIndex,Command)
		 Command = string.lower(Command)
if(Command == "stuff") then
for i = 1,26 do rprint(PlayerIndex, " ") end
				rprint(PlayerIndex, "This is about stuff")
				rprint(PlayerIndex, "So here's the stuff")
				rprint(PlayerIndex, "and maybe here's a link you can jot down")
return false
else
return true
end
end
function OnScriptUnload()	end

 

Edited by Weyland

Share this post


Link to post
Share on other sites

Here: 

-- Don't touch these.
api_version = "1.10.0.0"
display = {}
lines = {} 

-- Command to trigger text.
cmd = "!info"

-- line[number] = "text" .. get_var(1, "$global event variable")
-- or
-- line[number] = "text"
lines[1] = "Server Name: ".. get_var(1, "$svname")
lines[2] = "Gametype: ".. get_var(1, "$gt")
lines[3] = "This is line three"
lines[4] = "This is line four"
-- Add more lines as needed

function OnScriptLoad()
	register_callback(cb['EVENT_COMMAND'], "OnEventCommand")
	register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
	register_callback(cb['EVENT_TICK'], "OnEventTick")
end

function OnEventCommand(PlayerIndex, Command, Enviroment, Password)
	-- Lets get quotation marks out of our commands.
	local Command = string.lower(string.gsub(Command, '"', ""))
	if Command == cmd then
		-- If they are already set to true then set to false.
		if display[tonumber(PlayerIndex)] then 
			display[tonumber(PlayerIndex)] = false
		else -- If they are not true then set to true
			display[tonumber(PlayerIndex)] = true
		end
		return false
	end
end

function OnPlayerJoin(PlayerIndex)
	-- Make sure the default is for this to be truned off.
	-- Also makes it so the last player in this slot's setting does not carry over.
	display[tonumber(PlayerIndex)] = false
end

function OnEventTick()
	for i = 1,16 do
		-- Check if the player is in the server.
		if player_present(i) then
			-- If they want the display then.
			if display[i] then
				-- Spam 26 blank lines (to clear console for ENG and ESP clients.)
				for j = 0,25 do rprint(i, " ") end 
				-- Print info from all the lines (in order) to the player.
				for x = 1,#lines do
					rprint(i, lines[x])
				end
			end
		end
	end
end

function OnScriptUnload()	end	

 

Edited by Devieth
api_version = "1.10.0.0"

Share this post


Link to post
Share on other sites
18 hours ago, Weyland said:

Thanks @Devieth

 

Unfortunately I'm not able to get this working.

 

The script itself isn't loading.

Any ideas or suggestions would be much appreciated.

Try it now (updated to api_version = "1.10.0.0")

Share this post


Link to post
Share on other sites

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.