Jump to content

onPlayerChat Problem


gokalpfirat

Recommended Posts

  
g_R = getRootElement() 
messages{ 
"Hi" 
"How are u" 
"Whats up?" 
} 
serials { 
"2F79CDD46FA67EB6006A1C1E24BD3583" 
} 
randm = messages[math.random(1,3)] 
serial = getPlayerSerial(source) 
function onJoin() 
for i,v in pairs(serials) 
if (serial = v) then 
setElementData(source,"LP",true) 
end 
end 
addEventHandler("onPlayerJoin",g_R,onJoin) 
  
function chat(message,messageType) 
if getElementData(source,"LP") then 
cancelEvent() 
outputChatBox(getPlayerName(source).."#FFFFFF:"..randm ,g_R,0,0,0,true) 
end 
end 
addEventHandler("onPlayerChat",g_R,chat) 

Please fix it :cry: It should do when the serial that i want join setElementData LP true and when he chats cancelEvent() and create a new message to him. Its server-side.

Link to comment
  
messages = { 
"Hi", 
"How are u?", 
"Whats up?", 
"I love you", 
"I speak shit", 
"add more here", 
"no need to change anything else, too;)" 
} 
serials =  { 
"2F79CDD46FA67EB6006A1C1E24BD3583" 
} 
  
function chat(message,messageType) 
   serial = getPlayerSerial(source) 
   if serials[serial] then 
       cancelEvent() 
       outputChatBox(getPlayerName(source).."#FFFFFF:"..messages[math.random(1,table.getn(messages))] or "Hehe, you suck!" ,source,0,0,0,true) 
   end 
end 
addEventHandler("onPlayerChat",root,chat) 

Edited by Guest
Link to comment

You mean this ?

  
g_R = getRootElement() 
messages = { 
"Hi", 
"How are u", 
"Whats up?" 
} 
serials = { 
"2F79CDD46FA67EB6006A1C1E24BD3583" 
} 
randm = messages[math.random(1,#messages)] 
  
function onJoin() 
  
serial = getPlayerSerial(source)   
 if serial == serials then 
setElementData(source,"LP",true) 
end 
end 
addEventHandler("onPlayerJoin",g_R,onJoin) 
  
function chat(message,messageType) 
if getElementData(source,"LP") == true  then 
cancelEvent() 
outputChatBox(getPlayerName(source).."#FFFFFF:"..randm ,source,0,0,0,true) 
end 
end 
addEventHandler("onPlayerChat",g_R,chat) 

Link to comment
g_R = getRootElement() 
messages{ 
"Hi" 
"How are u" 
"Whats up?" 
} 
serials { 
["2F79CDD46FA67EB6006A1C1E24BD3583"] = true 
} 
  
  
function onJoin() 
local serial = getPlayerSerial(source) 
if serials[serial] then 
setElementData(source,"LP",true) 
end 
end 
addEventHandler("onPlayerJoin",g_R,onJoin) 
  
function chat(message,messageType) 
if getElementData(source,"LP") then 
cancelEvent() 
local randm = messages[math.random(1,3)] 
outputChatBox(getPlayerName(source).."#FFFFFF:"..randm ,g_R,0,0,0,true) 
end 
end 
addEventHandler("onPlayerChat",g_R,chat) 

Link to comment
messages = { 
"Hi", 
"How are u", 
"Whats up?" 
} 
  
serials = { 
["2F79CDD46FA67EB6006A1C1E24BD3583"] = true 
} 
  
  
function onJoin() 
local serial = getPlayerSerial(source) 
if serials[serial] then 
setElementData(source,"LP",true) 
end 
end 
addEventHandler("onPlayerJoin",root,onJoin) 
  
function chat(message,messageType) 
if getElementData(source,"LP") then 
cancelEvent() 
local randm = messages[math.random(#messages)] 
outputChatBox(getPlayerName(source).."#FFFFFF:"..randm ,root,0,0,0,true) 
end 
end 
addEventHandler("onPlayerChat",root,chat) 

Tested, don't forget to give the resource admin.

Link to comment
function hideJack(player,command,who,...) 
local targetPlayer = getPlayerFromName ( who ) 
if targetPlayer then 
local message = table.concat({...}, " ") 
outputChatBox(getPlayerName(who).."#EBDDB2: "..message ,root,255,255,255,true) 
end 
end 
addCommandHandler("yaziasda",hideJack) 

Link to comment

Use /debugscript 3

function hideJack(player,command,who,...) 
  local targetPlayer = getPlayerFromName ( who ) 
  if targetPlayer then 
    local message = table.concat({...}, " ") 
    outputChatBox(getPlayerName(targetPlayer ).."#EBDDB2: "..message ,root,255,255,255,true) 
  end 
end 
addCommandHandler("yaziasda",hideJack) 

Link to comment

You will have to make a "getPlayerFromPartialName"

here:

function getPlayerFromName( partialName ) 
    if partialName then 
        local matches = {} 
        for i, player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( player ) == partialName then 
                return player 
            end 
            if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then 
                table.insert ( matches , player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        end 
    end 
    return false 
end 

Now just put it anywhere, and don't change anything.

Link to comment
function sendMessageToNearbyPlayers( message, messageType ) 
    if messageType == 0 then 
        for i,v in ipairs( getElementsByType ("player") ) do 
            local theName = getAccountName (getPlayerAccount (source)) 
          outputChatBox( "#00FF00".. theName ..": #FFFFFF" .. message, v, 0, 0, 0, true ) 
        end 
        cancelEvent() 
    end 
end 
addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) 
  

That should do it

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...