Kenix Posted March 21, 2011 Share Posted March 21, 2011 So just do the script works but when people comes to record labels, etc do not appear but after restart everything is working standards is the problem I think with onClientResourceStart please help anyone faced with this problem. client local gme = getLocalPlayer() addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) local EXP1 = getElementData(gme,"Experience:",tostring) local Level1 = getElementData(gme,"Level:",tostring) local exptolevel1 = getElementData(gme,"NextLevel:",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) end ) addEventHandler ( "onClientElementDataChange", gme, function ( dataName, player ) local EXP2 = getElementData(gme,"Experience:",tostring) local Level2 = getElementData(gme,"Level:",tostring) local exptolevel2 = getElementData(gme,"NextLevel:",tostring) guiSetText ( EXPLabel, "EXP: "..EXP2.." / "..exptolevel2) guiSetText ( LevelsLabel, "Level: "..Level2) end ) server function JoinStartLevel() -- готово local EXP = setElementData(source,"Experience:",0) local Level = setElementData(source,"Level:",1) local exptolevel = setElementData ( source, "NextLevel:", 25 ) outputDebugString("PLayer Join "..tostring(EXP,Level,exptolevel)) end addEventHandler("onPlayerJoin", getRootElement(),JoinStartLevel) Link to comment
proracer Posted March 21, 2011 Share Posted March 21, 2011 From first point I can see that you use wrong arguments in getElementData. Link to comment
Dre-+- Posted March 21, 2011 Share Posted March 21, 2011 I think it fixed: client local gme = getLocalPlayer() addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) local EXP1 = getElementData(gme,"Experience:") local Level1 = getElementData(gme,"Level:") local exptolevel1 = getElementData(gme,"NextLevel:") outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) end ) addEventHandler ( "onClientElementDataChange", gme, function ( dataName, player ) local EXP2 = getElementData(gme,"Experience:") local Level2 = getElementData(gme,"Level:") local exptolevel2 = getElementData(gme,"NextLevel:") guiSetText ( EXPLabel, "EXP: "..EXP2.." / "..exptolevel2) guiSetText ( LevelsLabel, "Level: "..Level2) end ) Link to comment
Kenix Posted March 21, 2011 Author Share Posted March 21, 2011 No not all the same when I go, nothing appears Link to comment
Moderators Citizen Posted March 21, 2011 Moderators Share Posted March 21, 2011 I already seen this problem with another scripter that I help him. The problem is in your ElementData's name because he don't support the : Replace for exemple this: getElementData(gme,"Experience:") by this: getElementData(gme,"Experience") ( so the setElementData too ) If you use Notepad++, you can replace it easily: Ctrl+H and the "Replace All" button Link to comment
Kenix Posted March 21, 2011 Author Share Posted March 21, 2011 thanks for the advice, I use notepad + + but it still shows Labels just after the restart of the resource Link to comment
Moderators Citizen Posted March 21, 2011 Moderators Share Posted March 21, 2011 When do you want that this labels appears ? Link to comment
Kenix Posted March 21, 2011 Author Share Posted March 21, 2011 when a player join the server but gooey not appear if you dont use an event onClientPlayerJoin , only onClientResourceStart. Link to comment
Moderators Citizen Posted March 21, 2011 Moderators Share Posted March 21, 2011 so if you use the onClientPlayerJoin, it doesn't work ? Other way: addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( not getElementData( getLocalPlayer(), "Joined" ) ) then return end local EXP1 = getElementData(gme,"Experience",tostring) local Level1 = getElementData(gme,"Level",tostring) local exptolevel1 = getElementData(gme,"NextLevel",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) setElementData( getLocalPlayer(), "Joined", true ) end ) All setElementData are destroyed when a player quit the server. Link to comment
Castillo Posted March 22, 2011 Share Posted March 22, 2011 so if you use the onClientPlayerJoin, it doesn't work ?Other way: addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( not getElementData( getLocalPlayer(), "Joined" ) ) then return end local EXP1 = getElementData(gme,"Experience",tostring) local Level1 = getElementData(gme,"Level",tostring) local exptolevel1 = getElementData(gme,"NextLevel",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) setElementData( getLocalPlayer(), "Joined", true ) end ) All setElementData are destroyed when a player quit the server. onClientPlayerJoin is not triggered for the client. Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 I know Here on this I use onClientResourceStart Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 so if you use the onClientPlayerJoin, it doesn't work ?Other way: addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( not getElementData( getLocalPlayer(), "Joined" ) ) then return end local EXP1 = getElementData(gme,"Experience",tostring) local Level1 = getElementData(gme,"Level",tostring) local exptolevel1 = getElementData(gme,"NextLevel",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) setElementData( getLocalPlayer(), "Joined", true ) end ) All setElementData are destroyed when a player quit the server. not working Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 not working Sorry I made a big error addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( getElementData( getLocalPlayer(), "Joined" ) ) then return end local EXP1 = getElementData(gme,"Experience",tostring) local Level1 = getElementData(gme,"Level",tostring) local exptolevel1 = getElementData(gme,"NextLevel",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) setElementData( getLocalPlayer(), "Joined", true ) end ) Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 No, again just after the restart of the resource works ... Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 Mmmm that's strange, try this: addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( getElementData( getLocalPlayer(), "Joined" ) ~= true ) then local EXP1 = getElementData(gme,"Experience",tostring) local Level1 = getElementData(gme,"Level",tostring) local exptolevel1 = getElementData(gme,"NextLevel",tostring) outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..Level1,true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..EXP1.." / "..exptolevel1,true) setElementData( getLocalPlayer(), "Joined", true ) end end ) Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 the same labels are not visible Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 outputChatBox write: Player Resource start false false false userdata: 00001FB2 Player Element Data Change 0 false false userdata: 00001FB2 Player Element Data Change 0 1 false userdata: 00001FB2 Player Element Data Change 0 1 25 userdata: 00001FB2 addEventHandler ( "onClientElementDataChange", gme, function ( dataName, player ) local EXP2 = getElementData(gme,"Experience") local Level2 = getElementData(gme,"Level") local exptolevel2 = getElementData(gme,"NextLevel") outputChatBox ( "Player Element Data Change "..tostring(EXP2).." "..tostring(Level2).." "..tostring(exptolevel2).." "..tostring(gme)) guiSetText ( EXPLabel, "EXP "..EXP2.." / "..exptolevel2) guiSetText ( LevelsLabel, "Level "..Level2) end ) Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 Server: function JoinStartLevel() local EXP = setElementData(source,"Experience",0) local Level = setElementData(source,"Level",1) local exptolevel = setElementData ( source, "NextLevel", 25 ) outputDebugString("PLayer Join "..tostring(EXP,Level,exptolevel)) end addEventHandler("onPlayerJoin", getRootElement(),JoinStartLevel) Client: addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function( ) if ( getElementData( getLocalPlayer(), "Joined" ) ~= true ) then local EXP1 = getElementData(gme,"Experience") local Level1 = getElementData(gme,"Level") local exptolevel1 = getElementData(gme,"NextLevel") outputChatBox ( "Player Resource start "..tostring(EXP1).." "..tostring(Level1).." "..tostring(exptolevel1).." "..tostring(gme)) LevelsLabel = guiCreateLabel(0.8578,0.6104,0.125,0.0244,"Level: "..tostring(Level1),true) EXPLabel = guiCreateLabel(0.8578,0.6387,0.125,0.0244,"EXP: "..tostring(EXP1).." / "..tostring(exptolevel1),true) setElementData( getLocalPlayer(), "Joined", true ) end end ) Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 it WORKS huge thank you brother. Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 please help script does not work. Tablelevels = {} Tablelevels[1] = { "25", "100"} Tablelevels[2] = { "100", "150"} Tablelevels[3] = { "150", "200"} Tablelevels[4] = { "200", "500"} function Thislevelup() local dataElement1 = getElementData(source,"Experience") if tostring(dataElement1) == tostring(Tablelevels[1]) then local addLevel = getElementData(source,"Level") or 0 addLevel = addLevel +1 setElementData( source, "Level", addLevel ) local addNextLevel = getElementData(source,"NextLevel") or 0 addNextLevel = addNextLevel + tostring(Tablelevels[2]) setElementData( source, "NextLevel", addNextLevel ) outputChatBox("New Level") end end addEventHandler("onElementDataChange",getRootElement(),Thislevelup) Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 So... If you want to retreive a value from a table, you have to do: Tablelevels[theRow][theColumn]! The final code: Tablelevels = {} Tablelevels[0] = { "25", "100"} Tablelevels[1] = { "100", "150"} Tablelevels[2] = { "150", "200"} Tablelevels[3] = { "200", "500"} function Thislevelup() local dataElement1 = getElementData(source,"Experience") for k,i in ipairs( Tablelevels ) do if tostring(dataElement1) == tostring(Tablelevels[k][1]) then local addLevel = getElementData(source,"Level") or 0 addLevel = tonumber(addLevel)+1 -- tonumber for security setElementData( source, "Level", addLevel ) local addNextLevel = getElementData(source,"NextLevel") or 0 addNextLevel = addNextLevel + tonumber(Tablelevels[k][2]) setElementData( source, "NextLevel", addNextLevel ) outputChatBox("New Level") end end end addEventHandler("onElementDataChange",getRootElement(),Thislevelup) You want to retreive the row where the player's experience correspond: For exemple: if the player's experience is 25, so the good line is Tablelevels[0]. So you test each table line like this: for k,i in ipairs( Tablelevels ) do -- k start to 0 ( so I start your table with 0 ) if tostring(dataElement1) == tostring(Tablelevels[k][1]) then -- ( 1st loop k=0 ) if "25" == Tablelevels[0][1] then => if "25" == "25" then outputChatBox("New Level") addNextLevel = addNextLevel + tonumber(Tablelevels[k][2]) -- ( 1st loop k=0 ) so: tonumber(Tablelevels[0][2]) => tonumber( "100" ) ( You can't increment 2 strings, so you have to make tonumber instead of tostring ) end end Link to comment
Kenix Posted March 22, 2011 Author Share Posted March 22, 2011 does not work and I have a question when I use this event and then trigger and chatBox repeated as I clean it Here for example is a simple script at the start of a new level, he starts spamming. function LevelSystemShowUpLevel() local EXP5 = getElementData(source,"Experience") if EXP5 == 25 then setElementData ( source, "Level", 2) triggerClientEvent(source,"LevelSystemShowPlayerLevel",source) outputChatBox ( source, "New Level 2!", source,0,255,0) setElementData ( source, "NextLevel", 75) end if EXP5 == 75 then setElementData ( source, "Level", 3) triggerClientEvent(source,"LevelSystemShowPlayerLevel",source) outputChatBox ( source, "New Level 3!", 0,255,0) setElementData ( source, "NextLevel", 150) end end addEventHandler("onElementDataChange",getRootElement(),LevelSystemShowUpLevel) Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 onElementDataChange is triggered when the server make a setElementData Where is your setElementData( thePlayer,"Experience", something+somethingElse ) Link to comment
Kenix Posted March 23, 2011 Author Share Posted March 23, 2011 you mean this? setElementData(source,"Experience",tonumber(getElementData(source,"Experience"))+1) Link to comment
Moderators Citizen Posted March 23, 2011 Moderators Share Posted March 23, 2011 Yeah where is it ? ( I think in onPlayerWasted right ? ) Why your script spaming you ? ( see the comments ): function LevelSystemShowUpLevel() local EXP5 = getElementData(source,"Experience") -- for exemple EXP5 = 25 ... if tonumber( EXP5 ) == 25 then -- ...so if 25 == 25 then ... setElementData ( source, "Level", 2) -- here the onElementDataChange is triggered again but the Experience is always 25 so it do it again etc ... ... To fix this problem, you can add another condition like the current level: function LevelSystemShowUpLevel() local lvl = getElementData(source,"Level") local EXP5 = getElementData(source,"Experience") if EXP5 == 25 and tonumber( lvl ) ~= 2 then setElementData ( source, "Level", 2) triggerClientEvent(source,"LevelSystemShowPlayerLevel",source) outputChatBox ( source, "New Level 2!", source,0,255,0) setElementData ( source, "NextLevel", 75) end if EXP5 == 75 and tonumber( lvl ) ~= 3 then setElementData ( source, "Level", 3) triggerClientEvent(source,"LevelSystemShowPlayerLevel",source) outputChatBox ( source, "New Level 3!", 0,255,0) setElementData ( source, "NextLevel", 150) end end addEventHandler("onElementDataChange",getRootElement(),LevelSystemShowUpLevel) 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