Jump to content

Why is this not working???


Hamilton

Recommended Posts

Posted

I want this to show for everyplayer when the resource starts but it wont work :S Help is apricciated!

Here is the code:

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, thePlayer )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", getRootElement(), MyTestTextFunction)

Posted
I want this to show for everyplayer when the resource starts but it wont work :S Help is apricciated!

Here is the code:

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, thePlayer )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", getRootElement(), MyTestTextFunction)

Please Use


<div class="lua" id="{CB}" style="font-family: monospace;"><ol><li style="" class="li1"> </li></ol></div>

instead of Code

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, thePlayer )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", getRootElement(), MyTestTextFunction)

Posted
I want this to show for everyplayer when the resource starts but it wont work :S Help is apricciated!

Here is the code:

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, thePlayer )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", getRootElement(), MyTestTextFunction)

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, root )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", root, MyTestTextFunction)

Copy That ^ Above

Posted
function MyTestTextFunction ( ) 
    display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        textDisplayAddObserver ( display, player )  -- add an observer to it 
    end 
    text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item 
    textDisplayAddText ( display, text )           -- Add the text item to the text display 
end 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
I want this to show for everyplayer when the resource starts but it wont work :S Help is apricciated!

Here is the code:

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, thePlayer )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", getRootElement(), MyTestTextFunction)

function MyTestTextFunction () 

display = textCreateDisplay ()                 -- create a new display, store the reference in a variable called display

textDisplayAddObserver ( display, root )  -- add an observer to it

text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item

textDisplayAddText ( display, text )           -- Add the text item to the text display

end

addEventHandler("onResourceStart", root, MyTestTextFunction)

Copy That ^ Above

local settehcolor = tocolor(255, 255, 255, 255)     

 

function start()

    addEventHandler("onClientRender", root, dxthetext)

end

addEventHandler("onClientResourceStart", root, start)

   

function dxthetext()

    local screenWidth, screenHeight = guiGetScreenSize()

    local ax, ay = screenWidth 500, 300

    dxDrawText("Hello World!", ax,ay,500,300,settehcolor,4)

end

The Script MUST Be Clientside In the meta.xml

Posted

Still not working :(

I want it to create a text in the screen for all the players when the resource starts.

Here is the Script file code and the Meta code:

Meta.xml:

     "Hamilton" type="script" name="Notice" /> 
     

notice.lua:

function MyTestTextFunction ( ) 
    display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        textDisplayAddObserver ( display, player )  -- add an observer to it 
    end 
    text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item 
    textDisplayAddText ( display, text )           -- Add the text item to the text display 
end 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

Posted

Is a server side script, and you set it as client side ( type="client", must be type="server" ).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It's working, just in a wrong position I think, I removed this:

"low", 255, 0, 0, 0, 1.0 

and it worked.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Good, that worked

but now I got another problem

I want it to destroy after 5 seconds

Here is the script:

function MyTestTextFunction ( )

display = textCreateDisplay ( ) -- create a new display, store the reference in a variable called display

for index, player in ipairs ( getElementsByType ( "player" ) ) do

textDisplayAddObserver ( display, player ) -- add an observer to it

end

text = textCreateTextItem ( "Hello World", 0.5, 0.5 ) -- create a text item

textItemSetScale ( text, 2.0)

textDisplayAddText ( display, text ) -- Add the text item to the text display

textDestroyTextItem ( text )

setTimer ( textDestroyTextItem, 5000, 1 )

end

addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction )

Posted
Still not working :(

I want it to create a text in the screen for all the players when the resource starts.

Here is the Script file code and the Meta code:

Meta.xml:

     "Hamilton" type="script" name="Notice" /> 
     

notice.lua:

function MyTestTextFunction ( ) 
    display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        textDisplayAddObserver ( display, player )  -- add an observer to it 
    end 
    text = textCreateTextItem ( "Hello World", 0.5, 0.5, "low", 255, 0, 0, 0, 1.0 ) -- create a text item 
    textDisplayAddText ( display, text )           -- Add the text item to the text display 
end 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

Use This

local settehcolor = tocolor(255, 255, 255, 255)     
  
function start() 
    addEventHandler("onClientRender", root, dxthetext) 
end 
addEventHandler("onClientResourceStart", root, start) 
    
function dxthetext() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local ax, ay = screenWidth 500, 300 
    dxDrawText("Hello World!", ax,ay,500,300,settehcolor,4) 
end 

Posted
Good, that worked

but now I got another problem

I want it to destroy after 5 seconds

Here is the script:

function MyTestTextFunction ( )

display = textCreateDisplay ( ) -- create a new display, store the reference in a variable called display

for index, player in ipairs ( getElementsByType ( "player" ) ) do

textDisplayAddObserver ( display, player ) -- add an observer to it

end

text = textCreateTextItem ( "Hello World", 0.5, 0.5 ) -- create a text item

textItemSetScale ( text, 2.0)

textDisplayAddText ( display, text ) -- Add the text item to the text display

textDestroyTextItem ( text )

setTimer ( textDestroyTextItem, 5000, 1 )

end

addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction )

Well, if you don't give him the text to destroy, that won't work, also you're destroying it just after being created.

function MyTestTextFunction ( ) 
    display = textCreateDisplay ( ) -- create a new display, store the reference in a variable called display 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        textDisplayAddObserver ( display, player ) -- add an observer to it 
    end 
    text = textCreateTextItem ( "Hello World", 0.5, 0.5 ) -- create a text item 
    textItemSetScale ( text, 2.0) 
    textDisplayAddText ( display, text ) -- Add the text item to the text display 
    setTimer ( textDestroyTextItem, 5000, 1, text ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

]Working :) But now I got 1 more problem...

I want the text to remake itself after a certain amount of time. I thought it would work the way I did it but It wont :S

Here is the code, whats wrong?:

function MyTestTextFunction ( ) 
    display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do 
        textDisplayAddObserver ( display, player )  -- add an observer to it 
    end 
    text = textCreateTextItem ( "Report all the bugs you find with /report.", 0.01, 0.20 ) -- create a text item 
    textItemSetScale ( text, 1.5) 
    textDisplayAddText ( display, text )           -- Add the text item to the text display 
    setTimer ( textCreateTextItem, 15000, 0, text ) 
    setTimer ( textDestroyTextItem, 20000, 1, text ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

Posted
function MyTestTextFunction ( ) 
    if ( not text ) then 
        display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            textDisplayAddObserver ( display, player )  -- add an observer to it 
        end 
        text = textCreateTextItem ( "Report all the bugs you find with /report.", 0.01, 0.20 ) -- create a text item 
        textItemSetScale ( text, 1.5) 
        textDisplayAddText ( display, text )           -- Add the text item to the text display 
        setTimer ( textDestroyTextItem, 20000, 1, text ) 
    end 
end 
setTimer ( MyTestTextFunction, 15000, 0 ) 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That should create the text every 15 seconds if it doesn't exist already.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function MyTestTextFunction ( ) 
    if ( not text ) then 
        display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            textDisplayAddObserver ( display, player )  -- add an observer to it 
        end 
        text = textCreateTextItem ( "Report all the bugs you find with /report.", 0.01, 0.20 ) -- create a text item 
        textItemSetScale ( text, 1.5) 
        textDisplayAddText ( display, text )           -- Add the text item to the text display 
        setTimer ( 
            function ( ) 
                textDestroyTextItem ( text ) 
                text = nil 
            end 
            ,20000, 1 
        ) 
    end 
end 
setTimer ( MyTestTextFunction, 15000, 0 ) 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

Seems like: "textDestroyTextItem" doesn't remove the element, now it works.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Thank you Castillo!

Just 1 question, how do I make many different messages show?

I've got 1 message now, is it possible to make like a table where I can add messages and then when 1 message have been sent it will send the next one?

Posted

Make a table and a index variable, update it each time: "MyTestTextFunction" function is executed and get the new text.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Why is this not working? Please help me.

function MyTestTextFunction ( ) 
    if ( not text01 ) then 
        display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            textDisplayAddObserver ( display, player )  -- add an observer to it 
        end 
        text01 = textCreateTextItem ( "Report all the bugs you find with /report.", 0.01, 0.20 ) -- create a text item 
  text02 = textCreateTextItem ( "Some text", 0.01, 0.20 ) -- create a text item 
  text03 = textCreateTextItem ( "Some text", 0.01, 0.20 ) -- create a text item 
   
        textItemSetScale ( text01, 1.5) 
  textItemSetScale ( text02, 1.5) 
  textItemSetScale ( text03, 1.5) 
   
  any = math.random(1,3) 
   
  if (any == 1) then 
        textDisplayAddText ( display, text01 )           -- Add the text item to the text display 
        setTimer ( 
            function ( ) 
                textDestroyTextItem ( text01 ) 
                text01 = nil 
            end 
            ,20000, 1 
        ) 
   
  elseif (any == 2) then 
        textDisplayAddText ( display, text02 )           -- Add the text item to the text display 
        setTimer ( 
            function ( ) 
                textDestroyTextItem ( text02 ) 
                text02 = nil 
            end 
            ,20000, 1 
        ) 
   
  elseif (any == 3) then 
        textDisplayAddText ( display, text03 )           -- Add the text item to the text display 
        setTimer ( 
            function ( ) 
                textDestroyTextItem ( text03 ) 
                text03 = nil 
            end 
            ,20000, 1 
        ) 
    end 
end 
setTimer ( MyTestTextFunction, 15000, 0 ) 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

Error message: WARNING: Loading script failed: notice\notice.lua:49: 'end' expected (to close 'function' at line 1) near ''

Posted
function MyTestTextFunction ( ) 
    if ( not text01 ) then 
        display = textCreateDisplay ( )                 -- create a new display, store the reference in a variable called display 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            textDisplayAddObserver ( display, player )  -- add an observer to it 
        end 
        text01 = textCreateTextItem ( "Report all the bugs you find with /report.", 0.01, 0.20 ) -- create a text item 
        text02 = textCreateTextItem ( "Some text", 0.01, 0.20 ) -- create a text item 
        text03 = textCreateTextItem ( "Some text", 0.01, 0.20 ) -- create a text item 
  
        textItemSetScale ( text01, 1.5) 
        textItemSetScale ( text02, 1.5) 
        textItemSetScale ( text03, 1.5) 
  
        local any = math.random ( 1, 3 ) 
        if ( any == 1 ) then 
            textDisplayAddText ( display, text01 )           -- Add the text item to the text display 
            setTimer ( 
                function ( ) 
                    textDestroyTextItem ( text01 ) 
                    text01 = nil 
                end 
                ,20000, 1 
            ) 
        elseif ( any == 2 ) then 
            textDisplayAddText ( display, text02 )           -- Add the text item to the text display 
            setTimer ( 
                function ( ) 
                    textDestroyTextItem ( text02 ) 
                    text02 = nil 
                end 
                ,20000, 1 
            ) 
        elseif ( any == 3 ) then 
            textDisplayAddText ( display, text03 )           -- Add the text item to the text display 
            setTimer ( 
                function ( ) 
                    textDestroyTextItem ( text03 ) 
                    text03 = nil 
                end 
                ,20000, 1 
            ) 
        end 
    end 
end 
setTimer ( MyTestTextFunction, 15000, 0 ) 
addEventHandler ( "onResourceStart", resourceRoot, MyTestTextFunction ) 

You had a missing 'end'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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