Tronox Posted September 12, 2009 Posted September 12, 2009 Hi, I just started learning LUA. I have some simple chat commands (/pm and so), but what I need to do, so only players, that are in radius of x meters could see what i wrote? Thanks
Zadara Posted September 12, 2009 Posted September 12, 2009 Hi, I just started learning LUA. I have some simple chat commands (/pm and so), but what I need to do, so only players, that are in radius of x meters could see what i wrote?Thanks Mmm... You can create a col shape, around the one that typed the message. Check who is in that colshape, and if someone in the coll-shape, you can show the message for that one thats in the collshape. Just a idea...
Tronox Posted September 13, 2009 Author Posted September 13, 2009 (edited) Ok, here's the script: function localChat(sender, cmd, ... ) senderName = getPlayerName(sender) tbl_Message = {...} theMessage = table.concat( tbl_Message, " " ) local posX, posY, posZ = getElementPosition( sender ) local chatRadius = 10 local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) destroyElement( chatSphere ) for index, nearbyPlayer in ipairs( nearbyPlayers ) do outputChatBox( senderName.. " says: " ..theMessage, nearbyPlayer, 200, 200, 200 ) end end addCommandHandler("b", localChat) And it says: SCRIPT ERROR: ...TA San Andreas/server/mods/deathmatch/resources/Roleplay/server/Chat.lua:33: ')' expected near 'theMessage' [10:44:32] WARNING: Loading script failed: ...TA San Andreas/server/mods/deathmatch/resources/Roleplay/server/Chat.lua:33: ')' expected near 'theMessage' What's wrong with it? EDITED : I edited the code, but it's still not working EDITED: Thanks for your replies, it works Edited September 13, 2009 by Guest
robhol Posted September 13, 2009 Posted September 13, 2009 To add two strings you do "something" .. somevalue .. "another thing". The .. is a concatenation operator, it puts two strings together.
Dreft Posted September 13, 2009 Posted September 13, 2009 Or you can make everything with function PlayerToPoint(function from samp), function: function PlayerToPoint( player, radius, x, y, z ) oldpos = {} temppos = {} oldpos[0],oldpos[1],oldpos[2] = getElementPosition( player ) temppos[0] = oldpos[0] - x temppos[1] = oldpos[1] - y temppos[2] = oldpos[2] - z if(((temppos[0] < radius) and (temppos[0] > -radius)) and ((temppos[1] < radius) and (temppos[1] > -radius)) and ((temppos[2] < radius) and (temppos[2] > -radius))) then return true end return false end
Awwu Posted September 16, 2009 Posted September 16, 2009 Or you can make everything with function PlayerToPoint(function from samp), function: function PlayerToPoint( player, radius, x, y, z ) oldpos = {} temppos = {} oldpos[0],oldpos[1],oldpos[2] = getElementPosition( player ) temppos[0] = oldpos[0] - x temppos[1] = oldpos[1] - y temppos[2] = oldpos[2] - z if(((temppos[0] < radius) and (temppos[0] > -radius)) and ((temppos[1] < radius) and (temppos[1] > -radius)) and ((temppos[2] < radius) and (temppos[2] > -radius))) then return true end return false end You can actually make that much shorter: function playerToPoint( player, radius, x, y, z ) if isElement( player ) and radius and x and y and z then return getDistanceBetweenPoints3D( x, y, z, getElementPosition( player ) ) <= radius end return false end Though this one makes the check area a sphere shape rather than a cuboid.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now