Raised This Month: $ Target: $400
 0% 

Help: Allowing downloads based on map size.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JonnyH
Junior Member
Join Date: Apr 2004
Old 07-05-2004 , 13:15   Help: Allowing downloads based on map size.
Reply With Quote #1

Hi, Im trying to write a plugin for a friend, he wants ppl to be able to download any map less than 4mb is size from the server, otherwise he wants them to get a messages telling them where the map pack is.

So far, I have come up with the following, im not worrying about the message yet. This code is in plugin_init().

Code:
new mapname[64], mappath[128]
get_mapname(mapname,63)
format(mappath,127,"/maps/%s.bsp",mapname)
if (file_size(mappath, 0)>=4000)
	{
		server_cmd("sv_allowdownload 0")
	} else {
		server_cmd("sv_allowdownload 1")
	}
For some reason it doesnt work, I have tried loads of variations for the path of the map, with no luck, I am sure that it is not seeing the map, as if I do a "file_exists" I get 0.

Any idea how AMXX file_size would let me refer to a file in the maps directory, or where it starts its relative paths from (the AMXX dir, root or cs root)?

Thanks for any help,

Jonny
JonnyH is offline
Downtown1
Veteran Member
Join Date: Mar 2004
Old 07-05-2004 , 14:04  
Reply With Quote #2

Mappath should probably have /%modname%/maps/%mapname%.bsp
Downtown1 is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 07-05-2004 , 14:41  
Reply With Quote #3

Path of file_size is the moddir.

Code:
new map[33] get_mapname(map, 32) mappath[128] format(mappath, 127, "maps/%s.bsp", map) new mapsize = file_size(mappath, 0)
Johnny got his gun is offline
JonnyH
Junior Member
Join Date: Apr 2004
Old 07-06-2004 , 07:15  
Reply With Quote #4

Ok, having some problems now with the client messages, they are not apprearing, I have done it on Client_Connect, but it doesnt come up in console when the user gets the "Cannot download map..." message.

Ideally I would like to have the message pop up in one of those nice steamy boxes, but if this isnt possible, I would be happy with just console printing.

Thanks for the help above "Johnny got his gun", and any further help anyone can offer.

Code:
public plugin_init() 
{
   register_plugin("Download Tester","1.0","JonnyH")
   server_cmd("sv_allowdownload 1")

	new map[33], mappath[128]
	get_mapname(map, 32) 
	format(mappath, 127, "maps/%s.bsp", map) 
	new mapsize = file_size(mappath, 0)
	if (mapsize >= 4000)
		{
			server_cmd("sv_allowdownload 0")
		} else {
			server_cmd("sv_allowdownload 1")
		}

   return PLUGIN_CONTINUE 
}

public client_connect(id){
	if (get_cvar_num("sv_allowdownload")==0){
		client_cmd(id, "echo ^"========================================================================^"")
		client_cmd(id, "echo ^"[KOA] This map is too big to download from the server.^"")
		client_cmd(id, "echo ^"[KOA] Please download this map from www.K-O-A.com.^"")
		client_cmd(id, "echo ^"========================================================================^"")
	} else {
		client_cmd(id, "echo ^"========================================================================^"")
		client_cmd(id, "echo ^"[KOA] As this map is less than 4mb, you can download it from our server.^"")
		client_cmd(id, "echo ^"Visit www.K-O-A.com for more info.^"")
	}
}
JonnyH is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 07-06-2004 , 07:25  
Reply With Quote #5

Code:
public plugin_init() {    register_plugin("Download Tester","1.0","JonnyH")    server_cmd("sv_allowdownload 1")     new map[33], mappath[128]     get_mapname(map, 32)     format(mappath, 127, "maps/%s.bsp", map)     new mapsize = file_size(mappath, 0)     if (mapsize >= 4096)         {             server_cmd("sv_allowdownload 0")         } else {             server_cmd("sv_allowdownload 1")         }    return PLUGIN_CONTINUE }

Note that 4 megabytes = 4096 kilobytes ! 4000.
Its a littel nuance, but ya never know.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 07-06-2004 , 07:59  
Reply With Quote #6

file_size returns size in bytes.

4 megabyte = 4096 kB = 16777216 bytes

Quote:
/* Returns a file size in bytes if flag is set to 0.
* When flag is set to 1 returns number of lines in the file,
* and when flags is 2, function returns 1 if the file ends
* with line feed. If file doesn't exist returns -1. */
native file_size(const file[], flag=0);
Johnny got his gun is offline
JonnyH
Junior Member
Join Date: Apr 2004
Old 07-06-2004 , 08:37  
Reply With Quote #7

lol thanks, what can I say, I'm a noob.

The main problem though is still the messages to clients on connect. It isnt printing to the console etc.

Code:
public client_connect(id){ 
   if (get_cvar_num("sv_allowdownload")==0){ 
      client_cmd(id, "echo ^"========================================================================^"") 
      client_cmd(id, "echo ^"[KOA] This map is too big to download from the server.^"") 
      client_cmd(id, "echo ^"[KOA] Please download this map from www.K-O-A.com.^"") 
      client_cmd(id, "echo ^"========================================================================^"") 
   } else { 
      client_cmd(id, "echo ^"========================================================================^"") 
      client_cmd(id, "echo ^"[KOA] As this map is less than 4mb, you can download it from our server.^"") 
      client_cmd(id, "echo ^"Visit www.K-O-A.com for more info.^"") 
   } 
}
JonnyH is offline
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 07-06-2004 , 09:32  
Reply With Quote #8

instead of using client_cmd(id

try using

Quote:
console_print ( id, const message[], ... )
Soo your code would look like this

Code:
public client_connect(id){    if (get_cvar_num("sv_allowdownload")==0){       console_print(id, "========================================================================")       console_print(id, "[KOA] This map is too big to download from the server.")       console_print(id, "[KOA] Please download this map from www.K-O-A.com.")       console_print(id, "========================================================================")    } else {       console_print(id, "========================================================================")       console_print(id, "[KOA] As this map is less than 4mb, you can download it from our server.")       console_print(id, "Visit <a href="http://www.K-O-A.com" target="_blank" rel="nofollow noopener">www.K-O-A.com</a> for more info.")    } }

I hope that helps you out man
__________________

BigBaller is offline
CheesyPeteza
Senior Member
Join Date: Feb 2004
Location: UK
Old 07-06-2004 , 10:00  
Reply With Quote #9

When a players connecting their console isn't open though. The only way I know of getting a message to players before they connect is via the kick command as it allows you to give a reason why.

Code:
server_cmd("kick #%d ^"Please download this map from www.K-O-A.com.^"", get_user_userid(id))
__________________
YO|Cheesy Peteza

[email protected]

CheesyPeteza is offline
JonnyH
Junior Member
Join Date: Apr 2004
Old 07-06-2004 , 11:29  
Reply With Quote #10

The problem if I use the kick is that, it will kick everyone surly?

Is there an "FileDownload" event or similar native funtion?

Anyone know of a list of CS events?
JonnyH is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode