AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help: Allowing downloads based on map size. (https://forums.alliedmods.net/showthread.php?t=3392)

JonnyH 07-05-2004 13:15

Help: Allowing downloads based on map size.
 
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

Downtown1 07-05-2004 14:04

Mappath should probably have /%modname%/maps/%mapname%.bsp

Johnny got his gun 07-05-2004 14:41

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)

JonnyH 07-06-2004 07:15

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.^"")
        }
}


Dygear 07-06-2004 07:25

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.

Johnny got his gun 07-06-2004 07:59

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);

JonnyH 07-06-2004 08:37

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.^"")
  }
}


BigBaller 07-06-2004 09:32

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 :)

CheesyPeteza 07-06-2004 10:00

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

JonnyH 07-06-2004 11:29

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?


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

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