Kenix Posted March 31, 2011 Share Posted March 31, 2011 please help script perfectly working. I have a question how do I stop takeMoneyFunc if the player does not have this level? function skillButtonFunc (Levelids, Levelnames,Levelmoneys,LevelLevels ,LevelStatus) outputChatBox("skill buy") if (Levelids == "0") then outputChatBox("0") getThisElementData(4,source) takeMoneyFunc(3250,source) setPedStat(source, 71, 99) elseif (Levelids == "1") then getThisElementData(1,source) takeMoneyFunc(5500,source) setPedStat(source, 71, 299) end end addEvent ("PlayerSkillBuy", true) addEventHandler ("PlayerSkillBuy", getRootElement(),skillButtonFunc) function takeMoneyFunc(cashs,player) if (getPlayerMoney (player) >= cashs) then outputChatBox("skill buying") takePlayerMoney (player,cashs) else outputChatBox("you not have money ") end end function getThisElementData(tostring,player) if (getElementData (player,"Level") == tostring) then outputChatBox("level suitable") else outputChatBox("Level insufficient ") end end Link to comment
Antibird Posted March 31, 2011 Share Posted March 31, 2011 No guys do understand your question I suppose =/ Link to comment
Castillo Posted April 1, 2011 Share Posted April 1, 2011 This should work (tested) function skillButtonFunc (Levelids, Levelnames,Levelmoneys,LevelLevels ,LevelStatus) outputChatBox("skill buy") if (Levelids == "0" or Levelids == 0) then outputChatBox("0") getThisElementData(4,source) takeMoneyFunc(3250,4,source) setPedStat(source, 71, 99) elseif (Levelids == "1" or Levelids == 1) then getThisElementData(1,source) takeMoneyFunc(5500,1,source) setPedStat(source, 71, 299) end end addEvent ("PlayerSkillBuy", true) addEventHandler ("PlayerSkillBuy", getRootElement(),skillButtonFunc) function takeMoneyFunc(cashs,level,player) if (getPlayerMoney (player) >= tonumber(cashs)) then if getElementData(player,"Level") == tonumber(level) then outputChatBox("skill buying") takePlayerMoney (player,cashs) else end else outputChatBox("you not have money ") end end function getThisElementData(data,player) if (getElementData (player,"Level") == tonumber(data)) then outputChatBox("level suitable") return true else outputChatBox("Level insufficient ") return false end end Link to comment
Castillo Posted April 1, 2011 Share Posted April 1, 2011 No problem, always a pleasure to help Link to comment
Kenix Posted April 2, 2011 Author Share Posted April 2, 2011 guys i have new question in general, so I've done almost everything I wanted but I need to do that when the ability to buy something changed text guiGridList but I do not know how to get the player if he bought a skill or not and what kind of skill client event local localPlayer = getLocalPlayer() addEvent("selectSkill",true) addEventHandler( "selectSkill", localPlayer, function(rowIndex) outputChatBox("trigger called") guiGridListSetItemText(GUIEditor_Grid[211],rowIndex,5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211], rowIndex,5,0,255,0) outputChatBox("text change") end ) server function skillButtonFunc (Levelids, Levelnames,Levelmoneys,LevelLevels ,LevelStatus) outputChatBox("skill buy") if (Levelids == "0") then outputChatBox("0") getThisElementData(4,source) takeMoneyFunc(3250,4,source) triggerClientEvent(source, "selectSkill", source, 1) outputChatBox("trigger working") setPedStat(source, 71, 99) elseif (Levelids == "1") then getThisElementData(1,source) takeMoneyFunc(5500,1,source) triggerClientEvent(source, "selectSkill", source, 2) outputChatBox("trigger working") setPedStat(source, 71, 299) end end addEvent ("PlayerSkillBuy", true) addEventHandler ("PlayerSkillBuy", getRootElement(),skillButtonFunc) so I tested it but if you do not even have enough money, he still calls the event, and I think what you need as you get bought if the player skill number but I do not know how Link to comment
Castillo Posted April 2, 2011 Share Posted April 2, 2011 I can see an error here, local localPlayer = getLocalPlayer() addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), -- when you trigger an event from server side, you must use getRootElement() function(rowIndex) outputChatBox("trigger called") guiGridListSetItemText(GUIEditor_Grid[211],rowIndex,5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211], rowIndex,5,0,255,0) outputChatBox("text change") end ) Link to comment
Kenix Posted April 3, 2011 Author Share Posted April 3, 2011 ok but I did not understand how to do to get the skill function I do not know how to pass from a function skillButtonFunc a function getSkillFunc argument Levelids perhaps because of it not working. function getSkillFunc(player,Levelids) if (Levelids == tonumber) then local skillsID = tonumber triggerClientEvent(source, "selectSkill", source,skillsID) return true else return false end end getSkillFunc(1,source) addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), function(skillsID) if (skillsID == tonumber(1)) then guiGridListSetItemText(GUIEditor_Grid[211],1,5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211], 1,5,0,255,0) outputChatBox("text change 1") elseif (skillsID == tonumber(2)) then guiGridListSetItemText(GUIEditor_Grid[211],2,5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211],2,5,0,255,0) outputChatBox("text change 2") end end ) Link to comment
Castillo Posted April 3, 2011 Share Posted April 3, 2011 I'am not sure of what do you want to do, i assumed, you wanted to set the text of the purchased skill. addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), function(skillsID) if (tonumber(skillsID)) then guiGridListSetItemText(GUIEditor_Grid[211],tonumber(skillsID),5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211],tonumber(skillsID),5,0,255,0) outputChatBox("text change "..tonumber(skillsID)) end end ) Link to comment
Kenix Posted April 4, 2011 Author Share Posted April 4, 2011 I'am not sure of what do you want to do, i assumed, you wanted to set the text of the purchased skill. addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), function(skillsID) if (tonumber(skillsID)) then guiGridListSetItemText(GUIEditor_Grid[211],tonumber(skillsID),5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211],tonumber(skillsID),5,0,255,0) outputChatBox("text change "..tonumber(skillsID)) end end ) yes I meant it but getSkillFunc not working = ( Link to comment
Castillo Posted April 4, 2011 Share Posted April 4, 2011 I would like to know what should that function do, we're talking about getSkillFunc. I ask that because, what i seen makes totally no sense for me. Link to comment
Moderators Citizen Posted April 4, 2011 Moderators Share Posted April 4, 2011 function getSkillFunc(player,Levelids) if (Levelids == tonumber) then local skillsID = tonumber triggerClientEvent(source, "selectSkill", source,skillsID) return true else return false end end getSkillFunc(1,source) Ok, I found two errors: 1- The function is function getSkillFunc(player,Levelids) so why you made getSkillFunc(1,source) it's getSkillFunc(source,1) 2-Why your 'tonumber's are empty ? function getSkillFunc(player,Levelids) if ( Levelids ) then local skillsID = tonumber( Levelids ) triggerClientEvent(source, "selectSkill", source,skillsID) return true else return false end end And like Solidsnake, I don't understand what do you want to do exactly Link to comment
Wojak Posted April 4, 2011 Share Posted April 4, 2011 i like riddles function getSkillFunc(player,Levelids) local skillsID = tonumber( Levelids ) if skillsID then triggerClientEvent(player, "selectSkill", player, skillsID) return true else return false end end did I won? Link to comment
Moderators Citizen Posted April 4, 2011 Moderators Share Posted April 4, 2011 No you loose And it's not a joke: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() Link to comment
Wojak Posted April 4, 2011 Share Posted April 4, 2011 No you loose And it's not a joke: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() hmm i must be a little slow today - i dont understand you... you want to trigger event for all clients, but only add event in one client? i is like this triggerClientEvent( "selectSkill",player, skillsID) this triggerClientEvent(player, "selectSkill", skillsID) trigger the event for one client and set skillsID as source in a handler function... Link to comment
Kenix Posted April 4, 2011 Author Share Posted April 4, 2011 function getSkillFunc(player,Levelids) if (Levelids == tonumber) then local skillsID = tonumber triggerClientEvent(source, "selectSkill", source,skillsID) return true else return false end end getSkillFunc(1,source) Ok, I found two errors: 1- The function is function getSkillFunc(player,Levelids) so why you made getSkillFunc(1,source) it's getSkillFunc(source,1) 2-Why your 'tonumber's are empty ? function getSkillFunc(player,Levelids) if ( Levelids ) then local skillsID = tonumber( Levelids ) triggerClientEvent(source, "selectSkill", source,skillsID) return true else return false end end And like Solidsnake, I don't understand what do you want to do exactly This Works he Triggered to Client !!! YEEE THX MAN but client side not work addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), function(skillsID) outputChatBox("trigger Called YEE"..tostring(skillsID)) -- says nil else tonumber and if something does not work function wtf??? if (tonumber(skillsID)) then outputChatBox("1") guiGridListSetItemText(GUIEditor_Grid[211],tonumber(skillsID),5,"purchased",false,false) outputChatBox("2") guiGridListSetItemColor (GUIEditor_Grid[211],tonumber(skillsID),5,0,255,0) outputChatBox("text change "..tonumber(skillsID)) end end ) Link to comment
Moderators Citizen Posted April 4, 2011 Moderators Share Posted April 4, 2011 No you loose And it's not a joke: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() hmm i must be a little slow today - i dont understand you... you want to trigger event for all clients, but only add event in one client? i is like this triggerClientEvent( "selectSkill",player, skillsID) this triggerClientEvent(player, "selectSkill", skillsID) trigger the event for one client and set skillsID as source in a handler function... Where do you see that I want to trigger for all clients ? I want for only the corect client so: triggerClientEvent(player, "selectSkill", skillsID) but client side not work Because: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() Link to comment
Kenix Posted April 4, 2011 Author Share Posted April 4, 2011 No you loose And it's not a joke: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() hmm i must be a little slow today - i dont understand you... you want to trigger event for all clients, but only add event in one client? i is like this triggerClientEvent( "selectSkill",player, skillsID) this triggerClientEvent(player, "selectSkill", skillsID) trigger the event for one client and set skillsID as source in a handler function... Where do you see that I want to trigger for all clients ? I want for only the corect client so: triggerClientEvent(player, "selectSkill", skillsID) but client side not work Because: triggerClientEvent(player, "selectSkill", skillsID) The selectSkill function in client-side get only the skillsID. And when you are in the good client, then use getLocalPlayer() this is not working saying bad argument@`triggerClientEvent` but he saying text change 0 but he not changed text in gridlist client: function startShowingShopLevelMenu() showCursor(true) GUIEditor_Grid = {} MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) GUIEditor_Grid[211] = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) guiGridListSetSelectionMode(GUIEditor_Grid[211],1) for i = 1, 19 do guiGridListAddRow(GUIEditor_Grid[211]) end guiGridListAddColumn(GUIEditor_Grid[211],"ID",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Name",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"$",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Level",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Status",0.2) addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) for i,v in ipairs (skillsLevelsTable) do local row21 = guiGridListAddRow (GUIEditor_Grid[211]) guiGridListSetItemText (GUIEditor_Grid[211], row21, 1, v[1], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 2, v[2], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 3, v[3], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 4, v[4], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 5, v[5], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 6, v[6], false, true) end end table:(in client) skillsLevelsTable = { {"0","Deagle Easy Skill 1","3250","11"}, {"1","Deagle Normal Skill 2","5500","13"}, {"2","Deagle Hard Skill 3","8000","15"}, {"3","Deagle Very Hard Skill 4","15800","17"}, {"4","Deagle ~Pro~ Skill 5","21000","20"}, {"5","Shotgun Easy Skill 1 ","4500","12"}, {"6","Shotgun Normal Skill 2 ","8500","14"}, {"7","Shotgun Hard Skill 3","13000","16"}, {"8","Shotgun Very Hard Skill 4","15000","18"}, {"9","Shotgun ~Pro~ Skill 5","24000","21"}, {"10","SPAZ-12 Easy Skill 1 ","16500","22"}, {"11","SPAZ-12 Normal Skill 2 ","24500","28"}, {"12","SPAZ-12 Hard Skill 3 ","35500","32"}, {"13","SPAZ-12 Very Hard Skill 4 ","42500","36"}, {"14","SPAZ-12 ~Pro~ Skill 5 ","47500","40"}, {"15","MP5 Easy Skill 1 ","13130","16"}, {"16","MP5 Normal Skill 2 ","19450","19"}, {"17","MP5 Hard Skill 3 ","25500","23"}, {"18","MP5 Very Hard Skill 4 ","29330","26"}, {"19","MP5 ~Pro~ Skill 5 ","35000","29"}, {"20","AK-47 Easy Skill 1 ","15000","20"}, {"21","AK-47 Normal Skill 2 ","22500","24"}, {"22","AK-47 Hard Skill 3 ","27570","28"}, {"23","AK-47 Very Hard Skill 4 ","35130","32"}, {"24","AK-47 ~Pro~ Skill 5 ","43030","36"}, {"25","M4A1 Easy Skill 1 ","17110","25"}, {"26","M4A1 Normal Skill 2 ","25350","30"}, {"27","M4A1 Hard Skill 3 ","36100","35"}, {"28","M4A1 Very Hard Skill 4 ","44400","40"}, {"29","M4A1 ~Pro~ Skill 5 ","50000","45"} } Link to comment
Moderators Citizen Posted April 4, 2011 Moderators Share Posted April 4, 2011 Yeah sorry my bad I was a bad syntax of the triggerClientEvent in my mind sorry client: function startShowingShopLevelMenu() showCursor(true) GUIEditor_Grid = {} MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) GUIEditor_Grid[211] = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) guiGridListSetSelectionMode(GUIEditor_Grid[211],1) ------- Remove this: ------------- -- for i = 1, 19 do -- guiGridListAddRow(GUIEditor_Grid[211]) -- end ---------------------------------- guiGridListAddColumn(GUIEditor_Grid[211],"ID",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Name",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"$",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Level",0.2) guiGridListAddColumn(GUIEditor_Grid[211],"Status",0.2) addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) for i,v in ipairs (skillsLevelsTable) do local row21 = guiGridListAddRow (GUIEditor_Grid[211]) guiGridListSetItemText (GUIEditor_Grid[211], row21, 1, v[1], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 2, v[2], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 3, v[3], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 4, v[4], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 5, v[5], false, true) guiGridListSetItemText (GUIEditor_Grid[211], row21, 6, v[6], false, true) end end server: function getSkillFunc(player,Levelids) if ( Levelids ) then local skillsID = tonumber( Levelids ) triggerClientEvent(source, "selectSkill", getRootElement() ,skillsID) return true else return false end end Link to comment
Kenix Posted April 4, 2011 Author Share Posted April 4, 2011 text does not change in gridList Link to comment
Moderators Citizen Posted April 4, 2011 Moderators Share Posted April 4, 2011 Any errors ? Try this for debug: guiGridListSetItemText(GUIEditor_Grid[211],10,5,"purchased",false,false) Link to comment
Kenix Posted April 5, 2011 Author Share Posted April 5, 2011 Any errors ?Try this for debug: guiGridListSetItemText(GUIEditor_Grid[211],10,5,"purchased",false,false) no change WTF??? i create this for test and this working but text not change local textSkill = "purchased" local textt = guiGridListSetItemText(MainGrid,1,5,textSkill,false,false) outputChatBox("text:"..tostring(textt).." , "..tostring(textSkill)) he say text: true , purchased WTF what the problem?? MainGrid = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) Link to comment
Castillo Posted April 5, 2011 Share Posted April 5, 2011 With: function getSkillFunc(player,Levelids) if ( Levelids ) then local skillsID = tonumber( Levelids ) triggerClientEvent(player, "selectSkill", getRootElement() ,skillsID) return true else return false end end And this: addEvent("selectSkill",true) addEventHandler( "selectSkill", getRootElement(), function(skillsID) if (tonumber(skillsID)) then guiGridListSetItemText(GUIEditor_Grid[211],tonumber(skillsID),5,"purchased",false,false) guiGridListSetItemColor (GUIEditor_Grid[211],tonumber(skillsID),5,0,255,0) outputChatBox("text change "..tonumber(skillsID)) end end ) it works perfectly, take a look at this screenshot. http://img855.imageshack.us/i/mtascreen ... 82115.png/ 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