Raised This Month: $ Target: $400
 0% 

Help for a useful plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Turkish
Junior Member
Join Date: Jul 2010
Old 07-06-2010 , 14:22   Help for a useful plugin?
Reply With Quote #1

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
Turkish is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-06-2010 , 14:28   Re: Help for a useful plugin?
Reply With Quote #2

Search for some useful tutorials on the code's and snippets section..
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Turkish
Junior Member
Join Date: Jul 2010
Old 07-06-2010 , 14:57   Re: Help for a useful plugin?
Reply With Quote #3

Thanks but i searceh a lot but i couldn't find what I was searching can you give me links?
__________________
Map Maker
Turkish is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-06-2010 , 15:03   Re: Help for a useful plugin?
Reply With Quote #4

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
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 07-06-2010 at 15:10.
drekes is offline
Send a message via MSN to drekes
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 07-06-2010 , 16:52   Re: Help for a useful plugin?
Reply With Quote #5

Quote:
Originally Posted by drekes View Post
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 ); 
SnoW is offline
Send a message via MSN to SnoW
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-06-2010 , 17:00   Re: Help for a useful plugin?
Reply With Quote #6

Quote:
Originally Posted by SnoW View Post
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.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 07-06-2010 , 18:53   Re: Help for a useful plugin?
Reply With Quote #7

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.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 07-07-2010 , 05:51   Re: Help for a useful plugin?
Reply With Quote #8

Quote:
Originally Posted by Jelle View Post
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 View Post
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.

Last edited by SnoW; 07-07-2010 at 05:53.
SnoW is offline
Send a message via MSN to SnoW
Turkish
Junior Member
Join Date: Jul 2010
Old 07-07-2010 , 16:44   Re: Help for a useful plugin?
Reply With Quote #9

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"
__________________
Map Maker
Turkish is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-07-2010 , 17:05   Re: Help for a useful plugin?
Reply With Quote #10

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;

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
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 07:06.


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