#define Respawn
//argument0: 0 for server, 1 for local.
//argument1: if arg0 == 1, this is the x position to spawn
//argument2: if arg0 == 1, this is the y position to spawn
//
//if arg0 == 0, returns the instance ID of the spawn chosen
switch(argument0)
{
    case 0:
    var spawns, spawn, spawnchosen;
    spawns = 0
    spawn[0] = 0
    spawnchosen = 0
    if !IsTeamplay()
    {
        with obj_spawn
        {
            spawn[spawns] = id
            spawns+=1
        }
        with obj_spawn_red
        {
            spawn[spawns] = id
            spawns+=1
        }
        with obj_spawn_blue
        {
            spawn[spawns] = id
            spawns+=1
        }
    }
    else
    {
        if id.Team == TEAM_BLUE
        {
            with obj_spawn_blue
            {
                spawn[spawns] = id
                spawns+=1
            }
        }
        else if id.Team == TEAM_RED
        {
            with obj_spawn_red
            {
                spawn[spawns] = id
                spawns+=1
            }
        }
        if spawns == 0
        {
            with obj_spawn
            {
                spawn[spawns] = id
                spawns+=1
            }
        }
    }
    if spawns != 0
    {
        spawnchosen = irandom(spawns-1)
        xx = spawn[spawnchosen].x+16
        yy = spawn[spawnchosen].y+16
    }
    else
    {
        spawn[0] = -1
        spawnchosen = 0
        xx = 0
        yy = 0
    }
    buffer_clear(buffer)
    buffer_write_uint8(buffer, RESPAWN)
    buffer_write_float32(buffer, xx)
    buffer_write_float32(buffer, yy)
    socket_write_message(id.socket, buffer)
    event_perform_object(m_pController, ev_other, ev_user2)
    return spawn[spawnchosen]
    break
    
    case 1:
    hp[player_id] = 10
    armor[player_id] = 0
    for(i=0; i<5 i+=1) ammo[player_id,i] = 0
    with obj_body
    {
        alive = 1
        x = argument1
        y = argument2
        vspeed = 0
        hspeed = 0
    }
    break
}

#define CreateSpawn
switch(argument0)
{
    case 0:
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, EFFECT)
        buffer_write_uint8(buffer, EF_SPAWN)
        buffer_write_float32(buffer, argument1+16)
        buffer_write_float32(buffer, argument2+16)
        socket_write_message(socket, buffer)
    }
    break
    case 1:
    return effect_create_above(ef_ring,argument1,argument2,2,make_color_rgb(130,1,235))
    break
}

#define CreateDeath
//argument0: 0 for server, 1 for local.
//if server:
//argument1: color of the death effect.
//argument2: x
//argument3: y
//
//if local:
//argument1: x
//argument2: y
//argument3: color.
switch(argument0)
{
    case 0:
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, EFFECT)
        buffer_write_uint8(buffer, EF_DEATH)
        buffer_write_uintv(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_float32(buffer, argument3)
        socket_write_message(socket, buffer)
    }
    break
    case 1:
    return effect_create_above(ef_explosion,argument1,argument2,1,argument3)
    break
}

#define CreateExplosion
//argument0: 0 for server, 1 for local
//argument1: x position of explosion
//argument2: y position of explosion.
switch(argument0)
{
    case 0:
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, EFFECT)
        buffer_write_uint8(buffer, EF_EXPLOSION)
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        socket_write_message(socket, buffer)
    }
    break
    case 1:
    effect_create_above(ef_explosion,argument1,argument2,1,make_color_rgb(255,186,94))
    effect_create_above(ef_smoke,argument1,argument2,1,make_color_rgb(192,192,192))
    var explo, force, dir;
    explo = 0
    with obj_body
    {
        explo = point_distance(x,y,argument1,argument2)
        if explo <= 100
        {
            dir = point_direction(x,y,argument1,argument2)
            force = abs(100-explo)/4
            hspeed += round(lengthdir_x(force, dir+180))
            vspeed += round(lengthdir_y(force, dir+180))
        }
    }
    break
}

#define CreateSound
//argument0: 0 for server, 1 for client, 2 for local
//argument1: sound name.
//argument2: if arg1 == SOUND_FILE, the filename to play. wav and ogg only
switch(argument0)
{
    case 0:
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, SOUND)
        buffer_write_intv(buffer, argument1)
        if argument1 == SOUND_FILE then buffer_write_string(buffer, str(argument2))
        socket_write_message(socket, buffer)
    }
    break
    case 1:
    with obj_player
    {
        buffer_clear(buff)
        buffer_write_uint8(buff, SOUND)
        buffer_write_uint32(buff, argument1)
        socket_write_message(socket, buff)
    }
    break
    case 2:
    switch(argument1)
    {
        case SOUND_PLAYER_SPAWN:
        sound_play(choose(snd_spawn1,snd_spawn2,snd_spawn3,snd_spawn4,snd_spawn5,snd_spawn6,snd_spawn7))
        break
        case SOUND_PLAYER_DIE:
        sound_play(choose(snd_death1,snd_death2,snd_death3,snd_death4))
        break
        case SOUND_PLAYER_JUMP:
        sound_play(choose(snd_jump1,snd_jump2,snd_jump3,snd_jump4,snd_jump5,snd_jump6,snd_jump7,snd_jump8))
        break
        case SOUND_PLAYER_DOUBLEJUMP:
        sound_play(choose(snd_dbljump1,snd_dbljump2,snd_dbljump3))
        break
        case SOUND_WEAPON_SWITCH:
        sound_play(snd_wpswitch[irandom(2)])
        break
        case SOUND_WEAPON_NOAMMO:
        sound_play(snd_noammo[irandom(4)])
        break
        case SOUND_RIFLE_FIRE:
        sound_play(choose(snd_rifle01,snd_rifle02,snd_rifle03))
        break
        case SOUND_RIFLE_BOUNCE:
        sound_play(choose(snd_rifleb01,snd_rifleb02,snd_rifleb03))
        break
        case SOUND_GUN_FIRE:
        sound_play(snd_gun[irandom(2)])
        break
        case SOUND_CHAT_CLIENT:
        sound_play(snd_clientchat)
        break
        case SOUND_CHAT_HIGHLIGHT:
        sound_play(snd_pingchat)
        break
        case SOUND_CHAT_SERVER:
        sound_play(snd_serverchat)
        break
        case SOUND_WEAPON_SPAWN:
        sound_play(snd_wpspawn[irandom(2)])
        break
        case SOUND_GRENADE_FIRE:
        sound_play(snd_grenade[irandom(2)])
        break
        case SOUND_GRENADE_EXPLODE:
        sound_play(snd_grenadeexplo[irandom(2)])
        break
        case SOUND_SHOTGUN_FIRE:
        sound_play(snd_shotgun[irandom(2)])
        break
        case SOUND_PICKUP_GUN:
        sound_play(snd_pickupgun)
        break
        case SOUND_PICKUP_SHOTGUN:
        sound_play(snd_pickupsg)
        break
        case SOUND_PICKUP_GRENADE:
        sound_play(snd_pickuplauncher)
        break
        case SOUND_PICKUP_HEART:
        sound_play(snd_pickupheart[irandom(1)])
        break
        case SOUND_PICKUP_ARMOR:
        sound_play(snd_pickuparmor[irandom(3)])
        break
        case SOUND_PLAYER_PAIN_LONG:
        sound_play(snd_pain_long[irandom(1)])
        break
        case SOUND_PLAYER_PAIN_SHORT:
        sound_play(snd_pain_short[irandom(11)])
        break
        case SOUND_HIT:
        sound_play(snd_hit[irandom(2)])
        break
        case SOUND_HAMMER_FIRE:
        sound_play(snd_hammer[irandom(2)])
        break
        case SOUND_HAMMER_HIT:
        sound_play(snd_hammerhit[irandom(2)])
        break
        case SOUND_CTF_DROP:
        sound_play(snd_ctf_drop)
        break
        case SOUND_CTF_CAPTURE:
        sound_play(snd_ctf_capture)
        break
        case SOUND_CTF_RETURN:
        sound_play(snd_ctf_return)
        break
        case SOUND_CTF_GRAB_PL:
        sound_play(snd_ctf_grab_pl)
        break
        case SOUND_CTF_GRAB_EN:
        sound_play(snd_ctf_grab_en)
        break
        case SOUND_MENU:
        SS_PlaySound(snd_menu)
        break
        case SOUND_FILE:
        var file, snd;
        file = str(argument2)
        if file_exists(file)
        {
            snd = SS_LoadSound(file)
            SS_PlaySound(snd)
            with obj_player
            {
                sound[sounds] = snd
                sounds += 1
                if sounds >= 32 then sounds = 0
            }
        }
    }
    break
}

#define CreateSoundTarget
//argument0: player ID target
//argument1: sound name.
//argument2: if arg1 == SOUND_FILE, the filename of the sound. wav and ogg only
with obj_serversock
{
    if pid == argument0
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, SOUND)
        buffer_write_intv(buffer, argument1)
        if argument1 == SOUND_FILE then buffer_write_string(buffer, str(argument2))
        socket_write_message(socket, buffer)
    }
}

#define SendChat
if argument0 != -1
    Print(all, "[chat]: "+str(Team)+":"+str(pid)+":"+name+": "+str(argument1), 1, 1)
else
    Print(all, "[chat]: *** "+str(argument1))
with obj_serversock
{
    buffer_clear(buffer)
    buffer_write_uint8(buffer,CHAT)
    buffer_write_int32(buffer, argument0)
    buffer_write_string(buffer,str(argument1))
    socket_write_message(socket,buffer)
}

#define SendChatTarget
var idtarget;
idtarget = argument0

with obj_serversock
{
    if pid = idtarget
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer,CHAT)
        buffer_write_int32(buffer, -1)
        buffer_write_string(buffer,string(argument1))
        socket_write_message(socket,buffer)
    }
}

#define Kill
//argument0: 0 for server, 1 for client, 2 for local
//argument1: if argument0 = 0, this argument is the player ID to kill
switch(argument0)
{
    case 0:
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, KILL)
        buffer_write_uint32(buffer, argument1)
        socket_write_message(socket, buffer)
        if argument1 == pid
        {
            if alive
            {
                CreateDeath(0, otherbodycolor, x, y)
                
                //a nice sound
                CreateSound(0, SOUND_PLAYER_DIE)
            }
            hps = 0
            armors = 0
            for(i=0;i<5;i+=1) ammos[i] = 0
            alive = false
            respawn = 90
            Print(all, "[game]: kill victim='"+str(argument1)+":"+str(name)+"'", 1, 1)
            event_perform_object(m_pController, ev_other, ev_user3)
        }
    }
    break
    case 1:
    with obj_player
    {
        buffer_clear(buff)
        buffer_write_uint8(buff, KILL)
        socket_write_message(socket, buff)
    }
    break
    case 2:
    if obj_body.alive = 0
    {
        return 1;
    }
    obj_body.x = -room_width
    obj_body.y = -room_height
    obj_body.alive = 0
    hp[player_id] = 0
    break
}


#define FireWeapon
//argument0: the weapon to fire. 0 = hammer, 1 = pistol, 2 = shotgun, 3 = grenade, 4 = laser and 5 = ninja
//argument1: x, calculated with lengthdir_x()
//argument2: y, calculated with lengthdir_y()
//argument3: direction
//argument4: player ID who fired the weapon.
with obj_serversock
{
    buffer_clear(buffer)
    buffer_write_uint8(buffer, FIRE)
    buffer_write_uint8(buffer, argument0)
    buffer_write_float32(buffer, argument1)
    buffer_write_float32(buffer, argument2)
    buffer_write_float32(buffer, argument3)
    buffer_write_uint32(buffer, argument4)
    socket_write_message(socket, buffer)
}

#define Damage
//argument0: player to damage.
//argument1: HP damage.
//argument2: play pain sound? true/false (optional, leave empty for false)
//argument3: player ID attacker (set to -1 if none)
var ppid, damage, playsound, attacker;
ppid = argument0
damage = argument1
playsound = argument2
attacker = argument3

if damage <= 0 then return false

with obj_serversock
{
    if ppid = pid
    {
        if !can_damage then return false
        if hps > 0
        {
            if armors > 0
            {
                if damage > 1
                {
                    armors -= damage-1
                    hps -= 1
                }
                else armors -= damage
                if armors < 0
                {
                    hps -= -armors
                    armors = 0
                }
                if playsound && hps > 0 then CreateSound(0, SOUND_PLAYER_PAIN_SHORT)
            }
            else
            {
                hps -= damage
                if playsound && hps > 0
                {
                    if damage > 2 then CreateSound(0, SOUND_PLAYER_PAIN_LONG)
                    else CreateSound(0, SOUND_PLAYER_PAIN_SHORT)
                }
            }
            if hps <= 0
            {
                Kill(0, ppid)
                if attacker != -1
                {
                    with obj_serversock
                    {
                        if pid == attacker then points += 1
                        else if ppid == attacker then points -= 1
                    }
                }
            }
        }
        if alarm[2] = -1
        {
            oldeyes = eyes
            eyes = 2
            alarm[2] = 10
            Emote(pid, -1, eyes)
        }
        else alarm[2] = 10
    }
}

#define FireLaser
//argument0: x
//argument1: y
//argument2: angle
//argument3: length
//argument4: who fired it
//argument5: create object locally? (optional)
//argument6: "bounced" times (optional) (if arg5 is true)
var g;

if argument5 != false then
    {
        g = instance_create(argument0, argument1, obj_laser_server)
        g.image_angle = argument2
        g.image_xscale = argument3
        g.firedby = argument4
        g.bounced = argument6
    }
else
with obj_serversock
{
        buffer_clear(buffer)
        buffer_write_uint8(buffer, WEAPON)
        buffer_write_uint8(buffer, 4)
        buffer_write_float32(buffer, argument0)
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_uint32(buffer, argument3)
        buffer_write_uint32(buffer, argument4)
        socket_write_message(socket, buffer)
}

#define FireGun
//argument0: x
//argument1: y
//argument2: angle
//argument3: who fired it
var g;

with obj_serversock
{
        buffer_clear(buffer)
        buffer_write_uint8(buffer, WEAPON)
        buffer_write_uint8(buffer, WEAPON_GUN)
        buffer_write_float32(buffer, argument0)
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_uint32(buffer, argument3)
        socket_write_message(socket, buffer)
}
g = instance_create(argument0, argument1, obj_bullet_server)
g.image_angle = argument2
g.direction = argument2
g.firedby = argument3

#define FireGrenade
//argument0: x
//argument1: y
//argument2: angle
//argument3: who fired it
var g;

with obj_serversock
{
        buffer_clear(buffer)
        buffer_write_uint8(buffer, WEAPON)
        buffer_write_uint8(buffer, WEAPON_GRENADE)
        buffer_write_float32(buffer, argument0)
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_uint32(buffer, argument3)
        socket_write_message(socket, buffer)
}
g = instance_create(argument0, argument1, obj_grenade_server)
g.direction = argument2
g.firedby = argument3

#define FireShotgun
//argument0: x
//argument1: y
//argument2: angle
//argument3: who fired it
//argument4: spread amount
with obj_serversock
{
        buffer_clear(buffer)
        buffer_write_uint8(buffer, WEAPON)
        buffer_write_uint8(buffer, WEAPON_SHOTGUN)
        buffer_write_float32(buffer, argument0)
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_uint32(buffer, argument3)
        buffer_write_uint32(buffer, argument4)
        socket_write_message(socket, buffer)
}

var i, g, angle, spd;
angle = argument2
spd = shotgun_shootspeed
for(i=0; i<argument4; i+=1)
{
    g = instance_create(argument0, argument1, obj_pellet_server)
    g.direction = angle
    g.speed = spd
    g.firedby = argument3
    if is_odd(i)
        angle -= 12*(i+1)
    else
        angle += 12*(i+1)
    spd -= 2.5
}

#define Emote
//argument0: player id
//argument1: emote number (set to -1 for none)
//argument2: eye emote (optional)
with obj_serversock
{
    buffer_clear(buffer)
    buffer_write_uint8(buffer, EMOTICON)
    buffer_write_uint32(buffer, argument0)
    buffer_write_int16(buffer, argument1)
    buffer_write_uint8(buffer, argument2)
    socket_write_message(socket, buffer)
}

#define Tune
//argument0: tune name. look at obj_server create code to see which tunes you can use.
//argument1: value.
with obj_serversock
{
        buffer_clear(buffer)
        buffer_write_uint8(buffer, TUNE)
        buffer_write_string(buffer, argument0)
        buffer_write_float32(buffer, argument1)
        socket_write_message(socket, buffer)
}

#define TuneTarget
//argument0: tune name. look at obj_server create code to see which tunes you can use.
//argument1: value.
//argument2: player ID to tune.
with obj_serversock
{
    if pid == argument2
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, TUNE)
        buffer_write_string(buffer, argument0)
        buffer_write_intv(buffer, argument1)
        socket_write_message(socket, buffer)
    }
}

#define Pickup
//argument0: pickup type.
//
//if argument0 is POWERUP_WEAPON
//argument1: specify the weapon name. (can't be WEAPON_NONE)
//argument2: x position of the pickup
//argument3: y position of the pickup
//argument4: false if being picked up, true if respawning
//
//if it's something else
//argument1: x position of the pickup
//argument2: y position of the pickup
//argument3: false if being picked up, true if respawning

with obj_serversock
{
    buffer_clear(buffer)
    buffer_write_uint8(buffer, PICKUP)
    buffer_write_uint8(buffer, argument0)
    if argument0 == POWERUP_WEAPON
    {
        buffer_write_uint8(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_float32(buffer, argument3)
        buffer_write_uint8(buffer, argument4)
    }
    else
    {
        buffer_write_float32(buffer, argument1)
        buffer_write_float32(buffer, argument2)
        buffer_write_uint8(buffer, argument3)
    }
    socket_write_message(socket, buffer)
}

#define PickupTarget
//argument0: player ID target
//argument1: pickup type.
//
//if argument1 is POWERUP_WEAPON
//argument2: specify the weapon name. (can't be WEAPON_NONE)
//argument3: x position of the pickup
//argument4: y position of the pickup
//argument5: false if being picked up, true if respawning
//
//if it's something else
//argument2: x position of the pickup
//argument3: y position of the pickup
//argument4: false if being picked up, true if respawning

with obj_serversock
{
    if argument0 == pid
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, PICKUP)
        buffer_write_uint8(buffer, argument1)
        if argument1 == POWERUP_WEAPON
        {
            buffer_write_uint8(buffer, argument2)
            buffer_write_float32(buffer, argument3)
            buffer_write_float32(buffer, argument4)
            buffer_write_uint8(buffer, argument5)
        }
        else
        {
            buffer_write_float32(buffer, argument2)
            buffer_write_float32(buffer, argument3)
            buffer_write_uint8(buffer, argument4)
        }
        socket_write_message(socket, buffer)
    }
}

#define SendBroadcast
//SendBroadcast(player_id, message)
//Sends a broadcast to the specified player ID. use -1 to send to everyone
with obj_serversock
{
    if argument0 == -1
    {
            buffer_clear(buffer)
            buffer_write_uint8(buffer, BROADCAST)
            buffer_write_string(buffer, argument1)
            socket_write_message(socket, buffer)
    }
    else
    {
        if pid == argument0
        {
            buffer_clear(buffer)
            buffer_write_uint8(buffer, BROADCAST)
            buffer_write_string(buffer, argument1)
            socket_write_message(socket, buffer)
        }
    }
}

#define Kick
//Kick(player_id, reason)
//Disconnects a player with a reason
var oldname, old_x, old_y, old_bodycolor, was_ready, oldip;
with obj_serversock
{
    if argument0 == pid
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, KICK)
        buffer_write_string(buffer, argument1)
        socket_write_message(socket, buffer)
        alarm[11] = 15
        oldip = ip
        oldname = name
        old_x = x
        old_y = y
        old_bodycolor = otherbodycolor
        was_ready = ready
        ready = false
    }
}
Print(all, "[server]: Client dropped. cid="+str(argument0)+" addr="+str(oldip)+" reason='"+argument1+"'", 0, 1)
if was_ready
{
    SendChat(-1, oldname+" left the game. ("+argument1+")")
    CreateDeath(0, old_bodycolor, old_x, old_y)
    CreateSound(0, SOUND_PLAYER_DIE)
    with obj_serversock
    {
        if argument0 != pid
        {
            buffer_clear(buffer)
            buffer_write_uint8(buffer, DESTROY)
            buffer_write_uint32(buffer, argument0)
            socket_write_message(socket, buffer)
        }
    }
}

#define KickSocket
//KickSocket(socket, reason)
//Disconnects a player with a reason
//Use this if the player is still connecting and you haven't assigned an ID to them
//Like, for example, the server is full...
buffer_clear(buffer)
buffer_write_uint8(buffer, KICK)
buffer_write_string(buffer, argument1)
socket_write_message(argument0, buffer)
repeat 10 socket_update_write(argument0)
with obj_server
{
    kicksocket = argument0
    alarm[11] = 15
    players-=1
}
with obj_serversock
{
    if argument0 == socket then instance_destroy()
}

#define IsTeamplay
return global.m_isteamplay

#define TeamName
team = argument0
if IsTeamplay()
{
    if team == TEAM_RED then
        return "red team"
    else if team == TEAM_BLUE then
        return "blue team"
}
else
{
    if team == 0 then
        return "game"
}

return "spectators"

#define RespawnFlag
//RespawnFlag(team)
//respawn a flag back to its' spawn point
switch(argument0)
{
    case TEAM_RED:
    with obj_server_redflag
    {
        x = xstart
        y = ystart
        has_flag = -2
    }
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, EDITFLAG)
        buffer_write_uint8(buffer, TEAM_RED)
        buffer_write_int32(buffer, -2)
        buffer_write_float32(buffer, obj_server_redflag.xstart)
        buffer_write_float32(buffer, obj_server_redflag.ystart)
        socket_write_message(socket, buffer)
    }
    break
    case TEAM_BLUE:
    with obj_server_blueflag
    {
        x = xstart
        y = ystart
        has_flag = -2
    }
    with obj_serversock
    {
        buffer_clear(buffer)
        buffer_write_uint8(buffer, EDITFLAG)
        buffer_write_uint8(buffer, TEAM_BLUE)
        buffer_write_int32(buffer, -2)
        buffer_write_float32(buffer, obj_server_blueflag.xstart)
        buffer_write_float32(buffer, obj_server_blueflag.ystart)
        socket_write_message(socket, buffer)
    }
    break
}

#define LoadMap
//LoadMap(mapname)
//load a new map.
var mapname;
mapname = str(argument0)
TeamScore[TEAM_RED] = 0
TeamScore[TEAM_BLUE] = 0
obj_server.map = mapname
with obj_serversock
{
    Kill(0, pid)
    alive = true
    respawn = -1
    hps = 10
    ammos[WEAPON_GUN] = 10
    ready = false
    points = 0
    can_entergame = false
    with obj_server
    {
        gamemode = newgamemode
        event_perform(ev_other, ev_user0)
        md5_begin()
        md5_read_file("data\maps\"+map+".map")
        md5_end()
        svmaphash = md5_result()
    }
    buffer_clear(buffer)
    buffer_write_uint8(buffer, MAPCHANGE)
    buffer_write_string(buffer, mapname+".map")
    socket_write_message(socket, buffer)
}

#define ReloadMap
//ReloadMap()
//reload current map.
TeamScore[TEAM_RED] = 0
TeamScore[TEAM_BLUE] = 0
with obj_serversock
{
    Kill(0, pid)
    alive = true
    respawn = -1
    hps = 10
    ammos[WEAPON_GUN] = 10
    ready = false
    points = 0
    can_entergame = false
    with obj_server
    {
        gamemode = newgamemode
        event_perform(ev_other, ev_user0)
    }
    buffer_clear(buffer)
    buffer_write_uint8(buffer, MAPCHANGE)
    buffer_write_string(buffer, obj_server.map)
    socket_write_message(socket, buffer)
}

