Jump to content

Passing elements to server from client


Fabio(GNR)

Recommended Posts

Posted

So i created a GUI, script and everything that i think will work but i can't find a good way to pass the "client" element :(

Client:

function showgui () 
weapwindow = guiCreateWindow(307,127,480,516,"Weapons Menu",false) 
BuyAK = guiCreateButton(95,76,117,59,"Ak47 - 500$",false,weapwindow) 
BuyM4 = guiCreateButton(96,154,116,57,"M4 - 600$",false,weapwindow) 
BuyMP5 = guiCreateButton(97,302,116,57,"MP5 - 400$",false,weapwindow) 
BuyUZI = guiCreateButton(96,227,116,57,"UZI - 350$",false,weapwindow) 
BuyShotgun = guiCreateButton(278,300,117,59,"Shotgun - 400$",false,weapwindow) 
BuyComShot = guiCreateButton(278,227,117,59,"Combat Shotgun - 450$",false,weapwindow) 
BuyDeagle = guiCreateButton(277,76,117,59,"Deagle - 200$",false,weapwindow) 
BuyPistol = guiCreateButton(277,152,117,59,"Pistol - 150$",false,weapwindow) 
CloseButton = guiCreateButton(180,375,108,41,"Close",false,weapwindow) 
Text_Memo = guiCreateMemo(97,435,260,45,"You can buy weapons here for in DM.",false,weapwindow) 
guiMemoSetReadOnly(Text_Memo,true) 
guiSetVisible ( weapwindow, true ) 
showCursor(true) 
addEventHandler("onClientGUIClick", BuyAK, getAK, false) 
addEventHandler("onClientGUIClick", CloseButton, hidegui, false) 
end 
  
function hidegui() 
if guiGetVisible ( weapwindow ) then 
                guiSetVisible ( weapwindow, false )          
                showCursor( false ) 
     end 
end 
  
addCommandHandler ( "weapons", showgui ) 
  
  
function getAK ( playerSource ) 
local money = getPlayerMoney ( client ) 
    if (money > 500) then    
    outputChatBox("You don't have enough cash", client,230,0,0) 
    triggerServerEvent( "playerwantsAK", getLocalPlayer(), client) 
    else 
    outputChatBox("You don't have enough cash.", client,230,0,0) 
    end 
    end 

Server:

addEvent("playerwantsAK",true) 
addEventHandler("playerwantsAK",getRootElement(), 
function (client) 
if getElementData( client, "hasAK") == true then 
giveWeaponAmmo(client, 30, 450) 
outputChatBox("You got ammo for: AK",source,0,230,0) 
else 
givetheAK = giveWeapon(client, 30, 400, true) 
if givetheAk == true then 
setElementData( client, "hasAK", true) 
outputChatBox("You now have a: AK",source,0,230,0) 
else 
outputChatBox("failed to give AK",source,0,230,0) 
   end 
  end 
 end 
) 

Posted

why don't you just use giveWeapon for everything? it gives the ammo too.

function showgui () 
weapwindow = guiCreateWindow(307,127,480,516,"Weapons Menu",false) 
BuyAK = guiCreateButton(95,76,117,59,"Ak47 - 500$",false,weapwindow) 
BuyM4 = guiCreateButton(96,154,116,57,"M4 - 600$",false,weapwindow) 
BuyMP5 = guiCreateButton(97,302,116,57,"MP5 - 400$",false,weapwindow) 
BuyUZI = guiCreateButton(96,227,116,57,"UZI - 350$",false,weapwindow) 
BuyShotgun = guiCreateButton(278,300,117,59,"Shotgun - 400$",false,weapwindow) 
BuyComShot = guiCreateButton(278,227,117,59,"Combat Shotgun - 450$",false,weapwindow) 
BuyDeagle = guiCreateButton(277,76,117,59,"Deagle - 200$",false,weapwindow) 
BuyPistol = guiCreateButton(277,152,117,59,"Pistol - 150$",false,weapwindow) 
CloseButton = guiCreateButton(180,375,108,41,"Close",false,weapwindow) 
Text_Memo = guiCreateMemo(97,435,260,45,"You can buy weapons here for in DM.",false,weapwindow) 
guiMemoSetReadOnly(Text_Memo,true) 
guiSetVisible ( weapwindow, true ) 
showCursor(true) 
addEventHandler("onClientGUIClick", BuyAK, getAK, false) 
addEventHandler("onClientGUIClick", CloseButton, hidegui, false) 
end 
  
function hidegui() 
if guiGetVisible ( weapwindow ) then 
                guiSetVisible ( weapwindow, false )         
                showCursor( false ) 
     end 
end 
  
addCommandHandler ( "weapons", showgui ) 
  
function getAK ( playerSource ) 
local money = getPlayerMoney ( getLocalPlayer() ) 
    if (money > 500) then   
    triggerServerEvent( "playerwantsAK", getLocalPlayer(), getLocalPlayer()) 
    else 
    outputChatBox("You don't have enough cash.", 230,0,0) 
    end 
end 

addEvent("playerwantsAK",true) 
addEventHandler("playerwantsAK",getRootElement(), 
function (client) 
giveTheAK = giveWeapon(client, 30, 400, true) 
if giveTheAK then 
outputChatBox("You now have a: AK",source,0,230,0) 
else 
outputChatBox("failed to give AK",source,0,230,0) 
  end 
 end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

passing what element?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

If you want to pass an element from client to server, an ideal way would be to use triggerServerEvent.

The first 3 arguments for triggerServerEvent I think is

1. elements to trigger for

2. name of event to pass (this is a string value)

3. source of the event

The above are the 3 required arguments. You can supply extra values after those. This is where you will pass your element.

Example. triggerServerEvent ( getLocalPlayer(), "nameOfYourEvent", getLocalPlayer(), elementToPass )

 

After that you do addEvent ( "nameOfEvent", true ) to a server side script so it can communicate with your client.

crysis-02.png
Posted

triggerServerEvent ( getLocalPlayer(), "nameOfYourEvent", getLocalPlayer(), elementToPass )

the first getLocalPlayer() in client side is not needed if i'm right (at least i never use it)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)
triggerServerEvent ( getLocalPlayer(), "nameOfYourEvent", getLocalPlayer(), elementToPass )

the first getLocalPlayer() in client side is not needed if i'm right (at least i never use it)

I actually already tried this multiple times but i cant get it to work, how to "use" the element serverside after?

EDIT: btw, a player element

Edited by Guest
Posted

function (myevent,myevent2,myevent3)

its easy o_O

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function (myevent,myevent2,myevent3)

its easy o_O

but i have that:

--Client  function showgui () 
weapwindow = guiCreateWindow(307,127,480,516,"Weapons Menu",false) 
BuyAK = guiCreateButton(95,76,117,59,"Ak47 - 500$",false,weapwindow) 
BuyM4 = guiCreateButton(96,154,116,57,"M4 - 600$",false,weapwindow) 
BuyMP5 = guiCreateButton(97,302,116,57,"MP5 - 400$",false,weapwindow) 
BuyUZI = guiCreateButton(96,227,116,57,"UZI - 350$",false,weapwindow) 
BuyShotgun = guiCreateButton(278,300,117,59,"Shotgun - 400$",false,weapwindow) 
BuyComShot = guiCreateButton(278,227,117,59,"Combat Shotgun - 450$",false,weapwindow) 
BuyDeagle = guiCreateButton(277,76,117,59,"Deagle - 200$",false,weapwindow) 
BuyPistol = guiCreateButton(277,152,117,59,"Pistol - 150$",false,weapwindow) 
CloseButton = guiCreateButton(180,375,108,41,"Close",false,weapwindow) 
Text_Memo = guiCreateMemo(97,435,260,45,"You can buy weapons here for in DM.",false,weapwindow) 
guiMemoSetReadOnly(Text_Memo,true) 
guiSetVisible ( weapwindow, true ) 
showCursor(true) 
addEventHandler("onClientGUIClick", BuyAK, getAK, false) 
addEventHandler("onClientGUIClick", CloseButton, hidegui, false) 
end 
  
function hidegui() 
if guiGetVisible ( weapwindow ) then 
                -- if it is, we hide it 
                guiSetVisible ( weapwindow, false )          
                showCursor( false ) 
     end 
end 
  
addCommandHandler ( "weapons", showgui ) 
  
function getAK ( playerSource ) 
local money = getPlayerMoney ( client ) 
    if (money > 500) then    
    triggerServerEvent( "playerwantsAK", getLocalPlayer(), client) 
    else 
    outputChatBox("You don't have enough cash.", client,230,0,0) 
    end 
    end 
  
  

--Server  
addEvent("playerwantsAK",true) 
addEventHandler("playerwantsAK",getRootElement(), 
function (client) 
if getElementData( client, "hasAK") == true then 
giveWeaponAmmo(client, 30, 450) 
outputChatBox("You got ammo for: AK",source,0,230,0) 
else 
givetheAK = giveWeapon(client, 30, 400, true) 
if givetheAk == true then 
setElementData( client, "hasAK", true) 
outputChatBox("You now have a: AK",source,0,230,0) 
else 
outputChatBox("failed to give AK",source,0,230,0) 
   end 
  end 
 end 
) 
  

Posted

you aren't triggering any event in your script :roll::roll:

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
--Client  function showgui () 
weapwindow = guiCreateWindow(307,127,480,516,"Weapons Menu",false) 
BuyAK = guiCreateButton(95,76,117,59,"Ak47 - 500$",false,weapwindow) 
BuyM4 = guiCreateButton(96,154,116,57,"M4 - 600$",false,weapwindow) 
BuyMP5 = guiCreateButton(97,302,116,57,"MP5 - 400$",false,weapwindow) 
BuyUZI = guiCreateButton(96,227,116,57,"UZI - 350$",false,weapwindow) 
BuyShotgun = guiCreateButton(278,300,117,59,"Shotgun - 400$",false,weapwindow) 
BuyComShot = guiCreateButton(278,227,117,59,"Combat Shotgun - 450$",false,weapwindow) 
BuyDeagle = guiCreateButton(277,76,117,59,"Deagle - 200$",false,weapwindow) 
BuyPistol = guiCreateButton(277,152,117,59,"Pistol - 150$",false,weapwindow) 
CloseButton = guiCreateButton(180,375,108,41,"Close",false,weapwindow) 
Text_Memo = guiCreateMemo(97,435,260,45,"You can buy weapons here for in DM.",false,weapwindow) 
guiMemoSetReadOnly(Text_Memo,true) 
guiSetVisible ( weapwindow, true ) 
showCursor(true) 
addEventHandler("onClientGUIClick", BuyAK, getAK, false) 
addEventHandler("onClientGUIClick", CloseButton, hidegui, false) 
end 
  
function hidegui() 
if guiGetVisible ( weapwindow ) then 
                -- if it is, we hide it 
                guiSetVisible ( weapwindow, false )         
                showCursor( false ) 
     end 
end 
  
addCommandHandler ( "weapons", showgui ) 
  
function getAK ( playerSource ) 
local money = getPlayerMoney ( getLocalPlayer() ) 
    if (money > 500) then   
    triggerServerEvent( "playerwantsAK", getLocalPlayer(), getLocalPlayer()) 
    else 
    outputChatBox("You don't have enough cash.", 230,0,0) 
    end 
    end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
--Client  function showgui () 
weapwindow = guiCreateWindow(307,127,480,516,"Weapons Menu",false) 
BuyAK = guiCreateButton(95,76,117,59,"Ak47 - 500$",false,weapwindow) 
BuyM4 = guiCreateButton(96,154,116,57,"M4 - 600$",false,weapwindow) 
BuyMP5 = guiCreateButton(97,302,116,57,"MP5 - 400$",false,weapwindow) 
BuyUZI = guiCreateButton(96,227,116,57,"UZI - 350$",false,weapwindow) 
BuyShotgun = guiCreateButton(278,300,117,59,"Shotgun - 400$",false,weapwindow) 
BuyComShot = guiCreateButton(278,227,117,59,"Combat Shotgun - 450$",false,weapwindow) 
BuyDeagle = guiCreateButton(277,76,117,59,"Deagle - 200$",false,weapwindow) 
BuyPistol = guiCreateButton(277,152,117,59,"Pistol - 150$",false,weapwindow) 
CloseButton = guiCreateButton(180,375,108,41,"Close",false,weapwindow) 
Text_Memo = guiCreateMemo(97,435,260,45,"You can buy weapons here for in DM.",false,weapwindow) 
guiMemoSetReadOnly(Text_Memo,true) 
guiSetVisible ( weapwindow, true ) 
showCursor(true) 
addEventHandler("onClientGUIClick", BuyAK, getAK, false) 
addEventHandler("onClientGUIClick", CloseButton, hidegui, false) 
end 
  
function hidegui() 
if guiGetVisible ( weapwindow ) then 
                -- if it is, we hide it 
                guiSetVisible ( weapwindow, false )         
                showCursor( false ) 
     end 
end 
  
addCommandHandler ( "weapons", showgui ) 
  
function getAK ( playerSource ) 
local money = getPlayerMoney ( getLocalPlayer() ) 
    if (money > 500) then   
    triggerServerEvent( "playerwantsAK", getLocalPlayer(), getLocalPlayer()) 
    else 
    outputChatBox("You don't have enough cash.", 230,0,0) 
    end 
    end 

Thanks will try as soon as possible

EDIT: it Worked :P Thanks, again ( blue smiley ftw )

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