Jump to content

TriggerServerEvent


Agon

Recommended Posts

Hi guys. I made this but it doesn't work. no error, no debugscript messages. I think problems are triggerServerEvent and addEvent.. Did i misplace them? I mean should I addEvents on client-side? (I have never used addEvent and trigger event). Here is my code:

------- Client Side -------

function bindTheKeys(key, keyState) 
bindKey("Q", "down", openMenu) 
bindKey("Q", "up", closeMenu) 
bindKey("E", "down", startGoogle) 
bindKey("E", "up", stopGoogle) 
end 
addEventHandler("onClientPlayerLogin", getRootElement(), bindTheKeys) 
  
function openMenu() 
knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife", true) 
sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword", true) 
gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun", true) 
fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist", true) 
logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo", true) 
guiSetVisible(not guiGetVisible(knife)) 
guiSetVisible(not guiGetVisible(sword)) 
guiSetVisible(not guiGetVisible(gun)) 
guiSetVisible(not guiGetVisible(fist)) 
guiSetVisible(not guiGetVisible(logo)) 
showCursor(not isCursorShowing()) 
end 
  
function closeMenu() 
guiSetVisible(not guiGetVisible(knife)) 
guiSetVisible(not guiGetVisible(sword)) 
guiSetVisible(not guiGetVisible(gun)) 
guiSetVisible(not guiGetVisible(fist)) 
guiSetVisible(not guiGetVisible(logo)) 
showCursor(not isCursorShowing()) 
end 
  
function giveTheWeapons(element) 
if (element == knife) then 
triggerServerEvent("giveKnife", getLocalPlayer())  
elseif (element == sword) then 
triggerServerEvent("giveSword", getLocalPlayer())  
elseif (element == gun) then 
triggerServerEvent("giveGun", getLocalPlayer()) 
elseif (element == fist) then 
triggerServerEvent("useFist", getLocalPlayer()) 
end 
end 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 
  
function startGoogle() 
if (getCameraGoggleEffect == "normal") then 
setCameraGoggleEffect("thermalvision") 
end 
end 
  
function stopGoogle() 
if (getCameraGoogleEffect == "thermalvision") then 
setCameraGoogleEffect("normal") 
end 
end 

------- Server Side -------

function giveMyKnife(source) 
takeWeapon(source, 8 ) 
takeWeapon(source, 24) 
giveWeapon(source, 4, 1) 
end 
addEvent("giveKnife", true) 
addEventHandler("giveKnife", getRootElement(), giveMyKnife) 
  
function giveMySword(source) 
takeWeapon(source, 4) 
takeWeapon(source, 24) 
giveWeapon(source, 8, 1) 
end 
addEvent("giveSword", true) 
addEventHandler("giveSword", getRootElement(), giveMySword) 
  
function giveMyGun(source) 
takeWeapon(source, 8 ) 
takeWeapon(source, 4) 
giveWeapon(source, 24, 3) 
end 
addEvent("giveGun", true) 
addEventHandler("giveGun", getRootElement(), giveMyGun) 
  
function useMyFist(source) 
takeWeapon(source, 8 ) 
takeWeapon(source, 4) 
takeWeapon(source, 24) 
end 
addEvent("useFist", true) 
addEventHandler("useFist", getRootElement(), useMyFist) 

Link to comment

-- client side:

function bindTheKeys() 
    bindKey("Q", "down", openMenu) 
    bindKey("Q", "up", closeMenu) 
    bindKey("E", "down", startGoogle) 
    bindKey("E", "up", stopGoogle) 
end 
addEvent("onClientPlayerLogin",true) 
addEventHandler("onClientPlayerLogin", getRootElement(), bindTheKeys) 
  
function openMenu() 
    knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife", true) 
    sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword", true) 
    gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun", true) 
    fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist", true) 
    logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo", true) 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function closeMenu() 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function giveTheWeapons(element) 
    if (element == knife) then 
        triggerServerEvent("giveKnife", localPlayer) 
    elseif (element == sword) then 
        triggerServerEvent("giveSword", localPlayer) 
    elseif (element == gun) then 
        triggerServerEvent("giveGun", localPlayer) 
    elseif (element == fist) then 
        triggerServerEvent("useFist", localPlayer) 
    end 
end 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 
  
function startGoogle() 
    if (getCameraGoggleEffect == "normal") then 
        setCameraGoggleEffect("thermalvision") 
    end 
end 
  
function stopGoogle() 
    if (getCameraGoogleEffect == "thermalvision") then 
        setCameraGoogleEffect("normal") 
    end 
end 

-- server side:

function giveMyKnife() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 24) 
    giveWeapon(source, 4, 1) 
end 
addEvent("giveKnife", true) 
addEventHandler("giveKnife", getRootElement(), giveMyKnife) 
  
function giveMySword() 
    takeWeapon(source, 4) 
    takeWeapon(source, 24) 
    giveWeapon(source, 8, 1) 
end 
addEvent("giveSword", true) 
addEventHandler("giveSword", getRootElement(), giveMySword) 
  
function giveMyGun() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 4) 
    giveWeapon(source, 24, 3) 
end 
addEvent("giveGun", true) 
addEventHandler("giveGun", getRootElement(), giveMyGun) 
  
function useMyFist() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 4) 
    takeWeapon(source, 24) 
end 
addEvent("useFist", true) 
addEventHandler("useFist", getRootElement(), useMyFist) 
  
addEventHandler("onPlayerLogin",root, 
    function () 
        triggerClientEvent(source,"onClientPlayerLogin",source) 
    end 
) 

Link to comment

That script should bind the key's when a player logs in, or do you want it to bind them when the resource starts? if so:

-- client side:

function bindTheKeys() 
    bindKey("Q", "down", openMenu) 
    bindKey("Q", "up", closeMenu) 
    bindKey("E", "down", startGoogle) 
    bindKey("E", "up", stopGoogle) 
end 
addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys) 
  
function openMenu() 
    knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife", true) 
    sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword", true) 
    gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun", true) 
    fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist", true) 
    logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo", true) 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function closeMenu() 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function giveTheWeapons(element) 
    if (element == knife) then 
        triggerServerEvent("giveKnife", localPlayer) 
    elseif (element == sword) then 
        triggerServerEvent("giveSword", localPlayer) 
    elseif (element == gun) then 
        triggerServerEvent("giveGun", localPlayer) 
    elseif (element == fist) then 
        triggerServerEvent("useFist", localPlayer) 
    end 
end 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 
  
function startGoogle() 
    if (getCameraGoggleEffect == "normal") then 
        setCameraGoggleEffect("thermalvision") 
    end 
end 
  
function stopGoogle() 
    if (getCameraGoogleEffect == "thermalvision") then 
        setCameraGoogleEffect("normal") 
    end 
end 

-- server side:

function giveMyKnife() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 24) 
    giveWeapon(source, 4, 1) 
end 
addEvent("giveKnife", true) 
addEventHandler("giveKnife", getRootElement(), giveMyKnife) 
  
function giveMySword() 
    takeWeapon(source, 4) 
    takeWeapon(source, 24) 
    giveWeapon(source, 8, 1) 
end 
addEvent("giveSword", true) 
addEventHandler("giveSword", getRootElement(), giveMySword) 
  
function giveMyGun() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 4) 
    giveWeapon(source, 24, 3) 
end 
addEvent("giveGun", true) 
addEventHandler("giveGun", getRootElement(), giveMyGun) 
  
function useMyFist() 
    takeWeapon(source, 8 ) 
    takeWeapon(source, 4) 
    takeWeapon(source, 24) 
end 
addEvent("useFist", true) 
addEventHandler("useFist", getRootElement(), useMyFist) 

Link to comment
addEvent("onClientPlayerLogin",true) 
  
function startGoogle() 
    if getCameraGoggleEffect( ) == "normal" then 
        setCameraGoggleEffect( "thermalvision" ) 
    end 
end 
  
function stopGoogle() 
    if getCameraGoggleEffect( ) == "thermalvision" then 
        setCameraGoggleEffect( "normal" ) 
    end 
end 
  
  
  
  
  
function openMenu() 
    knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife", true) 
    sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword", true) 
    gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun", true) 
    fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist", true) 
    logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo", true) 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function closeMenu() 
    guiSetVisible(not guiGetVisible(knife)) 
    guiSetVisible(not guiGetVisible(sword)) 
    guiSetVisible(not guiGetVisible(gun)) 
    guiSetVisible(not guiGetVisible(fist)) 
    guiSetVisible(not guiGetVisible(logo)) 
    showCursor(not isCursorShowing()) 
end 
  
function giveTheWeapons(element) 
    if (element == knife) then 
        triggerServerEvent("giveKnife", localPlayer) 
    elseif (element == sword) then 
        triggerServerEvent("giveSword", localPlayer) 
    elseif (element == gun) then 
        triggerServerEvent("giveGun", localPlayer) 
    elseif (element == fist) then 
        triggerServerEvent("useFist", localPlayer) 
    end 
end 
  
function bindTheKeys() 
    bindKey("Q", "down", openMenu) 
    bindKey("Q", "up", closeMenu) 
    bindKey("E", "down", startGoogle) 
    bindKey("E", "up", stopGoogle) 
end 
     
addEventHandler("onClientPlayerLogin", getRootElement(), bindTheKeys) 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 

You not call function and getCameraGoogleEffect/setCameraGoogleEffect there is no.

viewtopic.php?f=91&t=40807

Link to comment

I wanted to add it when player logins because the script was going to check if the player is admin. That's why i made it onClientPlayerLogin. btw i can't see the images.. should i use guiSetVisible(logo, true) instead of guiSetVisible(not guiGetVisible(logo)) ?

Edit: Kenix i still can't see the gui or use google effects..

Link to comment
addEvent("onClientPlayerLogin",true) 
  
knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife.png", true) 
sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword.png", true) 
gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun.png", true) 
fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist.png", true) 
logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo.png", true) 
guiSetVisible( knife,   false )  
guiSetVisible( sword,   false ) 
guiSetVisible( gun,     false ) 
guiSetVisible( fist,    false ) 
guiSetVisible( logo,    false ) 
     
function fStateGoogle( ) 
    return setCameraGoggleEffect( getCameraGoggleEffect( ) == 'thermalvision' and 'normal' or getCameraGoggleEffect( ) == 'normal' and 'thermalvision'  ) 
end 
  
  
function fStateMenu( ) 
    guiSetVisible( knife, not guiGetVisible( knife ) ) 
    guiSetVisible( sword, not guiGetVisible( sword ) ) 
    guiSetVisible( gun, not guiGetVisible( gun ) ) 
    guiSetVisible( fist, not guiGetVisible( fist ) ) 
    guiSetVisible( logo, not guiGetVisible( logo ) ) 
    showCursor( not isCursorShowing( ) ) 
end 
  
function giveTheWeapons( ) 
    if (source == knife) then 
        triggerServerEvent("giveKnife", localPlayer) 
    elseif (source == sword) then 
        triggerServerEvent("giveSword", localPlayer) 
    elseif (source == gun) then 
        triggerServerEvent("giveGun", localPlayer) 
    elseif (source == fist) then 
        triggerServerEvent("useFist", localPlayer) 
    end 
end 
  
function bindTheKeys() 
    bindKey( "Q", "down", fStateMenu ) 
    bindKey( "E", "down", fStateGoogle ) 
end 
     
addEventHandler("onClientPlayerLogin", getRootElement(), bindTheKeys) 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 

Updated again.

Edited by Guest
Link to comment

<meta> 
    <info author="Agon" name="Menu" version="1.0" type="script"/> 
  
    <file src="images/aclogo.png"/> 
    <file src="images/sword.png"/> 
    <file src="images/knife.png"/> 
    <file src="images/gun.png"/> 
    <file src="images/fist.png"/> 
     
    <script src="menu_s.lua"/> 
    <script src="menu_c.lua" type="client"/> 
     
</meta> 
  

can't see the gui again..

Link to comment

Tested

addEvent("onClientPlayerLogin",true) 
  
knife = guiCreateStaticImage(0.4678, 0.3242, 0.0977, 0.1315, "images/knife.png", true) 
sword = guiCreateStaticImage(0.5830, 0.4336, 0.0977, 0.1315, "images/sword.png", true) 
gun = guiCreateStaticImage(0.3457, 0.4479, 0.0977, 0.1315, "images/gun.png", true) 
fist = guiCreateStaticImage(0.4688, 0.5898, 0.0977, 0.1315, "images/fist.png", true) 
logo = guiCreateStaticImage(0.4521, 0.4232, 0.0977, 0.1315, "images/aclogo.png", true) 
guiSetVisible( knife,   false )  
guiSetVisible( sword,   false ) 
guiSetVisible( gun,     false ) 
guiSetVisible( fist,    false ) 
guiSetVisible( logo,    false ) 
     
function fStateGoogle( ) 
    return setCameraGoggleEffect( getCameraGoggleEffect( ) == 'thermalvision' and 'normal' or getCameraGoggleEffect( ) == 'normal' and 'thermalvision'  ) 
end 
  
  
function fStateMenu( ) 
    guiSetVisible( knife, not guiGetVisible( knife ) ) 
    guiSetVisible( sword, not guiGetVisible( sword ) ) 
    guiSetVisible( gun, not guiGetVisible( gun ) ) 
    guiSetVisible( fist, not guiGetVisible( fist ) ) 
    guiSetVisible( logo, not guiGetVisible( logo ) ) 
    showCursor( not isCursorShowing( ) ) 
end 
  
function giveTheWeapons( ) 
    if (source == knife) then 
        triggerServerEvent("giveKnife", localPlayer) 
    elseif (source == sword) then 
        triggerServerEvent("giveSword", localPlayer) 
    elseif (source == gun) then 
        triggerServerEvent("giveGun", localPlayer) 
    elseif (source == fist) then 
        triggerServerEvent("useFist", localPlayer) 
    end 
end 
  
function bindTheKeys() 
    bindKey( "Q", "down", fStateMenu ) 
    bindKey( "E", "down", fStateGoogle ) 
end 
     
addEventHandler("onClientPlayerLogin", getRootElement(), bindTheKeys) 
addEventHandler("onClientMouseEnter", getRootElement(), giveTheWeapons) 

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