Jump to content
Sign in to follow this  
Foxseiz

Ads System

Recommended Posts

[Script] Ads System

 

Original Post: 

 

 

Description:

The script displays randomly in any message that you mount it in a specified period of time. Very handy for reminders about updates, etc. Installation: Open functions.lua  and add the code in  cha_timer : 
 

 

local SetTime = 5 - time after which the message will be added 
	local i = math . random (  1 ,  5  ) 	--  Random  ( 1  of  5 ) 

	if  ( math . mod ( now_tick ,  60 * SetTime  )  ==  0  and now_tick >  0  )  then 	--  checks 
		SystemNotice (TurnToCha (role), NoticeX [i]) - displays a message 
	end

Open variable.lua and add the code:

 

NoticeX 		=  {} 
NoticeX [ 1 ] 	=  "Welcome to the private server Online Pirates!" 
NoticeX [ 2 ] 	=  "If you found a bug, please report to our bug tracker" 
NoticeX [ 3 ] 	=  "Our site www.site.com " 
NoticeX [ 4 ] 	=  " Do not forget to vote for our server " 
NoticeX [ 5 ] 	=  " Do not forget to check the latest updates on our website! "

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

V3ct0r's Comment

 

Row

local i = math.random( 1, 5 )	-- Rand (1 of 5)

better to replace 

local i = math.random( 1, table.getn(NoticeX))	-- Rand (1 of N), where N - number of messages

Now we can add variable.lua any number of messages and we do not need to edit the function cha_timer ()

Row

local SetTime = 5	-- time after which the message will be added

You can also bring in variable.lua.

Later. In your code, messages are sent to all objects (players, monsters, trees, etc.). It is necessary to add a check IsPlayer (role) == 1

Function math.rand () is called every tick (every second), and why? We need it to be called every 5 minutes (the interval between messages). Need to add 

local i = math.random( 1, 5 )

Inside alarm condition messages.

 

In general, it turns out that something like this:

variable.lua

interval = 5 -- The interval between messages in minutes
notices = {} -- An array of messages

functions.lua , function cha_timer ()

if IsPlayer(role) == 1 then
    if ( now_tick > 0 and math.mod(now_tick, interval * 60) == 0 ) then
        local rand = math.random(1, table.getn(notices))
        SystemNotice(role, notices[rand])
    end	
 end

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

e1mer's Comment

 

And now all the same, just take the code with Victor ppm, and not much of its rewrite and extend festive \ holidays on the server.

3
 

	----------------------------------------------------------------------------- 
	--  Advertising \ Announcements system 	--------------------------------------------- 
	----------------------------------------------------------------------------- 
	if  ( AdsInGameRND  ==  1 ) then
		 if  IsPlayer ( role )  ==  1 then
			local interval =  1  --  The interval between messages in the system (35 seconds)
			if math . mod ( now_tick , interval )  ==  0 then
				 if  ( Holidays  ==  1 ) then
					rand = math . random ( 1 , table . getn ( notices_two )) 
					SystemInfo  = notices_two [ rand ] 
				else 
					rand = math . random ( 1 , table . getn ( notices )) 
					SystemInfo  = notices [ rand ]
				end
				SystemNotice ( role ,  SystemInfo  )
			end
		end
	end

Global variables in variable.lua, add to the end of the file:
 

	----------------------------------------------------------------------------- 
	--  Advertising \ Announcements system 	--------------------------------------------- 
	----------------------------------------------------------------------------- 
	Holidays 				=  0 		--  Partly inclusion "holidays" on the server
	AdsInGameRND 			=  0 		--  Partly inclusion \ off your system
      
	notices =  {} 
	notices_two =  {} 
	-  Conventional  Ad 
	notices [ 1 ]  =  "Normal ads" 
	-  Festive  days 
	notices_two [ 1 ]  =  "Holiday Ads"

Now we can use as a regular ad in the chat, so some holidays, weekends, etc., and you can include it is fairly simple, it is necessary to change one number in a global variable. 

 

  • Like 5

Share this post


Link to post
Share on other sites

Hey bro, nice guide and translation. I've made an extension to make it simple, improved & easier

 

Check it out right HERE

Edited by Sultan
  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...