Raised This Month: $ Target: $400
 0% 

[Help] What's wrong with this code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Inject
Junior Member
Join Date: Sep 2013
Old 09-15-2013 , 11:26   [Help] What's wrong with this code?
Reply With Quote #1

Code:
// Include files
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "0.1"

// end includes

public Plugin:myinfo =
{
   name = "GiveLR", //name of the plugin, for coding refrence
   author = "Inject", //who made the plugin or coding
   description = "Giving LR", //self explanitory
   version = PLUGIN_VERSION, //look at the previouse code
   url = "http://www.playmakers-il.net"
};

public OnPluginStart()
{
    RegConsoleCmd("sm_givelr", Command_GiveLR, "Giving LR by name.");
}

public Action:Command_GiveLR(client, args)
{
if(args < 1)
{

    if(client != 0 && GetClientTeam(client) > 1)
    {
        
        decl String:TeamNum[5];
        GetCmdArgString(TeamNum, sizeof(TeamNum));
        new team = StringToInt(TeamNum);
        new TCount = GetTeamClientCount(CS_TEAM_T);
        
        if(team == CS_TEAM_T && TCount >= 1)
        {
PrintToChat(client, "[SM] Usage: sm_givelr <Player_Name>");
else
PrintToChat(client, "[SM] LR is not in progress.")
return Plugin_Handled;
}

    new String:name[32], target = -1;
    GetCmdArg(1, name, sizeof(name));
 
    for (new i=1; i<=MaxClients; i++)
    {
        if (!IsClientConnected(i))
        {
            continue;
        }
        decl String:other[32];
        GetClientName(i, other, sizeof(other));
        if (StrEqual(name, other))
        {
            target = i;
        }
    }
 
    if (target == -1)
    {
        PrintToConsole(client, "Could not find any player with the name: \"%s\"", name);
        return Plugin_Handled;
    }
    
            decl String:cname[64]
    GetClientName(target, cname, sizeof(cname));
    ServerCommand("sm_respawn \"%s\" ", cname)
 
    return Plugin_Handled;
}
I want to make mod that you can give your LR(Last-Request) to another player, I am coding only 1 week, and I don't know what I did wrong.
Inject is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-15-2013 , 12:42   Re: [Help] What's wrong with this code?
Reply With Quote #2

So you want to kill the player that has an LR and respawn the chosen player?
SM9 is offline
Inject
Junior Member
Join Date: Sep 2013
Old 09-15-2013 , 13:00   Re: [Help] What's wrong with this code?
Reply With Quote #3

Quote:
Originally Posted by xCoderx View Post
So you want to kill the player that has an LR and respawn the chosen player?
Yeah, exactly
Inject is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-15-2013 , 13:48   Re: [Help] What's wrong with this code?
Reply With Quote #4

Sorry about long response.

Try this: (Untested)

PHP Code:
// Include files
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "0.1"

// end includes

public Plugin:myinfo =
{
    
name "GiveLR"//name of the plugin, for coding refrence
    
author "Inject"//who made the plugin or coding
    
description "Giving LR"//self explanitory
    
version PLUGIN_VERSION//look at the previouse code
    
url "http://www.playmakers-il.net"
};

new 
bool:isLastPlayer[MAXPLAYERS+1]    = { false, ... };

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_givelr"Command_GiveLR"Giving LR by name.");
}

public 
Action:Command_GiveLR(clientargs)
{
    if (
args 1)
        
ReplyToCommand(client"[SM] Usage: sm_givelr <name>");
    
    else
    {
        new 
team GetClientTeam(client);
        new 
CountT TCount();
        if(
client != 0)
        {
            if(
team == CS_TEAM_T)
            {
                if(
IsPlayerAlive(client))
                {
                    if(
CountT 1)
                    {
                        
PrintToChat(client"LR is not in progress!")
                        
PrintToConsole(client"LR is not in progress!");
                    }
                    
                    else
                    {
                        new 
String:input[32], target = -1;
                        
GetCmdArg(1inputsizeof(input));
                        
decl String:targetname[32];
                        
                        for (new 
i=1i<=MaxClientsi++)
                        {
                            if (!
IsClientConnected(i))
                            {
                                continue;
                            }
                            
                            
decl String:other[32];
                            
GetClientName(iothersizeof(other));
                            if (
StrContains(inputother))
                            {
                                
target i;
                                
GetClientName(targettargetnamesizeof(targetname));
                            }
                        }
                        
                        if(
IsClientInGame(target))
                        {
                            if(
GetClientTeam(target) == CS_TEAM_CT)
                            {
                                
PrintToChat(client"You can only give your LR to Terrorists!");
                                
PrintToConsole(client"You can only give your LR to Terrorists!");
                            }
                            else
                            {
                                
CS_RespawnPlayer(target);
                                
ForcePlayerSuicide(client);
                            }
                        }
                        else
                        {
                            
PrintToChat(client"Could not find any player with the name: \"%s\""targetname);
                            
PrintToConsole(client"Could not find any player with the name: \"%s\""targetname);
                        }
                    }
                }
                else
                {
                    
PrintToChat(client"You must alive!");
                    
PrintToConsole(client"You must alive!");
                }
                
            }
            else
            {
                
PrintToChat(client"You must be a Terrorist!");
                
PrintToConsole(client"You must be a Terrorist!");
            }
        }
    }
    return 
Plugin_Continue;
}


TCount(){
    new 
iTotalRed;
    
    for(new 
client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
            
iTotalRed++;
            
            case 
CS_TEAM_CT:{}
        }
        if(
iTotalRed == 1){
            
isLastPlayer[client] = true;
        }
        else{
            
isLastPlayer[client] = false;
        }
    }
    return 
iTotalRed;


Last edited by SM9; 09-15-2013 at 14:28.
SM9 is offline
Inject
Junior Member
Join Date: Sep 2013
Old 09-15-2013 , 15:51   Re: [Help] What's wrong with this code?
Reply With Quote #5

Quote:
Originally Posted by xCoderx View Post
Sorry about long response.

Try this: (Untested)

PHP Code:
// Include files
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "0.1"

// end includes

public Plugin:myinfo =
{
    
name "GiveLR"//name of the plugin, for coding refrence
    
author "Inject"//who made the plugin or coding
    
description "Giving LR"//self explanitory
    
version PLUGIN_VERSION//look at the previouse code
    
url "http://www.playmakers-il.net"
};

new 
bool:isLastPlayer[MAXPLAYERS+1]    = { false, ... };

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_givelr"Command_GiveLR"Giving LR by name.");
}

public 
Action:Command_GiveLR(clientargs)
{
    if (
args 1)
        
ReplyToCommand(client"[SM] Usage: sm_givelr <name>");
    
    else
    {
        new 
team GetClientTeam(client);
        new 
CountT TCount();
        if(
client != 0)
        {
            if(
team == CS_TEAM_T)
            {
                if(
IsPlayerAlive(client))
                {
                    if(
CountT 1)
                    {
                        
PrintToChat(client"LR is not in progress!")
                        
PrintToConsole(client"LR is not in progress!");
                    }
                    
                    else
                    {
                        new 
String:input[32], target = -1;
                        
GetCmdArg(1inputsizeof(input));
                        
decl String:targetname[32];
                        
                        for (new 
i=1i<=MaxClientsi++)
                        {
                            if (!
IsClientConnected(i))
                            {
                                continue;
                            }
                            
                            
decl String:other[32];
                            
GetClientName(iothersizeof(other));
                            if (
StrContains(inputother))
                            {
                                
target i;
                                
GetClientName(targettargetnamesizeof(targetname));
                            }
                        }
                        
                        if(
IsClientInGame(target))
                        {
                            if(
GetClientTeam(target) == CS_TEAM_CT)
                            {
                                
PrintToChat(client"You can only give your LR to Terrorists!");
                                
PrintToConsole(client"You can only give your LR to Terrorists!");
                            }
                            else
                            {
                                
CS_RespawnPlayer(target);
                                
ForcePlayerSuicide(client);
                            }
                        }
                        else
                        {
                            
PrintToChat(client"Could not find any player with the name: \"%s\""targetname);
                            
PrintToConsole(client"Could not find any player with the name: \"%s\""targetname);
                        }
                    }
                }
                else
                {
                    
PrintToChat(client"You must alive!");
                    
PrintToConsole(client"You must alive!");
                }
                
            }
            else
            {
                
PrintToChat(client"You must be a Terrorist!");
                
PrintToConsole(client"You must be a Terrorist!");
            }
        }
    }
    return 
Plugin_Continue;
}


TCount(){
    new 
iTotalRed;
    
    for(new 
client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
            
iTotalRed++;
            
            case 
CS_TEAM_CT:{}
        }
        if(
iTotalRed == 1){
            
isLastPlayer[client] = true;
        }
        else{
            
isLastPlayer[client] = false;
        }
    }
    return 
iTotalRed;


Working but it's not respawning the target, It's giving respawn to you, and not to the target...
Inject is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-15-2013 , 16:06   Re: [Help] What's wrong with this code?
Reply With Quote #6

Try this:

PHP Code:
// Include files
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "0.1"

// end includes

public Plugin:myinfo =
{
    
name "GiveLR"//name of the plugin, for coding refrence
    
author "Inject"//who made the plugin or coding
    
description "Giving LR"//self explanitory
    
version PLUGIN_VERSION//look at the previouse code
    
url "http://www.playmakers-il.net"
};

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_givelr"Command_GiveLR"Giving LR by name.");
}

public 
Action:Command_GiveLR(clientargs)
{
    if (
args 1)
        
ReplyToCommand(client"[SM] Usage: sm_givelr <name>");
    
    else
    {
        new 
team GetClientTeam(client);
        new 
CountT TCount();
        if(
client != 0)
        {
            if(
team == CS_TEAM_T)
            {
                if(
IsPlayerAlive(client))
                {
                    if(
CountT 1)
                    {
                        
PrintToChat(client"LR is not in progress!")
                        
PrintToConsole(client"LR is not in progress!");
                    }
                    
                    else
                    {
                        new 
String:input[32], target = -1;
                        
GetCmdArg(1inputsizeof(input));
                        
decl String:targetname[32];
                        
decl String:other[32];
                        
                        for (new 
i=1i<=MaxClientsi++)
                        {
                            if (!
IsClientConnected(i) || GetClientTeam(i) == CS_TEAM_CT || client == i)
                            {
                                continue;
                            }
                            
                            
GetClientName(iothersizeof(other));
                            if (
StrEqual(inputother))
                            {
                                
target i;
                                
GetClientName(targettargetnamesizeof(targetname));
                            }
                        }
                        
                        if(
IsClientInGame(target))
                        {
                            if(
GetClientTeam(target) == CS_TEAM_CT)
                            {
                                
PrintToChat(client"You can only give your LR to Terrorists!");
                                
PrintToConsole(client"You can only give your LR to Terrorists!");
                            }
                            else
                            {
                                if(
target == client){ // Don't go any further if target is the client.
                                    
PrintToChat(client"Error Target is Client executing cmd!")
                                    
PrintToConsole(client"Error Target is Client executing cmd!");
                                    return 
Plugin_Handled;
                                }
                                
                                else
                                {
                                    
CS_RespawnPlayer(target); // 
                                    
ForcePlayerSuicide(client);
                                }
                            }
                        }
                        else
                        {
                            
PrintToChat(client"Could not find any player with the name: \"%s\""targetname);
                            
PrintToConsole(client"Could not find any player with the name: \"%s\""targetname);
                        }
                    }
                }
                else
                {
                    
PrintToChat(client"You must alive!");
                    
PrintToConsole(client"You must alive!");
                }
                
            }
            else
            {
                
PrintToChat(client"You must be a Terrorist!");
                
PrintToConsole(client"You must be a Terrorist!");
            }
        }
    }
    return 
Plugin_Continue;
}


TCount(){
    new 
iTotalRed;
    
    for(new 
client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
            
iTotalRed++;
            
            case 
CS_TEAM_CT:{}
        }
    }
    return 
iTotalRed;

But you will now have to use full name of the target.
PS: I'm also new to coding, so if this does not work then I ask somebody else has a go. Cheers.

Last edited by SM9; 09-15-2013 at 19:14. Reason: Quick update.
SM9 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 17:09.


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