AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   !Redie to spawn on Alive players (https://forums.alliedmods.net/showthread.php?t=229130)

SkinnyBruv 11-02-2013 03:44

!Redie to spawn on Alive players
 
PHP Code:

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>

#pragma semicolon 1

#define PLUGIN_VERSION     "1.4"

new blockCommand;
new 
g_Collision;
new 
Handle:cvar_adverts INVALID_HANDLE;
new 
bool:g_IsGhost[MAXPLAYERS+1];

public 
Plugin:myinfo =
{
    
name "Redie 4 SourceMod",
    
author "MeoW",
    
description "Return as a ghost after you died.",
    
version PLUGIN_VERSION,
    
url "http://www.trident-gaming.net/"
};

public 
OnPluginStart()
{
    
HookEvent("round_end"Event_Round_EndEventHookMode_Pre);
    
HookEvent("round_start"Event_Round_StartEventHookMode_Pre);    
    
HookEvent("player_spawn"Event_Player_Spawn);
    
HookEvent("player_death"Event_Player_Death);
    
RegConsoleCmd("sm_redie"Command_Redie);
    
CreateTimer(120.0advert_,TIMER_REPEAT);
    
CreateConVar("sm_redie_version"PLUGIN_VERSION"Redie Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
cvar_adverts CreateConVar("sm_redie_adverts""1""If enabled, redie will produce an advert every 2 minutes.");
    
g_Collision FindSendPropInfo("CBaseEntity""m_CollisionGroup");
}

public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_WeaponCanUseOnWeaponCanUse);
}

public 
OnClientPostAdminCheck(client)
{
    
g_IsGhost[client] = false;
}

public 
Action:Event_Round_End(Handle:event, const String:name[], bool:dontBroadcast
{
    
blockCommand false;
}

public 
Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast
{
    
blockCommand true;
}


public 
Action:Event_Player_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(
g_IsGhost[client])
    {
        
SetEntProp(clientProp_Send"m_nHitboxSet"2);
        
g_IsGhost[client] = false;
    }
    else
    {
        
SetEntProp(clientProp_Send"m_nHitboxSet"0);
    }
}

public 
Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
PrintToChat(client"\x01[\x03AGNRedie\x01] \x04Type !redie into chat to respawn as a ghost.");
}

public 
Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon)
{
    if(
GetEntProp(clientProp_Send"m_lifeState") == 1)
    {
        
buttons &= ~IN_USE;
    }
    return 
Plugin_Continue;
}

public 
Action:Command_Redie(clientargs)
{
    if(
blockCommand)
    {
        if (!
IsPlayerAlive(client))
        {
            if(
GetClientTeam(client) > 1)
            {
                
g_IsGhost[client] = true;

                
CS_RespawnPlayer(client);
                
decl Float:fOrigin[3];
                new 
iRandom GetRandomInt(1MaxClients);
                for(new 
1<= MaxClientsi++)
                {
                    if(
== iRandom)
                    {
                        
GetClientAbsOrigin(ifOrigin);
                        if(
IsClientInGame(client) && IsPlayerAlive(client) && IsClientInGame(i))
                        {
                            
TeleportEntity(clientfOriginNULL_VECTORNULL_VECTOR);
                            break;
                        }
                    }
                    else break;
                }  
                new 
weaponIndex;
                for (new 
0<= 3i++)
                {
                    if ((
weaponIndex GetPlayerWeaponSlot(clienti)) != -1)
                    {  
                        
RemovePlayerItem(clientweaponIndex);
                        
RemoveEdict(weaponIndex);
                    }
                }
                
SetEntProp(clientProp_Send"m_lifeState"1);
                
SetEntData(clientg_Collision24true);
                
PrintToChat(client"\x01[\x03Redie\x01] \x04You are now a ghost.");
            }
            else
            {
                
PrintToChat(client"\x01[\x03Redie\x01] \x04You must be on a team.");
            }
        }
        else
        {
            
PrintToChat(client"\x01[\x03Redie\x01] \x04You must be dead to use redie.");
        }
    }
    else
    {
        
PrintToChat(client"\x01[\x03Redie\x01] \x04Please wait for the new round to begin.");
    }
    return 
Plugin_Handled;


public 
Action:OnWeaponCanUse(clientweapon)
{
    if(
GetEntProp(clientProp_Send"m_lifeState") == 1)
        return 
Plugin_Handled;
    
    return 
Plugin_Continue;
}

public 
Action:advert(Handle:timer)
{
    if(
GetConVarInt(cvar_adverts))
    {
        
PrintToChatAll ("\x01[\x03AGNRedie\x01] \x04This server is running a modified version of !redie.");
    }
    return 
Plugin_Continue;


Can somebody help me fix this problem i have.

Like if you type !redie multiple times, 1 out of like 15 chances you will actually spawn on an alive player but the rest of them you actually spawn in the spawn locations.

Can someone help me fix the code.

Could we actually somehow remove the spawn locations just for redie so they only spawn on currently alive players?

Im not sure, just please comment and help out :D

xf117 11-02-2013 05:17

Re: !Redie to spawn on Alive players
 
You can't remove spawn location. When player spawns he WILL be spawned on proper spawn position of info_player_start(depends on the mod) entity. But you can teleport them immediately to another player. But if the player is in weird position, spawned player might stuck in the wall, floor or ceiling.

SkinnyBruv 11-02-2013 05:59

Re: !Redie to spawn on Alive players
 
Quote:

Originally Posted by xf117 (Post 2055899)
You can't remove spawn location. When player spawns he WILL be spawned on proper spawn position of info_player_start(depends on the mod) entity. But you can teleport them immediately to another player. But if the player is in weird position, spawned player might stuck in the wall, floor or ceiling.

Well then they'd type !redie and they'd respawn to a different place.

Could i grab a piece of code to implement into !redie

GsiX 11-02-2013 07:55

Re: !Redie to spawn on Alive players
 
PHP Code:

public Action:Command_Redie(clientargs

    if(
blockCommand
    { 
        
// your chance is here.. Note that it still take you forever to trying as sourcemod random is suck.
        
if ( GetRandomInt1) != )
        {
            if( 
client PrintToConsoleclient"[REDLE]; Try again..." );
            else    
PrintToChatclient"[REDLE]; Try again..." );
            return 
Plugin_Handled;
        }
        
        if (!
IsPlayerAlive(client)) 
        { 
            if(
GetClientTeam(client) > 1
            { 
                
g_IsGhost[client] = true

                
CS_RespawnPlayer(client); 
                
decl Float:fOrigin[3]; 
                new 
iRandom GetRandomInt(1MaxClients); 
                
                
// note that this loop may teleport you to the opposite team 
                // as well as teleport you to the null location.
                
for(new 1<= MaxClientsi++) 
                { 
                    if(
== iRandom
                    { 
                        
GetClientAbsOrigin(ifOrigin); 
                        if(
IsClientInGame(client) && IsPlayerAlive(client) && IsClientInGame(i)) 
                        { 
                            
TeleportEntity(clientfOriginNULL_VECTORNULL_VECTOR); 
                            break; 
                        } 
                    } 
                }   
                
                
                
// the rest of the code down here
                
    
return Plugin_Handled



SkinnyBruv 11-04-2013 05:43

Re: !Redie to spawn on Alive players
 
Still doesnt work.

Bimbo1 11-04-2013 08:27

Re: !Redie to spawn on Alive players
 
new players[MaxClients+1];
new count = 0;
for(new i = 1; i 0){

decl Float:pos[3];
GetClientAbsOrigin(players[GetRandomInt(0, count-1)], pos);
TeleportEntity(client, pos NULL_VECTOR, NULL_VECTOR);

}

fudge, tapatalk screwed this up... i will rewrite it later.

Bimbo1 11-04-2013 08:39

Re: !Redie to spawn on Alive players
 
new players[MaxClients+1];
new count = 0;
for(new i = 1; i <= MaxClients; i++){

if(IsClientInGame(i) && IsPlayerAlive(i)){

players[count] = i;
count++;

}

}
if(count > 0){

decl Float:pos[3]; GetClientAbsOrigin(players[GetRandomInt(0, count-1), pos);
TeleportEntity(client, pos, NULL_VECTOR, NULL_VECTOR);

}

Bimbo1 11-04-2013 08:43

Re: !Redie to spawn on Alive players
 
it's missing a "]", i'm not modifying(or modifing, i dunno) it, as it might mess up again.

SkinnyBruv 11-04-2013 16:56

Re: !Redie to spawn on Alive players
 
Still pending on a new code, due to !redie teleports you to players AND start spawn locations

Bimbo1 11-04-2013 18:35

Re: !Redie to spawn on Alive players
 
it's not pending anything. it's working fine(with just a thing added):
Code:

public Action:Command_Redie(client, args)
{
        if(blockCommand)
        {
                if (!IsPlayerAlive(client))
                {
                        if(GetClientTeam(client) > 1)
                        {
                                g_IsGhost[client] = true;

                                CS_RespawnPlayer(client);
                                new players[MaxClients+1];
                                new count = 0;
                                for(new i = 1; i <= MaxClients; i++){

                                        if(i != client && IsClientInGame(i) && IsPlayerAlive(i)){

                                                players[count] = i;
                                                count++;

                                        }

                                }
                                if(count > 0){

                                        decl Float:pos[3];
                                        GetClientAbsOrigin(players[GetRandomInt(0, count-1)], pos);
                                        TeleportEntity(client, pos, NULL_VECTOR, NULL_VECTOR);

                                }
                                new weaponIndex;
                                for (new i = 0; i <= 3; i++)
                                {
                                        if ((weaponIndex = GetPlayerWeaponSlot(client, i)) != -1)
                                        { 
                                                RemovePlayerItem(client, weaponIndex);
                                                RemoveEdict(weaponIndex);
                                        }
                                }
                                SetEntProp(client, Prop_Send, "m_lifeState", 1);
                                SetEntData(client, g_Collision, 2, 4, true);
                                PrintToChat(client, "\x01[\x03Redie\x01] \x04You are now a ghost.");
                        }
                        else
                        {
                                PrintToChat(client, "\x01[\x03Redie\x01] \x04You must be on a team.");
                        }
                }
                else
                {
                        PrintToChat(client, "\x01[\x03Redie\x01] \x04You must be dead to use redie.");
                }
        }
        else
        {
                PrintToChat(client, "\x01[\x03Redie\x01] \x04Please wait for the new round to begin.");
        }
        return Plugin_Handled;
}



All times are GMT -4. The time now is 00:15.

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