Agon Posted February 1, 2012 Share Posted February 1, 2012 function installEverything() local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 0) end addEventHandler("onResourceStart" getResourceRootElement(getThisResource()), installEverything) function gunWindow() buyGun_Window[1] = guiCreateWindow(374,104,346,519,"Select Your Weapon",false) guiWindowSetSizable(buyGun_Window[1],false) weaponList_Grid[1] = guiCreateGridList(11,31,324,435,false,buyGun_Window[1]) guiGridListSetSelectionMode(weaponList_Grid[1],2) weaponAccept_Button[1] = guiCreateButton(12,477,118,33,"Accept",false,buyGun_Window[1]) weaponCancel_Button[2] = guiCreateButton(213,477,118,31,"Cancel",false,buyGun_Window[1]) end addEventHandler("onMarkerHit", bankWeaponMarker, gunWindow) and this is my list but don't know how to put it in this... type="weapons"> "Melee"> "5" price="25" level="1" name="Baseball bat" /> "9" price="250" level="1" name="Chainsaw" /> "8" price="150" level="1" name="Katana" /> "4" price="30" level="1" name="Knife" /> "6" price="10" level="1" name="Shovel" /> "Handguns"> "24" price="350" level="3" name="Desert eagle" /> "22" price="300" level="1" name="Pistol" /> "23" price="250" level="1" name="Silenced" /> "Shotguns"> "26" price="850" level="4" name="Sawn-off shotgun" /> "25" price="700" level="6" name="Shotgun" /> "27" price="550" level="6" name="SPAZ-12" /> "Sub-machine guns"> "29" price="500" level="9" name="MP5" /> "32" price="700" level="12" name="TEC-9" /> "28" price="850" level="12" name="Uzi" /> "Machine guns"> "30" price="1500" level="15" name="AK47" /> "31" price="1250" level="15" name="M4" /> "Rifles"> "33" price="2000" level="20" name="Country sniper" /> "34" price="3000" level="20" name="Sniper" /> When I hit that marker, I want to popup that window and i can do it. but can't put list in it. and this is a little bit confusing. i put a level system in it. if my level or money is lower then weapon i've chosen, i want it not to give me the weapon. seems very confusing and I'm confused... please help Link to comment
TAPL Posted February 1, 2012 Share Posted February 1, 2012 Event onResourceStart is Server-side Event onMarkerHit is Server-side Function guiCreateWindow is Client-side Function guiWindowSetSizable is Client-side Function guiCreateGridList is Client-side Function guiGridListSetSelectionMode is Client-side Function guiCreateButton is Client-side you should use Events onClientResourceStart and onClientMarkerHit Link to comment
Agon Posted February 2, 2012 Author Share Posted February 2, 2012 Do i need to trigger events? because my markers will be server side but gui will be client side.. Link to comment
TAPL Posted February 2, 2012 Share Posted February 2, 2012 you can do trigger or you can create the markers server side and using the event onClientMarkerHit from client side Link to comment
Agon Posted February 2, 2012 Author Share Posted February 2, 2012 ---Server-side function installEverything() local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 0) end addEvent("hitTheMarker", true) addEventHandler("hitTheMarker", getResourceRootElement(getThisResource)), installEverything) ---Client-side function gunWindow() triggerServerEvent ( "hitTheMarker", bankWeaponMarker, gunWindow ) buyGun_Window[1] = guiCreateWindow(374,104,346,519,"Select Your Weapon",false) guiWindowSetSizable(buyGun_Window[1],false) weaponList_Grid[1] = guiCreateGridList(11,31,324,435,false,buyGun_Window[1]) guiGridListSetSelectionMode(weaponList_Grid[1],2) weaponAccept_Button[1] = guiCreateButton(12,477,118,33,"Accept",false,buyGun_Window[1]) weaponCancel_Button[2] = guiCreateButton(213,477,118,31,"Cancel",false,buyGun_Window[1]) end addEventHandler("onMarkerHit", bankWeaponMarker, gunWindow) like this? Link to comment
JR10 Posted February 2, 2012 Share Posted February 2, 2012 This is so messed up. Server: local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 0) function installEverything(hElement) triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end addEventHandler("onMarkerHit", bankWeaponMarker, installEverything) client: function gunWindow() buyGun_Window[1] = guiCreateWindow(374,104,346,519,"Select Your Weapon",false) guiWindowSetSizable(buyGun_Window[1],false) weaponList_Grid[1] = guiCreateGridList(11,31,324,435,false,buyGun_Window[1]) guiGridListSetSelectionMode(weaponList_Grid[1],2) weaponAccept_Button[1] = guiCreateButton(12,477,118,33,"Accept",false,buyGun_Window[1]) weaponCancel_Button[2] = guiCreateButton(213,477,118,31,"Cancel",false,buyGun_Window[1]) end addEvent("hitTheMarker", true) addEventHandler("hitTheMarker", root, gunWindow) Link to comment
Agon Posted February 2, 2012 Author Share Posted February 2, 2012 Your server side doesn't create marker(i think it's my fault ) I made this but when i go to marker, gui doesn't appear ----Server Side function createMyMarker() local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 255) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), createMyMarker) function installEverything(hElement) triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end addEventHandler("onMarkerHit", bankWeaponMarker, installEverything) it says " line 9 bad argument @ addEventHandler [expected element at argument 2, got nil] Clientside is same with yours.. Link to comment
JR10 Posted February 2, 2012 Share Posted February 2, 2012 Mine does work, yours will too, but the variable bankWeaponMarker is local inside createMyMarker function, so it can only be used inside createMyMarker. function createMyMarker() bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 255) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), createMyMarker) function installEverything(hElement) triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end addEventHandler("onMarkerHit", bankWeaponMarker, installEverything) I changed bankWeaponMarker variable to global, so it can be used everywhere in the script. Link to comment
Agon Posted February 2, 2012 Author Share Posted February 2, 2012 gui doesn't appear it still says " line 9 bad argument @ addEventHandler [expected element at argument 2, got nil] " Link to comment
JR10 Posted February 2, 2012 Share Posted February 2, 2012 local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1, 0, 0, 255, 255) function installEverything(hElement) triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end addEventHandler("onMarkerHit", bankWeaponMarker, installEverything) Link to comment
Agon Posted February 2, 2012 Author Share Posted February 2, 2012 still can't see the gui Link to comment
Castillo Posted February 2, 2012 Share Posted February 2, 2012 -- client side: function gunWindow() buyGun_Window = {} weaponList_Grid = {} weaponAccept_Button = {} weaponCancel_Button = {} buyGun_Window[1] = guiCreateWindow(374,104,346,519,"Select Your Weapon",false) guiWindowSetSizable(buyGun_Window[1],false) weaponList_Grid[1] = guiCreateGridList(11,31,324,435,false,buyGun_Window[1]) guiGridListSetSelectionMode(weaponList_Grid[1],2) weaponAccept_Button[1] = guiCreateButton(12,477,118,33,"Accept",false,buyGun_Window[1]) weaponCancel_Button[2] = guiCreateButton(213,477,118,31,"Cancel",false,buyGun_Window[1]) end addEvent("hitTheMarker", true) addEventHandler("hitTheMarker", root, gunWindow) -- server side: local bankWeaponMarker=createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1.5, 0, 0, 255, 255) function installEverything(hElement) triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end addEventHandler("onMarkerHit", bankWeaponMarker, installEverything) Link to comment
GanJaRuleZ Posted February 2, 2012 Share Posted February 2, 2012 function buyGuiVisible( element,matchingDimension ) if matchingDimension and getElementType( element ) == "player" then triggerClientEvent ( hElement,"hitTheMarker" ,hElement) end end addEventHandler("onMarkerHit",bankWeaponMarker,buyGuiVisible ) Try it Link to comment
Agon Posted February 3, 2012 Author Share Posted February 3, 2012 Thank you Solidsnake it works. but how can i add gridlist? i have weapons.xml but i don't know how to add the list into gui.. Link to comment
Kenix Posted February 3, 2012 Share Posted February 3, 2012 Client side: addEvent( "hitTheMarker", true ) buyGun_Window = { } weaponList_Grid = { } weaponAccept_Button = { } weaponCancel_Button = { } function gunWindow( ) buyGun_Window[1] = guiCreateWindow( 374,104,346,519,"Select Your Weapon",false ) guiWindowSetSizable( buyGun_Window[1],false ) weaponList_Grid[1] = guiCreateGridList( 11,31,324,435,false,buyGun_Window[1] ) guiGridListSetSelectionMode( weaponList_Grid[1],2 ) local weapon = guiGridListAddColumn( playerList, "Weapon name", 0.85 ) local id = guiGridListAddColumn( playerList, "ID", 0.85 ) local file = xmlLoadFile ( "weapons.xml" ) local info = xmlFindChild ( file, "weapon", 0 ) if info then for i,v in pairs( xmlNodeGetAttributes ( info ) ) do local row = guiGridListAddRow ( weaponList_Grid[1] ) guiGridListSetItemText( weaponList_Grid[1],row,weapon,i,false,false ) guiGridListSetItemText( weaponList_Grid[1],row,id,v,false,false ) end end xmlUnloadFile ( file ) weaponAccept_Button[1] = guiCreateButton( 12,477,118,33,"Accept",false,buyGun_Window[1] ) weaponCancel_Button[2] = guiCreateButton( 213,477,118,31,"Cancel",false,buyGun_Window[1] ) end addEventHandler( "hitTheMarker", root, gunWindow ) Server side: local bankWeaponMarker = createMarker(2304.19921875, -16.19921875, 25.5, "cylinder", 1.5, 0, 0, 255, 255) function installEverything( hElement ) if getElementType( hElement ) == "player" then triggerClientEvent ( hElement,"hitTheMarker" ,hElement ) end end addEventHandler( "onMarkerHit", bankWeaponMarker, installEverything ) weapons.xml <root> <weapon id="1" name="Brass knuckles" /> <weapon id="5" name="Baseball bat" /> <weapon id="15" name="Cane" /> <weapon id="9" name="Chainsaw" /> <weapon id="2" name="Golf club" /> <weapon id="7" name="Pool cue" /> <weapon id="8" name="Katana" /> <weapon id="4" name="Knife" /> <weapon id="3" name="Nightstick" /> <weapon id="6" name="Shovel" /> <weapon id="24" name="Desert eagle" /> <weapon id="22" name="Pistol" /> <weapon id="23" name="Silenced" /> <weapon id="26" name="Sawn-off shotgun" /> <weapon id="25" name="Shotgun" /> <weapon id="27" name="SPAZ-12" /> <weapon id="29" name="MP5" /> <weapon id="32" name="TEC-9" /> <weapon id="28" name="Uzi" /> <weapon id="30" name="AK47" /> <weapon id="31" name="M4" /> <weapon id="33" name="Country sniper" /> <weapon id="34" name="Sniper" /> <weapon id="37" name="Flame thrower" /> <weapon id="36" name="Heat seeking RPG" /> <weapon id="38" name="Minigun" /> <weapon id="35" name="Rocket launcher" /> <weapon id="16" name="Grenade" /> <weapon id="18" name="Molotov" /> <weapon id="39" name="Satchel" /> <weapon id="40" name="Satchel detonator" /> <weapon id="17" name="Tear gas" /> <weapon id="43" name="Camera" /> <weapon id="42" name="Fire extinguisher" /> <weapon id="45" name="Infrared goggles" /> <weapon id="44" name="Night vision goggles" /> <weapon id="46" name="Parachute" /> <weapon id="14" name="Flowers" /> <weapon id="10" name="Long dildo" /> <weapon id="11" name="Short dildo" /> <weapon id="12" name="Vibrator" /> </root> Updated again. Link to comment
Agon Posted February 3, 2012 Author Share Posted February 3, 2012 everything is ok but weapons.xml doesn't appear tried them but list didn't appear Link to comment
Kenix Posted February 3, 2012 Share Posted February 3, 2012 https://wiki.multitheftauto.com/wiki/Meta.xml <meta> <script src="s.lua" type="server" /> <!-- server side script --> <script src="c.lua" type="client" /> <!-- client side script --> </meta> Link to comment
Agon Posted February 3, 2012 Author Share Posted February 3, 2012 i know that but list doesn't appear i tried everything but didn't work.. Link to comment
Agon Posted February 4, 2012 Author Share Posted February 4, 2012 I made this so far with some help of the wiki: <catalog type="weapons"> <group name="Melee"> <weapon id="5" price="25" level="1" name="Baseball bat" /> <weapon id="9" price="250" level="1" name="Chainsaw" /> <weapon id="8" price="150" level="1" name="Katana" /> <weapon id="4" price="30" level="1" name="Knife" /> <weapon id="6" price="10" level="1" name="Shovel" /> </group> <group name="Handguns"> <weapon id="24" price="350" level="3" name="Desert eagle" /> <weapon id="22" price="300" level="1" name="Pistol" /> <weapon id="23" price="250" level="1" name="Silenced" /> </group> <group name="Shotguns"> <weapon id="26" price="850" level="4" name="Sawn-off shotgun" /> <weapon id="25" price="700" level="6" name="Shotgun" /> <weapon id="27" price="550" level="6" name="SPAZ-12" /> </group> <group name="Sub-machine guns"> <weapon id="29" price="500" level="9" name="MP5" /> <weapon id="32" price="700" level="12" name="TEC-9" /> <weapon id="28" price="850" level="12" name="Uzi" /> </group> <group name="Machine guns"> <weapon id="30" price="1500" level="15" name="AK47" /> <weapon id="31" price="1250" level="15" name="M4" /> </group> <group name="Rifles"> <weapon id="33" price="2000" level="20" name="Country sniper" /> <weapon id="34" price="3000" level="20" name="Sniper" /> </group> </catalog> ---Serverside addEvent( "hitTheMarker", true ) buyGun_Window = { } weaponList_Grid = { } weaponAccept_Button = { } weaponCancel_Button = { } function gunWindow( ) buyGun_Window = guiCreateWindow( 374,104,346,519,"Select Your Weapon",false ) guiWindowSetSizable( buyGun_Window,false ) weaponList_Grid = guiCreateGridList( 11,31,324,435,false,buyGun_Window ) guiGridListSetSelectionMode( weaponList_Grid,2 ) weaponAccept_Button = guiCreateButton( 12,477,118,33,"Accept",false,buyGun_Window ) weaponCancel_Button = guiCreateButton( 213,477,118,31,"Cancel",false,buyGun_Window ) showCursor(true, true) local id = guiGridListAddColumn( playerList, "ID", 0.85 ) local price = guiGridListAddColumn( playerList, "Price", 0.85 ) local level = guiGridListAddColumn( playerList, "Level", 0.85) local wname = guiGridListAddColumn( playerList, "Weapon name", 0.85 ) local file = xmlLoadFile ( "weapons.xml" ) weaponTable = {} if weapon then for _,group in ipairs(xmlNodeGetChildren(file)) do local row = guiGridListAddRow ( weaponList_Grid ) local name = xmlNodeGetAttribute(group,"type") weaponTable[name] = {} guiGridListSetItemText(weaponList_Grid,row,1,name,false,false) guiGridListSetItemData(weaponList_Grid,row,1,"header") for _,weapon in ipairs(xmlNodeGetChildren(group)) do local id = xmlNodeGetAttribute(weapon,"id") local price = xmlNodeGetAttribute(weapon,"price") local level = xmlNodeGetAttribute(weapon,"level") local wname = xmlNodeGetAttribute(weapon,"name") table.insert(weaponTable[name],{id,price,level,wname}) end end setElementData(weaponList_Grid,"expanded","none") xmlUnloadFile ( file ) end addEventHandler( "hitTheMarker", root, gunWindow ) function giveMeWeapon(weaponid) if weaponid then giveWeapon(source, weaponid, 500) end end addEvent("giveWeaponFromGUI",true) addEventHandler("giveWeaponFromGUI",root,giveMeWeapon) function processDoubleClick(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(weaponList_Grid) if row and col and row ~= -1 and col ~= -1 then if guiGridListGetItemData(weaponList_Grid,row,col) == "header" then local selected = guiGridListGetItemText(weaponList_Grid,row,col) changeGridlistState(selected) end end end end function changeGridlistState(group) if group then if getElementData(weaponList_Grid,"expanded") == group then guiGridListClear(weaponList_Grid) for group,_ in pairs(weaponTable) do local row = guiGridListAddRow(weaponList_Grid) guiGridListSetItemText(weaponList_Grid,row,1,group,false,false) guiGridListSetItemData(weaponList_Grid,row,1,"header") end setElementData(weaponList_Grid,"expanded","none") else guiGridListClear(weaponList_Grid) local row = guiGridListAddRow(weaponList_Grid) guiGridListSetItemText(weaponList_Grid,row,1,group,false,false) guiGridListSetItemData(weaponList_Grid,row,1,"header") for _,weapon in ipairs(weaponTable[group]) do row = guiGridListAddRow(weaponList_Grid) guiGridListSetItemText(weaponList_Grid,row,1,"- "..weapon[2],false,false) guiGridListSetItemText(weaponList_Grid,row,2,getWeaponType(tonumber(weapon[1])),false,false) guiGridListSetItemData(weaponList_Grid,row,1,tostring(weapon[1])) end setElementData(weaponList_Grid,"expanded",group) end end end --- Clientside function giveMeWeaponHandler(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(weaponList_Grid) if row and col and row ~= -1 and col ~= -1 then local selected = guiGridListGetItemData(weaponList_Grid,row,col) selected = tonumber(selected) if selected then triggerServerEvent("giveWeaponFromGUI",getRootElement(),selected,x,y,z) guiSetVisible(buyGun_Window,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a weapon.") end end end but it seems it doesn't work... Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 Maybe because you got almost all the client side in the server side? -- client side: function gunWindow( ) buyGun_Window = guiCreateWindow( 374,104,346,519,"Select Your Weapon",false ) guiWindowSetSizable( buyGun_Window,false ) weaponList_Grid = guiCreateGridList( 11,31,324,435,false,buyGun_Window ) weaponAccept_Button = guiCreateButton( 12,477,118,33,"Accept",false,buyGun_Window ) addEventHandler("onClientGUIClick",weaponAccept_Button,giveMeWeaponHandler,false) weaponCancel_Button = guiCreateButton( 213,477,118,31,"Cancel",false,buyGun_Window ) addEventHandler("onClientGUIClick",weaponAccept_Button, function () guiSetVisible(buyGun_Window,false) showCursor(false,false) end, false) local id = guiGridListAddColumn( weaponList_Grid, "ID", 0.85 ) local price = guiGridListAddColumn( weaponList_Grid, "Price", 0.85 ) local level = guiGridListAddColumn( weaponList_Grid, "Level", 0.85) local wname = guiGridListAddColumn( weaponList_Grid, "Weapon name", 0.85 ) local file = xmlLoadFile ( "weapons.xml" ) if (file) then for _,group in ipairs(xmlNodeGetChildren(file)) do local row = guiGridListAddRow(weaponList_Grid) local name = xmlNodeGetAttribute(group,"name") guiGridListSetItemText(weaponList_Grid,row,1,name,true,false) for _,weapon in ipairs(xmlNodeGetChildren(group)) do local row = guiGridListAddRow(weaponList_Grid) local id = xmlNodeGetAttribute(weapon,"id") local name = xmlNodeGetAttribute(weapon,"name") local price = xmlNodeGetAttribute(weapon,"price") local level = xmlNodeGetAttribute(weapon,"level") guiGridListSetItemText(weaponList_Grid,row,1,id,false,false) guiGridListSetItemText(weaponList_Grid,row,2,price,false,false) guiGridListSetItemText(weaponList_Grid,row,3,level,false,false) guiGridListSetItemText(weaponList_Grid,row,4,name,false,false) end end end showCursor(true, true) setElementData(weaponList_Grid,"expanded","none") xmlUnloadFile ( file ) end addEvent( "hitTheMarker", true ) addEventHandler( "hitTheMarker", root, gunWindow ) function giveMeWeaponHandler(button,state) if (button == "left" and state == "up") then local row,col = guiGridListGetSelectedItem(weaponList_Grid) if (row and col and row ~= -1 and col ~= -1) then local selected = guiGridListGetItemText(weaponList_Grid,row,col) local selected = tonumber(selected) if selected then triggerServerEvent("giveWeaponFromGUI",localPlayer,selected) guiSetVisible(buyGun_Window,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a weapon.") end end end -- server side: function giveMeWeapon(weaponid) if weaponid then giveWeapon(source, weaponid, 500, true) end end addEvent("giveWeaponFromGUI",true) addEventHandler("giveWeaponFromGUI",root,giveMeWeapon) 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