Jump to content

help with script


Kenix

Recommended Posts

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

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
  • Moderators

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
  • Moderators

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
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
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
not working

Sorry I made a big error :roll:

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
  • Moderators

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

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

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

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

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

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

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

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