GuyFromPast Posted September 25, 2010 Share Posted September 25, 2010 (edited) 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 September 25, 2010 by Guest Link to comment
dzek (varez) Posted September 25, 2010 Share Posted September 25, 2010 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
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 Ok i started all again and finally got it working but theres only one problem.. how to make getplayerfromname working like when i type /n var then it understand that i mean varez .. right now i have to type /n #00ff00varez for this .. any tips ? Link to comment
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 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
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 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
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 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
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 Thank you so much Link to comment
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 ((sorry doublepost )) bah ur probably sick of helping me already :@ but i need one more thing that i cant handle how to "else" like if player not found then it says outputChatBox("blabla to himselfblabla") Link to comment
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 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
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 Well i tryed it before.. not working thats why i asked it here maybe its because when player not found i get error in console bad argument to find blabla got nil ... Link to comment
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 post your whole script.. and if you have any warning/error COPY IT EXACTLY AS IT SAYS.. Also read this topic: viewtopic.php?f=91&t=27027 Omg.. It's like phoning to Customer Center and complaining for 30 mins about that you can't (for example) start your car, and after that 30 minutes you tell them that yesterday the engine had blown. Link to comment
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 # 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
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 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
GuyFromPast Posted September 26, 2010 Author Share Posted September 26, 2010 Oo thanks.. works perfect Link to comment
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