Jump to content

Chatbox Ads


Deagle

Recommended Posts

BUMP!

Cmon man, I dont know scripting, but I think that you need just to modify some lines here :

function advert( ) 
    local rnd = math.random( 1, #adMessages ) 
    outputChatBox( adMessages[ rnd ], getRootElement(), 255, 255, 255, true ) 
end 
  

Link to comment

with this version rarely one ad can repeat 2times once a cycle of all add table.

probably there would be more efficient way of 2nd table, but cba doing that, as this should work just fine.

  
  
local tbl={ } 
local tblPos=1 
  
function refreshList() 
    local count=1 
    for _,val in pairs(adMessages) do --pairs automatically randomizes the list 
        tbl[count]=val 
        count=count+1 
    end 
end 
  
function advert( ) 
    outputChatBox( adMessages[tblPos], getRootElement(), 255, 255, 255, true ) 
    tblPos=tblPos+1 
    if tblPos>#adMessages then 
        tblPos=1 
        refreshList() 
    end 
end 
  
addEventHandler("onResoruceStart",getRootElement(),refreshList) 
  

if you don't want that 1 add cant appear more then once a cycle tru all list use this version

WARNING:NEVER USE IT WITH ONLY 1 ADD OR INF LOOP WILL BE MADE.

  
local lastRnd=0 
function advert( ) 
     local rnd = math.random( 1, #adMessages ) 
     while rnd == lastRnd do 
         rnd = math.random( 1, #adMessages ) 
     end 
     outputChatBox( adMessages[ rnd ], getRootElement(), 255, 255, 255, true ) 
     lastRnd=rnd 
end 
  

Edited by Guest
Link to comment

well, math.random is obviously used to get a random number and it is possible to get the same number a few times in a row..

I suppose you could take them 1 by 1 instead of being all randomized.

Try the following code, even though I didn't test it and I'm not sure if this is what you want to do..

function advert( ) 
    nr = nr + 1 
    if nr == #adMessages then nr = 0 end 
    outputChatBox( adMessages[nr], getRootElement(), 255, 255, 255, true ) 
end 

Right before this function, add the following line: nr = 0

Link to comment

WARNING:NEVER USE IT WITH ONLY 1 ADD OR INF LOOP WILL BE MADE.

why not prevent it then, instead of writing warnings in caps? :S

  
local lastRnd=0 
function advert() 
     local rnd = math.random( 1, #adMessages ) 
     while rnd == lastRnd and #adMessages > 1 do 
         rnd = math.random( 1, #adMessages ) 
     end 
     outputChatBox( adMessages[ rnd ], getRootElement(), 255, 255, 255, true ) 
     lastRnd=rnd 
end 
  

Link to comment

WARNING:NEVER USE IT WITH ONLY 1 ADD OR INF LOOP WILL BE MADE.

why not prevent it then, instead of writing warnings in caps? :S

  
local lastRnd=0 
function advert() 
     local rnd = math.random( 1, #adMessages ) 
     while rnd == lastRnd and #adMessages > 1 do 
         rnd = math.random( 1, #adMessages ) 
     end 
     outputChatBox( adMessages[ rnd ], getRootElement(), 255, 255, 255, true ) 
     lastRnd=rnd 
end 
  

dont think that should be necessary for the use it serves, just would consume more resoruces.

EDIT:

slight improvement

  
local lastRnd=0 
function advert( ) 
     local rnd 
     repeat 
         rnd = math.random( 1, #adMessages ) 
     until rnd ~= lastRnd 
     outputChatBox( adMessages[ rnd ], getRootElement(), 255, 255, 255, true ) 
     lastRnd=rnd 
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...