SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Editing > Editing Help

Reply
 
Thread Tools Search this Thread
Old 12-08-2017   #1
choalover
チャオノコイビト
Default Lua Chat System Issues

I'm having a bug where clan chat only shows up for one person in the same clan even if there are multiple people in the same clan. Also, local chat only shows up for the source player even if other players are in range.

Code:
rawset(_G, "thenewlife", {})

thenewlife.userranks = {
	TNLUR_OWNER = "Owner",
	TNLUR_COOWNER = "Co-Owner",
	TNLUR_ADMIN = "Admin",
	TNLUR_MOD = "Mod",
	TNLUR_CITIZEN = "Citizen",
	TNLUR_GUEST = "Guest",
	TNLUR_BANNED = "Banned",
	TNLUR_EARLYMEMBER = "Early Member",
	
	["Owner"] = "Owner",
	["Co-Owner"] = "Co-Owner",
	["Admin"] = "Admin",
	["Mod"] = "Mod",
	["Citizen"] = "Citizen",
	["Guest"] = "Guest",
	["Banned"] = "Banned",
	["Early Member"] = "Early Member",
	
	[1] = "Owner",
	[2] = "Co-Owner",
	[3] = "Admin",
	[4] = "Mod",
	[5] = "Citizen",
	[6] = "Guest",
	[7] = "Banned",
	[8] = "Early Member",
}

thenewlife.clans = {
	TNLCLAN_MOONPARTY = "Moon Party Clan",
	TNLCLAN_EVILDOERS = "Evil Doers Clan",
	TNLCLAN_NEWLIFEWORKERS = "New Life Workers Clan",
	
	["Moon Party Clan"] = "Moon Party Clan",
	["Evil Doers Clan"] = "Evil Doers Clan",
	["New Life Workers Clan"] = "New Life Workers Clan",
	
	[1] = "Moon Party Clan",
	[2] = "Evil Doers Clan",
	[3] = "New Life Workers Clan",
}

thenewlife.chatchannels = {
	TNLCC_GLOBAL = "Global Chat Room",
	TNLCC_LOCAL = "Local Chat Room",
	TNLCC_VANILLA = "Vanilla Chat Room",
	TNLCC_PRIVATE = "Private Chat Room",
	TNLCC_CLAN = "Clan Chat Room",
	
	["Global Chat Room"] = "Global Chat Room",
	["Local Chat Room"] = "Local Chat Room",
	["Vanilla Chat Room"] = "Vanilla Chat Room",
	["Private Chat Room"] = "Private Chat Room",
	["Clan Chat Room"] = "Clan Chat Room",
	
	[1] = "Global Chat Room",
	[2] = "Local Chat Room",
	[3] = "Vanilla Chat Room",
	[4] = "Private Chat Room",
	[5] = "Clan Chat Room",
}

addHook("PlayerMsg", function(source, type, target, msg)
	if not mapheaderinfo[gamemap].thenewlife return false end
	if (type == 0)
		if (msg:sub(1, 1) == "/") and not (msg:sub(1, 3) == "/me")
			if (msg:sub(1, 2) == "//")
				msg = msg:sub(2)
			end
		end
	
		if not source.chatchannel
			source.chatchannel = thenewlife.chatchannels.TNLCC_GLOBAL
		end
	
		if (source.chatchannel == thenewlife.chatchannels.TNLCC_GLOBAL)
			type = 0
			print("\03[" + thenewlife.chatchannels.TNLCC_GLOBAL + "] (" + source.userrank + ") <" + source.name + "> " + msg)
			return true
		elseif (source.chatchannel == thenewlife.chatchannels.TNLCC_LOCAL)
			type = 2
			for player in players.iterate
				player.xydist = R_PointToDist2(source.mo.x, source.mo.y, player.mo.x, player.mo.y)
				player.zdist = abs(source.mo.z - player.mo.z)
				if ((player.xydist >= -5) and (player.xydist <= 5)) and ((player.zdist >= -5) and (player.zdist <= 5))
					player.inrangeofsource = true
				else
					player.inrangeofsource = false
				end
				if player.inrangeofsource
					CONS_Printf(player, "\03[" + thenewlife.chatchannels.TNLCC_LOCAL + "] (" + source.userrank + ") <" + source.name + "> " + msg)
					return true
				end
			end
		elseif (source.chatchannel == thenewlife.chatchannels.TNLCC_VANILLA)
			type = 0
			return false
		elseif (source.chatchannel == thenewlife.chatchannels.TNLCC_PRIVATE)
			type = 2
			target = source
			CONS_Printf(source, "\03[" + thenewlife.chatchannels.TNLCC_PRIVATE + " {Source}] (" + source.userrank + ") <" + source.name + "> " + msg)
			CONS_Printf(target, "\03[" + thenewlife.chatchannels.TNLCC_PRIVATE + " {Target}] (" + target.userrank + ") <" + target.name + "> " + msg)
			return true
		elseif (source.chatchannel == thenewlife.chatchannels.TNLCC_CLAN)
			type = 1
			for player in players.iterate
				if not source.clan CONS_Printf(source, "[TNL] You must be in a clan in order to use clan chat!\n") return true end
				if player.clan == source.clan
					CONS_Printf(player, "\03[" + thenewlife.chatchannels.TNLCC_CLAN + " {" + source.clan + "}] (" + source.userrank + ") <" + source.name + "> " + msg)
					return true
				end
			end
		end
	else return false
	end
end)
Update: The issues should be fixed cause I got help on Discord. It is a good idea to return true after the for loop, especially in the PlayerMsg, and HurtMsg hooks, and make sure to multiply by FRACUNIT if a function or something else returns fixed_t.
__________________
I really enjoy working on Lua scripts for SRB2.

Last edited by choalover; 12-08-2017 at 06:50 PM.
choalover is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.