Jump to content

[Help!] loadstring and color


.:HyPeX:.

Recommended Posts

well loadstring is not doing anything, and color returned is just crazy values, like -168586

  
outputChatBox("#00aaffdxDrawRectangle Script by HyPeX Started", 255,255,255,true) 
  
  
function TurnRectangle(cmd,shit) 
if DxRectangleDraw then 
outputChatBox("#00aaffPlease finish the steps or restart the script.", 255,255,255,true) 
return 
end 
DxRectangleDraw = true 
outputChatBox("#00aaffPlease Do '/color R G B A' now", 255,255,255,true) 
end 
addCommandHandler("dxRec", TurnRectangle) 
  
function SetRecColour(cmd,valA, valB, valC, valD) 
if not valD then 
outputChatBox("#00aaffPlease Do '/color R G B A' -> You're missing R G B A", 255,255,255,true) 
return 
end 
if not DxRectangleDraw then 
outputChatBox("#00aaffPlease Do '/dxRec' first!", 255,255,255,true) 
return 
else 
outputChatBox("#00aaffPlease Draw an Area now. (Press and hold)", 255,255,255,true) 
color = tocolor(valA, valB, valC, valD) 
showCursor(true) 
end 
end 
addCommandHandler("color", SetRecColour) 
  
function OnClientCursorClick(button, state) 
if not DxRectangleDraw then 
outputChatBox("#00aaffPlease Do '/dxRec' first!", 255,255,255,true) 
return 
end 
if not color then 
outputChatBox("#00aaffPlease Do '/color R G B A' first!", 255,255,255,true) 
return 
end 
if state == "down" then 
CursorTable = {} 
CursorTable.X1, CursorTable.Y1 = getCursorPosition() 
outputChatBox("#00aaffPlease Hold and Drag the cursor.", 255,255,255,true) 
addEventHandler("onClientRender", getRootElement(), DrawExampleRec) 
end 
if state == "up" then 
CursorTable.X2, CursorTable.Y2 = getCursorPosition() 
removeEventHandler("onClientRender", getRootElement(), DrawExampleRec) 
showCursor(false) 
outputChatBox("#00aaffRectangle Selection is over, Please do '/CopyRec' to copy to clipboard", 255,255,255,true) 
end 
  
end 
addEventHandler("onClientClick", getRootElement(), OnClientCursorClick) 
  
function DrawExampleRec() 
if not CursorTable then 
return 
end 
if not color then 
outputChatBox("#00aaffColor error, please check the setps.", 255,255,255,true) 
removeEventHandler("onClientRender", getRootElement(), DrawExampleRec) 
return 
end 
local x,y = guiGetScreenSize() 
EndX, EndY = getCursorPosition() 
dxDrawRectangle(CursorTable.X1 * x, CursorTable.Y1 * y,( EndX * x ) - ( CursorTable.X1 * x ), ( EndY * y - CursorTable.Y1 * y ), color) 
end 
  
function CopyRec(cmd) 
if not color then 
outputChatBox("#00aaffPlease check the function, color missing", 255,255,255,true) 
return 
end 
if not CursorTable.X2 then 
outputChatBox("#00aaffPlease check the function, end corner of rectangle is missing.", 255,255,255,true) 
return 
end 
DrawString = "function DrawRectangle()".."\r\n".."local x,y = guiGetScreenSize()".."\r\n".."local color = "..color.."".."\r\n".."local EndY = "..EndY.."".."\r\n".."local EndX = "..EndX.."".."\r\n".."local CursorTableY1 = "..CursorTable.Y1.."".."\r\n".."local CursorTableX1 = "..CursorTable.X1.." ".."\r\n".."dxDrawRectangle(CursorTableX1 * x, CursorTableY1 * y,( EndX * x ) - ( CursorTableX1 * x ), ( EndY * y - CursorTableY1 * y ), color)".."\r\n".."end ".."\r\n".."addEventHandler('onClientRender', getRootElement(), DrawRectangle)"  
setClipboard(DrawString) 
outputConsole(DrawString) 
outputChatBox("#00aaffDraw string was saved, you can now test it with '/TestRec'.", 255,255,255,true) 
end 
addCommandHandler("CopyRec", CopyRec) 
  
function TestRec() 
if not DrawString then 
outputChatBox("#00aaffPlease do the function first, Draw string doesnt exist.", 255,255,255,true) 
return 
loadstring(DrawString) 
end 
end 
addCommandHandler("TestRec", TestRec) 

Random test:

  
function DrawRectangle() 
local x,y = guiGetScreenSize() 
local color = 1677721600 
local EndY = 0.40234375 
local EndX = 0.6860294342041 
local CursorTableY1 = 0.25260415673256 
local CursorTableX1 = 0.28529411554337  
dxDrawRectangle(CursorTableX1 * x, CursorTableY1 * y,( EndX * x ) - ( CursorTableX1 * x ), ( EndY * y - CursorTableY1 * y ), color) 
end  
addEventHandler('onClientRender', getRootElement(), DrawRectangle) 

PD: Somehow, that crazy number colour, works as if tocolor, lol.

Edited by Guest
Link to comment
loadstring doesn't work because you put it after 'return'.

Moved it down, with no result.

  
function TestRec() 
if not DrawString then 
outputChatBox("#00aaffPlease do the function first, Draw string doesnt exist.", 255,255,255,true) 
return 
end 
loadstring(DrawString) 
outputChatBox("#00aaffRunning the string.", 255,255,255,true) 
end 
addCommandHandler("TestRec", TestRec) 
  

i get the output thought.. (running)

Edited by Guest
Link to comment

Bump still need help, tried to use runcode with crun and got this..

  
Executing client-side command: function DrawRectangle() local x,y = guiGetScreenSize() dxDrawRectangle(0.26397058367729 * x, 0.24869792163372 * y,( 0.80588233470917 * x ) - ( 0.26397058367729 * x ), ( 0.43098959326744 * y - 0.24869792163372 * y ), -1275068416) end addEventHandler( 
Error: [string "function DrawRectangle() local x,y = guiGetScreenSize() dxDrawR..."]:1: unexpected symbol near '<eof> 

To make it work i did string like this:

TestString = "function DrawRectangle() local x,y = guiGetScreenSize() dxDrawRectangle("..CursorTable.X1.." * x, "..CursorTable.Y1.." * y,( "..EndX.." * x ) - ( "..CursorTable.X1.." * x ), ( "..EndY.." * y - "..CursorTable.Y1.." * y ), "..color..") end addEventHandler('onClientRender', getRootElement(), DrawRectangle)" 

Gives same result as original string try..

Link to comment
TestString = [[function DrawRectangle() local x,y = guiGetScreenSize() dxDrawRectangle("..CursorTable.X1.." * x, "..CursorTable.Y1.." * y,( "..EndX.." * x ) - ( "..CursorTable.X1.." * x ), ( "..EndY.." * y - "..CursorTable.Y1.." * y ), "..color..") end addEventHandler('onClientRender', getRootElement(), DrawRectangle)]] 

Try that string instead.

Link to comment

Try with this function:

function runString ( commandstring ) 
    local notReturned 
    local commandFunction, errorMsg = loadstring ( "return ".. commandstring ) 
    if ( errorMsg ) then 
        notReturned = true 
        commandFunction, errorMsg = loadstring ( commandstring ) 
    end 
  
    if ( errorMsg ) then 
        return false 
    end 
  
    local results = { pcall ( commandFunction ) } 
    if ( not results [ 1 ] ) then 
        return false 
    end 
end 

function TestRec ( ) 
    if ( not DrawString ) then 
        outputChatBox ( "#00aaffPlease do the function first, Draw string doesnt exist.", 255, 255, 255, true ) 
        return 
    end 
  
    runString ( DrawString ) 
end 
addCommandHandler ( "TestRec", TestRec ) 

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