Jump to content

Client side & server side


Lordkrypton

Recommended Posts

Posted

Hi,

This is the first time i create a script with both server side & client side.

It's like a vip panel, and only players for are vip ( meaning are friendly ) can open it.

I don't understand how to make the jetpack button call a function in the server side ( givePedJetPack ).

Can someone help me ?

Thank you

window = guiCreateWindow(0.25,0.25,0.1,0.5,"Vip Panel",true) 
guiSetAlpha( window, 1 ) 
guiWindowSetMovable(window,true) 
guiWindowSetSizable(window,false) 
guiSetVisible(window,false) 
showCursor(false) 
  
button = guiCreateButton( 0.05, 0.1, 1, 0.1, "Jetpack", true, window ) 
button = guiCreateButton( 0.05, 0.3, 1, 0.1, "blablabla", true, window ) 
  
--Binding to set window visible 
bindKey('k','down', 
function() 
guiSetVisible(window, not guiGetVisible(window)) 
showCursor(not isCursorShowing()) 
end 
) 

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

Use triggerServerEvent, read the information and examples thoroughly and it's rather easy to understand.

Simply put, you have a server-side function which is remotely triggered by a client. You use addEvent to create a custom event for that function, then trigger that event via triggerServerEvent.

Same logic applies for triggerClientEvent.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Thank you :D

But i don't understand how to use the button.

Look at what i did.

Client :

window = guiCreateWindow(0.25,0.25,0.1,0.5,"Vip Panel",true) 
guiSetAlpha( window, 1 ) 
guiWindowSetMovable(window,true) 
guiWindowSetSizable(window,false) 
guiSetVisible(window,false) 
showCursor(false) 
  
  
buttonjet = guiCreateButton( 0.05, 0.1, 1, 0.1, "Jetpack", true, window ) 
addEventHandler ( "onClientGUIClick", buttonjet, givejetpack, false ) 
  
  
function givejetpack () 
triggerServerEvent ( "onGiveJet", resourceRoot ) 
end 
  
--Binding to set window visible 
bindKey('k','down', 
function() 
guiSetVisible(window, not guiGetVisible(window)) 
showCursor(not isCursorShowing()) 
end 
) 

server :

function putjet() 
    outputChatBox ( "test") 
end 
addEvent( "onGiveJet", true ) 
addEventHandler( "onGiveJet", resourceRoot, putjet ) 

Help me to link the button to the event putjet on server-side :)

Thank you

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

addEventHandler is called before giveJetpack is even declared.

buttonjet = guiCreateButton( 0.05, 0.1, 1, 0.1, "Jetpack", true, window )  
  
function givejetpack () 
triggerServerEvent ( "onGiveJet", resourceRoot ) 
end 
addEventHandler ( "onClientGUIClick", buttonjet, givejetpack, false ) 
  

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Thank you :) but, i mean, how to link the ped who click in client-side to server-side, i know i can add arguments to triggerServerEvent but wich one ?

Excuse my bad english :/

Thnak you :)

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

Give the jetpack to client, it is the variable representing the game client that called the request/event. However, using some cheats, people might be able to fraudulently call this event despite the fact they're not actually VIP, so you should further check if the request originated from a VIP player.

Previously known as MrTasty.

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