Jump to content

bindkey problem


downight

Recommended Posts

Hi, I want to bind this (it's original, without bind):

local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() 
  
local name, author, lastTimePlayed, spawnPointCount, playedCount, modename 
local startTick 
  
local enabled = false 
local drawTime = 10000 
  
local month = {"January","February","March","April","May","June","July","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
function handleMapInfo(mapInfo) 
    name            = mapInfo.name or "Unknown" 
    author          = mapInfo.author or "Unknown" 
    lastTimePlayed  = timestampToDate(mapInfo.lastTimePlayed) or "Unknown" 
    spawnPointCount = tostring(mapInfo.spawnPointCount) 
    playedCount     = tostring(mapInfo.playedCount or "Unknown") 
    modename        = mapInfo.modename ~= "Destruction derby" and mapInfo.modename or "DD / DM" 
     
    startTick = getTickCount() 
     
    if not enabled then 
        addEventHandler("onClientRender",getRootElement(),handleOnRender) 
        enabled = true 
    end 
end 
addEvent("onClientMapStarting",true) 
addEventHandler("onClientMapStarting",getRootElement(),handleMapInfo) 
  
function handleOnRender() 
    local time = getTickCount() - startTick 
     
    local alphaFactor 
     
    if time < 1000 then 
        alphaFactor = time / 1000 
    elseif time >= 1000 and time < drawTime + 1000 then 
        alphaFactor = 1 
    elseif time >= drawTime + 1000 and time < drawTime + 2000 then 
        alphaFactor = 1 - (time - (drawTime + 1000)) / 1000 
    elseif time >= drawTime + 2000 then 
        enabled = false 
        removeEventHandler("onClientRender",getRootElement(),handleOnRender) 
        return 
    end 
     
    local maxLabelWidth = 81 
     
    local nameWidth            = dxGetTextWidth(name,1,"default-bold") 
    local authorWidth          = dxGetTextWidth(author) + maxLabelWidth 
    local lastTimePlayedWidth  = dxGetTextWidth(lastTimePlayed) + maxLabelWidth 
    local spawnPointCountWidth = dxGetTextWidth(spawnPointCount) + maxLabelWidth 
    local playedCountWidth     = dxGetTextWidth(playedCount) + maxLabelWidth 
    local modenameWidth        = dxGetTextWidth(modename) + maxLabelWidth 
     
    local width  = math.max(nameWidth,authorWidth,lastTimePlayedWidth,spawnPointCountWidth,playedCountWidth,modenameWidth) + 10 
    local height = 100 
     
    local x = SCREEN_WIDTH - width 
    local y = SCREEN_HEIGHT / 1.3 - height / 1.3 
     
    dxDrawRectangle(x,y,width,20,tocolor(0,0,0,255*alphaFactor)) 
    dxDrawRectangle(x,y + 20,width,height - 20,tocolor(0,0,0,200*alphaFactor)) 
     
    dxDrawText(name,x,y,x+width,y+20,tocolor(97,255,19*alphaFactor),1,"default-bold","center","center") 
    dxDrawText("Author:\nTipo:\nSpawnpoints:\ntimes played:\nlast time:",x+5,y+20,0,0,tocolor(97,255,19*alphaFactor),1,"default-bold") 
    dxDrawText(string.format("%s\n%s\n%s\n%s\n%s",author,modename,spawnPointCount,playedCount,lastTimePlayed),x+5+maxLabelWidth,y+20,0,0,tocolor(255,255,255*alphaFactor)) 
end 

The script is shown when the map is started so it shows you proper map information:

1_zps50ac3c4e.png

but when I tried to bind it as letter "m", It shows the "default" info (should be the same as the image above):

2_zps36df1a55.png

I don't know what's going on :(

Link to comment

Yes that's because you removed the 'onClientMapStarting' Event as i think because the 'mapInfo' return nil .

Try this :

local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() 
  
local name, author, lastTimePlayed, spawnPointCount, playedCount, modename 
local startTick 
  
local enabled = false 
local drawTime = 10000 
  
local month = {"January","February","March","April","May","June","July","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
function handleMapInfo(mapInfo) 
    ReturnInfo = mapInfo 
end 
  
addEvent("onClientMapStarting",true) 
addEventHandler("onClientMapStarting",getRootElement(),handleMapInfo) 
  
bindKey ( "m","down", 
    function (      ) 
      if not ReturnInfo then return end 
            name            = ReturnInfo.name or "Unknown" 
            author          = ReturnInfo.author or "Unknown" 
            lastTimePlayed  = timestampToDate(ReturnInfo.lastTimePlayed) or "Unknown" 
            spawnPointCount = tostring(ReturnInfo.spawnPointCount) 
            playedCount     = tostring(ReturnInfo.playedCount or "Unknown") 
            modename        = ReturnInfo.modename ~= "Destruction derby" and ReturnInfo.modename or "DD / DM" 
            startTick = getTickCount() 
                if not enabled then 
                    addEventHandler("onClientRender",getRootElement(),handleOnRender) 
                    enabled = true 
        else 
                enabled = false 
                removeEventHandler("onClientRender",getRootElement(),handleOnRender)        
        end 
    end 
) 
  
function handleOnRender() 
    local time = getTickCount() - startTick 
    
    local alphaFactor 
    
    if time < 1000 then 
        alphaFactor = time / 1000 
    elseif time >= 1000 and time < drawTime + 1000 then 
        alphaFactor = 1 
    elseif time >= drawTime + 1000 and time < drawTime + 2000 then 
        alphaFactor = 1 - (time - (drawTime + 1000)) / 1000 
    elseif time >= drawTime + 2000 then 
        enabled = false 
        removeEventHandler("onClientRender",getRootElement(),handleOnRender) 
        return 
    end 
    
    local maxLabelWidth = 81 
    
    local nameWidth            = dxGetTextWidth(name,1,"default-bold") 
    local authorWidth          = dxGetTextWidth(author) + maxLabelWidth 
    local lastTimePlayedWidth  = dxGetTextWidth(lastTimePlayed) + maxLabelWidth 
    local spawnPointCountWidth = dxGetTextWidth(spawnPointCount) + maxLabelWidth 
    local playedCountWidth     = dxGetTextWidth(playedCount) + maxLabelWidth 
    local modenameWidth        = dxGetTextWidth(modename) + maxLabelWidth 
    
    local width  = math.max(nameWidth,authorWidth,lastTimePlayedWidth,spawnPointCountWidth,playedCountWidth,modenameWidth) + 10 
    local height = 100 
    
    local x = SCREEN_WIDTH - width 
    local y = SCREEN_HEIGHT / 1.3 - height / 1.3 
    
    dxDrawRectangle(x,y,width,20,tocolor(0,0,0,255*alphaFactor)) 
    dxDrawRectangle(x,y + 20,width,height - 20,tocolor(0,0,0,200*alphaFactor)) 
    
    dxDrawText(name,x,y,x+width,y+20,tocolor(97,255,19*alphaFactor),1,"default-bold","center","center") 
    dxDrawText("Author:\nTipo:\nSpawnpoints:\ntimes played:\nlast time:",x+5,y+20,0,0,tocolor(97,255,19*alphaFactor),1,"default-bold") 
    dxDrawText(string.format("%s\n%s\n%s\n%s\n%s",author,modename,spawnPointCount,playedCount,lastTimePlayed),x+5+maxLabelWidth,y+20,0,0,tocolor(255,255,255*alphaFactor)) 
end 

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