Jump to content

Panel when player died


Recommended Posts

hello guys,

I'm creating a panel which should appear when you died or when you log in the server. But what I've tried didnt work. Someone can tell me how it should be?

There are 2 warnings with debug

lua:8 Bad argument @ 'addEventHandler' [Expected function at argument 3, got none]

lua:20 Bad argument @ 'addEventHandler' [Expected function at argument 3, got none]

function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
end 
  
local drawingPanel = false 
addEventHandler ( "onPlayerLogin", root ) 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 
  
  
addEventHandler( "onPlayerWasted", root ) 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 

Edited by Guest
Link to comment
Well, to start with, the events you are using are both server side.

Second, you put a parentheses where there should be a comma.

addEventHandler( "onPlayerWasted", root ) 

Correct:

addEventHandler( "onPlayerWasted", root, 

Ah, I've also tried to do it without a parenthese as explained in wiki but that didn't work.

So probably the problem is that I've use it in clientside

I'll try it in serverside.

Thanks,

EDIT::

I've got another problem..

debug:

lua:4: attempt to call global 'drawPanel' (a nill value)

I've moved the eventhandlers to the clientside.

When I die that error comes and when I login as well.

The codes so far.

ServerSide:

addEventHandler ( "onPlayerLogin", root, 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 
) 
  
  
addEventHandler( "onPlayerWasted", root, 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 
) 

ClientSide:

function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
end 

I've read that I need to use SetTimer, but I don't know how I can apply it to the script.

Edited by Guest
Link to comment

well no need to, change line 19 from

onPlayerWasted 

to

OnClientPlayerWasted 

at line 7 addEvent at server side and trigger server event from your client side.

would be the following:

Client:

function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
end 
  
local drawingPanel = false 
triggerServerEvent( "InsertYourEventName", localplayer, "sourceEvent") 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 
  
  
addEventHandler( "onClientPlayerWasted", root, 
    function () 
        if not drawingPanel then 
            drawPanel() 
            drawingPanel = true 
        else 
            drawPanel() 
            drawingPanel = false 
        end 
    end 

ofc you'll add addEventHandler server side

addEvent 
addEventHandler 

Link to comment

Here, use this client-side; This will draw your panel when the player dies, until he spawns again. Try to learn from it, if you have any questions, post them up.

local function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
end 
  
--When the player dies 
addEventHandler("onClientPlayerWasted", localPlayer, 
function() 
    addEventHandler("onClientRender", root, drawPanel) --Draw the panel each frame using onClientRender 
end) 
  
--When the player spawns 
addEventHandler("onClientPlayerSpawn", localPlayer, 
function() 
    removeEventHandler("onClientRender", root, drawPanel) --Stop drawing the panel by removing the event handler 
end) 

Link to comment

onPlayerLogin is not a command, it is an event that is triggered when a player logs in.You can script your own client-side onPlayerLogin.

You can use the following server-side:

addEventHandler("onPlayerLogin", root, 
function() 
    triggerClientEvent(source, "onClientPlayerLogin", source) 
  
end) 

I've edited the script to include the custom onClientPlayerLogin event, client-side:

local drawing = false 
  
local function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
end 
  
--Function to attach the onClientRender event to drawPanel, to draw your panel each frame. 
local function attachHandler() 
    if not drawing then 
        addEventHandler("onClientRender", root, drawPanel) 
        drawing = true 
    end 
end 
  
--Remove handler to stop drawing the panel 
local function removeHandler() 
    if drawing then 
        removeEventHandler("onClientRender", root, drawPanel) 
        drawing = false 
    end 
end 
  
--When the player dies 
addEventHandler("onClientPlayerWasted", localPlayer, attachHandler) 
  
 --When the player logs in 
addEvent("onClientPlayerLogin", true) 
addEventHandler("onClientPlayerLogin", localPlayer, attachHandler) 
  
--When the player spawns 
addEventHandler("onClientPlayerSpawn", localPlayer, removeHandler) 

You are going to need to stop drawing the panel after the player logs in at some point, just hook the event that suits you to removeHandler to stop drawing the panel.

Edited by Guest
Link to comment

I've got another question. I got a panel, and some buttons. These are supposed to open a panel when you click at one it also works. But, I want it for example if you click on LS button the ls panel appear, but if you click on LV button, LS panel will disappear and the LV one will appear.

Script i've so far. This opens the panel but when you click on the other one that one opens as well, but i want the previous one closed if you click on another one.

local drawingPanel = false 
  
function drawPanel() 
    dxDrawImage(306, 186, 399, 344, "wdspawn.png", 0, 0, 0, tocolor(0, 0, 0, 160), false) 
    dxDrawText("RC", 552, 397, 615, 439, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "left", "top", false, false, true, false, false) 
    dxDrawText("WS", 395, 396, 458, 438, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "left", "top", false, false, true, false, false) 
    dxDrawText("LS", 478, 460, 541, 502, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "left", "top", false, false, true, false, false) 
    dxDrawText("Spawn", 405, 334, 605, 378, tocolor(255, 255, 255, 255), 1.30, "bankgothic", "center", "top", false, false, true, false, false) 
    
   if detailFunction and type(detailFunction) == "function" then 
        detailFunction() -- draw the right part the panel 
    end 
end 
  
local function attachHandler() 
    if not drawing then 
        addEventHandler("onClientRender", root, drawPanel) 
        drawing = true 
        guiPanelBtnSetVisible ( true ) 
        showCursor ( true ) 
    end 
end 
  
local function removeHandler() 
    if drawing then 
        removeEventHandler("onClientRender", root, drawPanel) 
        guiPanelBtnSetVisible ( false ) 
        showCursor ( false )   
    end 
end 
  
addEventHandler("onClientPlayerWasted", localPlayer, attachHandler) 
  
addEvent("onClientPlayerLogin", true) 
addEventHandler("onClientPlayerLogin", localPlayer, attachHandler) 
  
addEventHandler("onClientPlayerSpawn", localPlayer, removeHandler) 
  
function guiPanelBtnSetVisible( bool ) 
    guiSetVisible(ls.btn, bool) 
    guiSetVisible(ws.btn, bool) 
    guiSetVisible(rc.btn, bool) 
end 
  
------------------------------------------------------------------------------------------------------- 
ls = {} 
function drawLSwindow( btn, state) 
    ls.window = guiCreateWindow(552, 481, 355, 198, "", false) 
    lsCatagory = guiCreateGridList(17, 45, 155, 143, false, ls.window) 
    guiGridListAddColumn(GUIEditor.gridlist[1], "Catagory", 0.9) 
    lsCatagory = guiCreateGridList(182, 45, 155, 143, false, ls.window) 
    guiGridListAddColumn(class.gridlist, "Class", 0.9) 
    lsLabal = guiCreateLabel(21, 21, 107, 24, "Los Santos Spawns", false, ls.window) 
    guiLabelSetVerticalAlign(GUIEditor.label[1], "center") 
end 
     
function onLSButtonClicked( btn, state ) 
    if btn ~= "left" or state ~= "up" then return end 
    detailFunction = drawLSwindow 
end 
  
ls.btn = guiCreateButton(476, 452, 66, 60, "", false) 
guiSetAlpha(ls.btn, 0) 
guiSetVisible(ls.btn, false) 
addEventHandler("onClientGUIClick", ls.btn, onLSButtonClicked, true) 
------------------------------------------------------------------------------------------------------- 
ws = {} 
function drawWSwindow( btn, state) 
    ws.window = guiCreateWindow(32, 422, 355, 198, "", false) 
    wsCatagory = guiCreateGridList(17, 45, 155, 143, false, ws.window) 
    guiGridListAddColumn(GUIEditor.gridlist[2], "Catagory", 0.9) 
    wsClass = guiCreateGridList(182, 45, 155, 143, false, ws.window) 
    guiGridListAddColumn(GUIEditor.gridlist[3], "Class", 0.9) 
    wsLabel = guiCreateLabel(21, 21, 133, 24, "Whetstone Spawns", false, ws.window) 
    guiLabelSetVerticalAlign(GUIEditor.label[2], "center") 
end 
  
function onWSButtonClicked( btn, state ) 
    if btn ~= "left" or state ~= "up" then return end 
    detailFunction = drawWSwindow 
end 
  
ws.btn = guiCreateButton(397, 388, 66, 60, "", false) 
guiSetAlpha(ws.btn, 0) 
guiSetVisible(ws.btn, false) 
addEventHandler("onClientGUIClick", ws.btn, onWSButtonClicked, true) 
------------------------------------------------------------------------------------------------------- 
rc = {} 
function drawRCwindow( btn, state) 
    rc.window = guiCreateWindow(627, 422, 355, 198, "", false) 
    rcCatagory = guiCreateGridList(17, 45, 155, 143, false, rc.window) 
    guiGridListAddColumn(GUIEditor.gridlist[4], "Catagory", 0.9) 
    rcClass = guiCreateGridList(182, 45, 155, 143, false, rc.window) 
    guiGridListAddColumn(GUIEditor.gridlist[5], "Class", 0.9) 
    rcLabel = guiCreateLabel(21, 21, 123, 24, "Red Country Spawns", false, rc.window) 
    guiLabelSetVerticalAlign(GUIEditor.label[3], "center") 
end 
  
function onRCButtonClicked( btn, state ) 
    if btn ~= "left" or state ~= "up" then return end 
    detailFunction = drawRCwindow 
end 
  
rc.btn = guiCreateButton(551, 387, 66, 60, "", false) 
guiSetAlpha(rc.btn, 0) 
guiSetVisible(rc.btn, false) 
addEventHandler("onClientGUIClick", rc.btn, onRCButtonClicked, false) 

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