Hazard| Posted July 14, 2014 Share Posted July 14, 2014 Hello, I tried to make something like this before, and didn't reach the goal yet (easy script for you) The issue is that I don't really know how to make this happend only on (theplayer)'s screen. Like if the command to make the sound & picture go off on a players screen, was "scare", and I did /scare Haz then the player with the namepart "Haz" got "scared". The code below is what I have, the scareImage function should be handled by a command named "scare". Can you help? local sw,sh = guiGetScreenSize() function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function scareImage() local scareSound = playSound("scare.mp3") setSoundVolume(scareSound, 1) dxDrawImage(math.random(-5,0),math.random(-5,0),sw+5,sh+5,'scare.jpg',0,0,0,tocolor(255,255,255,math.random(200,240)),true) end --addCommandHandler("scare"?????????????????????????????????????????????????) thx Link to comment
GTX Posted July 14, 2014 Share Posted July 14, 2014 Server: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end addCommandHandler("scaree", function(player, command, target) local target = getPlayerFromPartialName(target) if target then triggerClientEvent(target, "scareJumpThem", target) end end ) Client: function drawIt() -- Do whatever. end function scare() addEventHandler("onClientRender", root, drawIt) end addEvent("scareJumpThem", true) addEventHandler("scareJumpThem", root, scare) Link to comment
Hazard| Posted July 14, 2014 Author Share Posted July 14, 2014 ERROR: Server triggered clientside event scareJumpThem, but event is not added clientside Link to comment
Blinker. Posted July 14, 2014 Share Posted July 14, 2014 client side function draw(target) local scareSound = playSound("scare.mp3") setSoundVolume(scareSound, 1) dxDrawImage(math.random(-5,0),math.random(-5,0),sw+5,sh+5,'scare.jpg',0,0,0,tocolor(255,255,255,math.random(200,240)),true) end function drawHandler() addEventHandler("onClientRender",root,draw) end addEvent("draw",true) addEventHandler("draw",root,drawHandler) server side function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end addCommandHandler("scare", function(player, command, target) local target = getPlayerFromPartialName(target) if target then triggerClientEvent("draw", localPlayer,target) end end ) Link to comment
GTX Posted July 14, 2014 Share Posted July 14, 2014 What the hell, Blinker.? Your code is wrong. Hazard|, make sure your meta is written properly. (Must include server side and client side file.) Link to comment
Hazard| Posted July 14, 2014 Author Share Posted July 14, 2014 My meta "" author="" version="1" type="script" /> Is it wrong? Link to comment
Controlled Posted July 15, 2014 Share Posted July 15, 2014 Quick improvement for server. function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name~=nil then -- Change this so "if name" actually does something. As you defined before you want it or nil. for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end addCommandHandler("scaree", function(player, command, target) local target = getPlayerFromPartialName(target) if target then triggerClientEvent(target, "scareJumpThem", target) end end ) Try this with the client. Root wasn't defined. function drawIt() -- Do whatever. end function scare() addEventHandler("onClientRender", root, drawIt) end addEvent("scareJumpThem", true) addEventHandler("scareJumpThem", getRootElement(), scare) Link to comment
Hazard| Posted July 15, 2014 Author Share Posted July 15, 2014 Still same error http://imgur.com/ZLXcgT9 Link to comment
ADCX Posted July 15, 2014 Share Posted July 15, 2014 Server: function getPlayerFromPartialName(SearchName) local Players = getElementsByType("player") for _,Player in ipairs(Players) local PlayerName = getPlayerName(Player) if string.find(PlayerName,SearchName) then return Player end end return false end function ScarePlayer(Player,Command,Argument) if (Command == "scare") then if (Argument) then local Victim = getPlayerFromPartialName(Argument) if (Victim) then triggerClientEvent(Victim, "ShowScare",Player) else outputChatBox("Player not found!",Player) end else outputChatBox("Player's name not specified!",Player) end end end addCommandHandler("scare",ScarePlayer) Client: ScareLength = 5000 -- How much time will the scare be rendered (in milliseconds) function ShowScare() addEventHandler("onClientRender",getRootElement,DrawScare) setTimer(removeEventHandler,ScareLength,1,"onClientRender",getRootElement,DrawScare) end addEvent("ShowScare",true) addEventHandler("ShowScare",getRootElement(),ShowScare) function DrawScare() local scareSound = playSound("scare.mp3") setSoundVolume(scareSound,1) dxDrawImage(math.random(-5,0),math.random(-5,0),sw+5,sh+5,'scare.jpg',0,0,0,tocolor(255,255,255,math.random(200,240)),true) end Link to comment
Hazard| Posted July 15, 2014 Author Share Posted July 15, 2014 WARNING: c.lua:4: Bad argument @ 'addEventHandler' [Expected element at argument 2, got function I got this warning now, when I do 'scare playername' Link to comment
ADCX Posted July 15, 2014 Share Posted July 15, 2014 Try now. Client: ScareLength = 5000 -- How much time will the scare be rendered (in milliseconds) function ShowScare() addEventHandler("onClientRender",getRootElement(),DrawScare) setTimer(removeEventHandler,ScareLength,1,"onClientRender",getRootElement,DrawScare) end addEvent("ShowScare",true) addEventHandler("ShowScare",getRootElement(),ShowScare) function DrawScare() local scareSound = playSound("scare.mp3") setSoundVolume(scareSound,1) dxDrawImage(math.random(-5,0),math.random(-5,0),sw+5,sh+5,'scare.jpg',0,0,0,tocolor(255,255,255,math.random(200,240)),true) end Link to comment
Hazard| Posted July 15, 2014 Author Share Posted July 15, 2014 it works, I just had to put local sw,sh = guigetscreensize () ++++ but it renders the sound too so it sounds so stupid Can you make the sound just replay n replay n replay? not render? thx Link to comment
GTX Posted July 15, 2014 Share Posted July 15, 2014 Try this with the client. Root wasn't defined. function drawIt() -- Do whatever. end function scare() addEventHandler("onClientRender", root, drawIt) end addEvent("scareJumpThem", true) addEventHandler("scareJumpThem", getRootElement(), scare) "root" is predefined variable. It's same as getRootElement(). Link to comment
ADCX Posted July 15, 2014 Share Posted July 15, 2014 Yes, you were right about the sound, I'm not sure how I didn't notice that. Client: ScareLength = 5000 -- How much time will the scare be rendered (in milliseconds) function ShowScare() local scareSound = playSound("scare.mp3") setSoundVolume(scareSound,1) addEventHandler("onClientRender",getRootElement(),DrawScare) setTimer(removeEventHandler,ScareLength,1,"onClientRender",getRootElement,DrawScare) end addEvent("ShowScare",true) addEventHandler("ShowScare",getRootElement(),ShowScare) function DrawScare() dxDrawImage(math.random(-5,0),math.random(-5,0),sw+5,sh+5,'scare.jpg',0,0,0,tocolor(255,255,255,math.random(200,240)),true) end Also, like GTX said, you can use 'root' instead of 'getRootElement()' and 'resourceRoot' instead of 'getResourceRootElement()'. It doesn't make much difference, but it spares a CPU usage a bit. 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