Fabio(GNR) Posted January 2, 2011 Share Posted January 2, 2011 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 ) Link to comment
Castillo Posted January 3, 2011 Share Posted January 3, 2011 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 ) Link to comment
Fabio(GNR) Posted January 3, 2011 Author Share Posted January 3, 2011 why don't you just use giveWeapon for everything? it gives the ammo too. but this doesnt fix anything for passing the element right?? Thanks tough Link to comment
jkub Posted January 3, 2011 Share Posted January 3, 2011 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. Link to comment
Castillo Posted January 3, 2011 Share Posted January 3, 2011 triggerServerEvent ( getLocalPlayer(), "nameOfYourEvent", getLocalPlayer(), elementToPass ) the first getLocalPlayer() in client side is not needed if i'm right (at least i never use it) Link to comment
Fabio(GNR) Posted January 3, 2011 Author Share Posted January 3, 2011 (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 January 3, 2011 by Guest Link to comment
Castillo Posted January 3, 2011 Share Posted January 3, 2011 function (myevent,myevent2,myevent3) its easy o_O Link to comment
Fabio(GNR) Posted January 3, 2011 Author Share Posted January 3, 2011 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 ) Link to comment
Castillo Posted January 3, 2011 Share Posted January 3, 2011 you aren't triggering any event in your script Link to comment
Fabio(GNR) Posted January 3, 2011 Author Share Posted January 3, 2011 you aren't triggering any event in your script hehe please re-read i kinda forgot the latest function Link to comment
Castillo Posted January 3, 2011 Share Posted January 3, 2011 --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 Link to comment
Fabio(GNR) Posted January 3, 2011 Author Share Posted January 3, 2011 --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 Thanks, again ( blue smiley ftw ) 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