Jump to content

Need some help with chat script


GuyFromPast

Recommended Posts

function no(player, cmd) 
  local player = getLocalPlayer() 
       outputChatBox  ( "#ff0000No Way ".. string.stripColourCodes(getPlayerName(player)) .. "!", 24, 73, 122,true) 
   end 
    
addCommandHandler("n", no) 
function string.stripColourCodes(s) 
   return type(s) == 'string' and string.gsub(s,'#%x%x%x%x%x%x','') or s 
end 

I need help with that script

Im afraid im getting only bad words here because i have readed other topic and yeah..

anyways i need script for example when i type /n Varez then it says No way, Varez or /n p50 then it says No way, p50

I have readed whole wiki and this is all what i got there :(

Edited by Guest
Link to comment

This is just random. You are confusing server side and client side. Also You are trying to display player element. This is all wrong.

I think you are trying to "learn" lua by only reading examples from wiki. You can't do it this way. Follow tutorial. Check wiki main page, there's link saying Scripting Introduction

Link to comment

wow, i was thinking so hard to understand you.. i think you are talking about:

  
function findPlayerByName(playerPart) 
  local pl = getPlayerFromName(playerPart) 
  if isElement(pl) then 
    return pl 
  else 
    for i,v in ipairs (getElementsByType ("player")) do 
      if (string.find(getPlayerName(v),playerPart)) then 
        return v 
      end 
    end 
  end 
end 
  

Link to comment

Um.. not working but thanks for trying to help me :(

ok i try to make example because my english suck

i wanna do this command

(ur full name is #ff00ffvarez)

i have to type /n #ff00ffvarez

but i want to make it easier.. like /n var and it do same thing

function no( playerSource, command, elephant ) 
    local horse = getPlayerFromName ( elephant )               
    if ( horse ) then 
    local egg = getPlayerName(playerSource)                                       
    outputChatBox (egg.." No way, " ..elephant.." !", getRootElement(), 0, 0, 5, true ) 
    end 
end 
  
addCommandHandler ( "n", no ) 
  
  
  
  

Link to comment

horse, elephant, egg? xDDD

i gave you this function to use it:

  
function findPlayerByName(playerPart) 
  local pl = getPlayerFromName(playerPart) 
  if isElement(pl) then 
    return pl 
  else 
    for i,v in ipairs (getElementsByType ("player")) do 
      if (string.find(getPlayerName(v),playerPart)) then 
        return v 
      end 
    end 
  end 
end 
  
function no(playerSource, command, arg1) 
    local playerElement = findPlayerByName(arg1) 
    if playerElement then 
      local name = getPlayerName(playerElement) 
      local sourceName = getPlayerName(playerSource) 
      outputChatBox (sourceName..": No way, " ..name.." !", getRootElement(), 0, 0, 5, true) 
    end 
end 
  
addCommandHandler ("n", no) 
  

clean now?

Link to comment
  
    if playerElement then 
      local name = getPlayerName(playerElement) 
      local sourceName = getPlayerName(playerSource) 
      outputChatBox (sourceName..": No way, " ..name.." !", getRootElement(), 0, 0, 5, true) 
    else 
      local sourceName = getPlayerName(playerSource) 
      outputChatBox (sourceName.." to himself: No way!", getRootElement(), 0, 0, 5, true) 
    end 
  

this is weird for me.

also this is very basic thing, hope you will learn lua more

Link to comment
# function findPlayerByName(playerPart) 
   local pl = getPlayerFromName(playerPart) 
   if isElement(pl) then 
     return pl 
   else 
     for i,v in ipairs (getElementsByType ("player")) do 
       if (string.find(getPlayerName(v),playerPart)) then 
         return v 
       end 
     end 
   end 
 end 
   
 function no(playerSource, command, arg1) 
    local playerElement = findPlayerByName(arg1) 
     if playerElement then 
      local name = getPlayerName(playerElement) 
       local sourceName = getPlayerName(playerSource) 
      outputChatBox (sourceName..": No way, " ..name.." !", getRootElement(), 0, 0, 5, true) 
   else 
     local sourceName = getPlayerName(playerSource) 
     outputChatBox (sourceName.." to himself: No way!", getRootElement(), 0, 0, 5, true) 
     end 
 end 
   
 addCommandHandler ("n", no) 
   

and error

ERROR: newbi-scripts/untlited 10.lua:8 bad argument #2 to 'find' (string expected, got nil) 

hope it help

else not working :(

Link to comment

because you used only "n" command, without anything as argument ;|

"fixed" and commented code:

  
function findPlayerByName(playerPart) 
    local pl = getPlayerFromName(playerPart) 
    if isElement(pl) then 
        return pl 
    else 
        for i,v in ipairs (getElementsByType ("player")) do 
            if (string.find(getPlayerName(v),playerPart)) then 
                return v 
            end 
        end 
    end 
 end 
   
function no(playerSource, command, arg1) 
    if arg1 == nil then 
        -- player is not specified 
        -- this message goes only to player used "n" command 
        outputChatBox("You have to specify player name", playerSource, 255, 255, 255, true) 
    else 
        local playerElement = findPlayerByName(arg1) 
        if playerElement then 
            -- we found player 
            local name = getPlayerName(playerElement) 
            local sourceName = getPlayerName(playerSource) 
            outputChatBox (sourceName..": No way, " ..name.." !", getRootElement(), 255, 255, 255, true) 
        else 
            -- player is not found 
            local sourceName = getPlayerName(playerSource) 
            outputChatBox (sourceName.." to himself: No way!", getRootElement(), 255, 255, 255, true) 
        end 
    end 
end 
  

and result (my ingame nick: dzek)

/n

You have to specify player name

/n vare

dzek to himself: No way!

/n dze

dzek: No way, dzek !

i think that this X to himself should be: player is not found, but whatever

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