AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help for a useful plugin? (https://forums.alliedmods.net/showthread.php?t=131566)

Turkish 07-06-2010 14:22

Help for a useful plugin?
 
Hi im very new to scripting (sorry for my english (usualy gramer)),
I want to make a plugin I want to learn some useful things for my plugin.
First I want to make a plugin that if some one is not in a team (spectator) and wants to type "respawn" this plugin will kick the player.
Pls help me with this plugin .
What i know :
If, If else , Case if ,for
What i didnt understand by looking to the plugin .sma's:
for i=.......... , max players

I can understand well please help me

abdul-rehman 07-06-2010 14:28

Re: Help for a useful plugin?
 
Search for some useful tutorials on the code's and snippets section..:up:

Turkish 07-06-2010 14:57

Re: Help for a useful plugin?
 
Thanks but i searceh a lot but i couldn't find what I was searching can you give me links?

drekes 07-06-2010 15:03

Re: Help for a useful plugin?
 
about the for loops. It's actually quite simple.

PHP Code:

new players[32]; // To hold the players id.
new pnum// The amount of players.
new tempid// To store the temporary player ids

get_players(playerspnum); // Counts the players

for(0pnumi++) 
{    
    
// i < pnum means as long as i smaller then the amount of players, it continues to loop
    
tempid players[i// store the temporary id in a var

    
if(!is_user_alive(tempid))// If he is dead, skip him
        
continue;

    
set_user_health(tempid100); // Just an example


Respawn thing:
PHP Code:

#include <amxmodx>
#include <hamsandwich>

#pragma semicolon 1

public plugin_init()
{
    
register_plugin("respawn""1.0""Drekes");
    
    
register_clcmd("say respawn""cmd_respawn");
}

public 
cmd_respawn(id)
{
    if(
get_user_team(id) != || get_user_team(id) != 2)
    {
        new 
userid get_user_userid(id);
        
        
server_cmd("amx_kick %i ^"Don't try to respawn when you are not in a team^"", userid);
        
        return PLUGIN_HANDLED;
    }
    
    ExecuteHamB(Ham_CS_RoundRespawn, id);
    
    return PLUGIN_HANDLED;


Not tested but should work

SnoW 07-06-2010 16:52

Re: Help for a useful plugin?
 
Quote:

Originally Posted by drekes (Post 1230106)
about the for loops. It's actually quite simple.

PHP Code:

new players[32]; // To hold the players id.
new pnum// The amount of players.
new tempid// To store the temporary player ids

get_players(playerspnum); // Counts the players

for(0pnumi++) 
{    
    
// i < pnum means as long as i smaller then the amount of players, it continues to loop
    
tempid players[i// store the temporary id in a var

    
if(!is_user_alive(tempid))// If he is dead, skip him
        
continue;

    
set_user_health(tempid100); // Just an example



The variable named "i" is never created. Also your way of using continue is horrible. I believe flagging alive players doesn't give you that much false positives.
.
PHP Code:

for( new playerplayer pnumplayer++ )
     if( 
is_user_alive( ( tempid playersplayer ] ) ) )
          
set_user_healthtempid100 ); 


drekes 07-06-2010 17:00

Re: Help for a useful plugin?
 
Quote:

Originally Posted by SnoW (Post 1230224)
The variable named "i" is never created. Also your way of using continue is horrible. I believe flagging alive players doesn't give you that much false positives.
.
PHP Code:

for( new playerplayer pnumplayer++ )
     if( 
is_user_alive( ( tempid playersplayer ] ) ) )
          
set_user_healthtempid100 ); 


I looked over i.
But i don't understand what's wrong with the continue. I learned it this way.

Jelle 07-06-2010 18:53

Re: Help for a useful plugin?
 
PHP Code:

    if(get_user_team(id) != || get_user_team(id) != 2

to

PHP Code:

if ( get_user_team(id) == ) return 

Just an idea. Then you do not need two, but only one check. As I see it, it is a bit faster.

SnoW 07-07-2010 05:51

Re: Help for a useful plugin?
 
Quote:

Originally Posted by Jelle (Post 1230335)
PHP Code:

    if(get_user_team(id) != || get_user_team(id) != 2

to

PHP Code:

if ( get_user_team(id) == ) return 

Just an idea. Then you do not need two, but only one check. As I see it, it is a bit faster.

It's twice as fast( Only because the native is also called unnecessarily twice ). Somehow what I'd use is:

PHP Code:

switch( cs_get_user_teamid ) )
{
     case 
CS_TEAM_UNASSIGNEDCS_TEAM_SPECTATOR:
     {
          
//Action
     
}


Quote:

Originally Posted by drekes (Post 1230232)
I looked over i.
But i don't understand what's wrong with the continue. I learned it this way.

You shouldn't use jumps( breaks, continues and returns ) as they just make the code harder to perceive and mess it up. You want to keep things simple and it's much easier to think that you eat if you'r hungry instead of if you'r not hungry you skip eating.

Turkish 07-07-2010 16:44

Re: Help for a useful plugin?
 
When i tested it i didnt work :(
I was spectator i typed respawn in chat i couldnt see that i typed respawn but when i closed this plugin i could see.
And it didnt kick me when i was spectator and typed "respawn"

drekes 07-07-2010 17:05

Re: Help for a useful plugin?
 
I changed it a bit like snow said. It doesn't work on my listenserver because id is not found, but i think it will on a real server.

PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <cstrike>

#pragma semicolon 1

public plugin_init()
{
    
register_plugin("respawn""1.0""Drekes");
    
    
register_clcmd("say respawn""cmd_respawn");
}

public 
cmd_respawn(id)
{
    switch(
cs_get_user_team(id))
    {
        case 
CS_TEAM_UNASSIGNEDCS_TEAM_SPECTATOR
        {
            new 
userid get_user_userid(id);
            
            
server_cmd("amx_kick %i ^"Dont try to respawn when you are not in a team^""userid);
            
            return 
PLUGIN_HANDLED;
        }
    }
    
    
ExecuteHamB(Ham_CS_RoundRespawnid);
    
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 07:06.

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