Raised This Month: $51 Target: $400
 12% 

!Redie to spawn on Alive players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SkinnyBruv
AlliedModders Donor
Join Date: Feb 2013
Location: Straya
Old 11-02-2013 , 03:44   !Redie to spawn on Alive players
Reply With Quote #1

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
__________________
www.ancientgaming.net is my story.
Everything happens for a reason.
Nothing is random...
#Do you even AGN...
SkinnyBruv is offline
Send a message via Skype™ to SkinnyBruv
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 11-02-2013 , 05:17   Re: !Redie to spawn on Alive players
Reply With Quote #2

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.
xf117 is offline
Send a message via ICQ to xf117
SkinnyBruv
AlliedModders Donor
Join Date: Feb 2013
Location: Straya
Old 11-02-2013 , 05:59   Re: !Redie to spawn on Alive players
Reply With Quote #3

Quote:
Originally Posted by xf117 View Post
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
__________________
www.ancientgaming.net is my story.
Everything happens for a reason.
Nothing is random...
#Do you even AGN...
SkinnyBruv is offline
Send a message via Skype™ to SkinnyBruv
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-02-2013 , 07:55   Re: !Redie to spawn on Alive players
Reply With Quote #4

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

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
SkinnyBruv
AlliedModders Donor
Join Date: Feb 2013
Location: Straya
Old 11-04-2013 , 05:43   Re: !Redie to spawn on Alive players
Reply With Quote #5

Still doesnt work.
__________________
www.ancientgaming.net is my story.
Everything happens for a reason.
Nothing is random...
#Do you even AGN...
SkinnyBruv is offline
Send a message via Skype™ to SkinnyBruv
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-04-2013 , 08:27   Re: !Redie to spawn on Alive players
Reply With Quote #6

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.
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 11-04-2013 at 08:30.
Bimbo1 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-04-2013 , 08:39   Re: !Redie to spawn on Alive players
Reply With Quote #7

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

}
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-04-2013 , 08:43   Re: !Redie to spawn on Alive players
Reply With Quote #8

it's missing a "]", i'm not modifying(or modifing, i dunno) it, as it might mess up again.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
SkinnyBruv
AlliedModders Donor
Join Date: Feb 2013
Location: Straya
Old 11-04-2013 , 16:56   Re: !Redie to spawn on Alive players
Reply With Quote #9

Still pending on a new code, due to !redie teleports you to players AND start spawn locations
__________________
www.ancientgaming.net is my story.
Everything happens for a reason.
Nothing is random...
#Do you even AGN...
SkinnyBruv is offline
Send a message via Skype™ to SkinnyBruv
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-04-2013 , 18:35   Re: !Redie to spawn on Alive players
Reply With Quote #10

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; 
}
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 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 02:26.


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