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

Need help!!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
s@ch
New Member
Join Date: Nov 2014
Old 01-01-2015 , 06:06   Need help!!
Reply With Quote #1

Hi guys,I am interested in developing a plugin for cs 1.6..but I don't know where to start.I have a good knowledge of c language.so can you guys give me the link for the same.
Thanks in advance
s@ch is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 01-01-2015 , 07:38   Re: Need help!!
Reply With Quote #2

Just read this tutorial:

https://forums.alliedmods.net/showthread.php?t=94381
zmd94 is offline
s@ch
New Member
Join Date: Nov 2014
Old 01-01-2015 , 12:08   Re: Need help!!
Reply With Quote #3

Thank you bro for replying.will read that thread... Will posts my doubt's here...if u don't mind.
s@ch is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 01-01-2015 , 12:13   Re: Need help!!
Reply With Quote #4

I'll wait. Hopefully I can help you as I'm also still learning.
zmd94 is offline
s@ch
New Member
Join Date: Nov 2014
Old 01-02-2015 , 01:50   Re: Need help!!
Reply With Quote #5

public cmd_hp(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED

new Arg1[24]
new Arg2[4]

//Get the command arguments from the console
read_argv(1, Arg1, 23)
read_argv(2, Arg2, 3)

//Convert the health from a string to a number
new Health = str_to_num(Arg2)

//Is the first character the @ symbol?
if (Arg1[0] == '@')
{
new Team = 0
//Check which team was specified.
//Note that we start from [1], this is okay
// it just means the @ isn't included
if (equali(Arg1[1], "CT"))
{
Team = 2
} else if (equali(Arg1[1], "T")) {
Team = 1
}
new players[32], num
//This function will fill the players[32] variable
// with valid player ids. num will contain the number
// of players that are valid.
get_players(players, num)
new i
for (i=0; i<num; i++)
{
if (!Team)
{
//Set this player's health
set_user_health(players[i], Health)
} else {
if (get_user_team(players[i]) == Team)
{
set_user_health(players[i], Health)
}
}
}
} else {
//finds a player id that matches the partial name given
//the 1 means that it will not target the player if he
// has immunity access
new player = cmd_target(id, Arg1, 1)
if (!player)
{
//this will print a message to the user who tried the command
//The format for this command is called "format()" style,
// where the first string formats the message according
// to any number of following parameters.
// %s means a string
// %d or %i means an integer
// %f means a float
// so "Hello %s, I am %d years old" will
// require a string and integer to follow
console_print(id, "Sorry, player %s could not be found or targetted!", Arg1)
return PLUGIN_HANDLED
} else {
set_user_health(player, Health)
}
}

return PLUGIN_HANDLED
}

i was reading the intro to amx scripting thread ..and i have a couple of doubts :

1.what is the use/meaning of this
read_argv(1, Arg1, 23)
read_argv(2, Arg2, 3)
2.why we have to Convert the health from a string to a number?
can you please tell me what is use/meaning of the following statements

if (Arg1[0] == '@')
{
new Team = 0
//Check which team was specified.
//Note that we start from [1], this is okay
// it just means the @ isn't included
if (equali(Arg1[1], "CT"))
{
Team = 2
} else if (equali(Arg1[1], "T")) {
Team = 1
}
new players[32], num
//This function will fill the players[32] variable
// with valid player ids. num will contain the number
// of players that are valid.
Thanks in advance
s@ch is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 01-02-2015 , 02:19   Re: Need help!!
Reply With Quote #6

First of all, please use php tag to show your code:
PHP Code:
public cmd_hp(idlevelcid)
{
    if (!
cmd_access(idlevelcid3))
        return 
PLUGIN_HANDLED

    
new Arg1[24]
    new 
Arg2[4]

    
//Get the command arguments from the console
    
read_argv(1Arg123)
    
read_argv(2Arg23)

    
//Convert the health from a string to a number
    
new Health str_to_num(Arg2)

    
//Is the first character the @ symbol?
    
if (Arg1[0] == '@')
    {
        new 
Team 0
        
//Check which team was specified.
        //Note that we start from [1], this is okay
        // it just means the @ isn't included
        
if (equali(Arg1[1], "CT"))
        {
            
Team 2
        

        else if (
equali(Arg1[1], "T")) 
        {
            
Team 1
        
}
        
        new 
players[32], num
        
//This function will fill the players[32] variable
        // with valid player ids. num will contain the number
        // of players that are valid.
        
get_players(playersnum)
        
        new 
i
        
for (i=0i<numi++)
        {
            if (!
Team)
            {
                
//Set this player's health
                
set_user_health(players[i], Health)
            } 
            else 
            {
                if (
get_user_team(players[i]) == Team)
                {
                    
set_user_health(players[i], Health)
                }
            }
        }
    } 
    else 
    {
        
//finds a player id that matches the partial name given
        //the 1 means that it will not target the player if he
        // has immunity access
        
new player cmd_target(idArg11)
        if (!
player)
        {
            
//this will print a message to the user who tried the command
            //The format for this command is called "format()" style,
            // where the first string formats the message according
            // to any number of following parameters.
            // %s means a string
            // %d or %i means an integer
            // %f means a float
            // so "Hello %s, I am %d years old" will
            // require a string and integer to follow
            
console_print(id"Sorry, player %s could not be found or targetted!"Arg1)
            return 
PLUGIN_HANDLED
        

        else 
        {
            
set_user_health(playerHealth)
        }
    }

    return 
PLUGIN_HANDLED

native read_argv(id, output[], len) is used to retrieves argument of client command. So, for example:

amx_freeHP zmd94 90:

1. zmd94 = is the first argument.
2. 90 = is the second argument

For second question: why we need to convert the health from a string to a number?
PHP Code:
new Health str_to_num(Arg2
This is because we want to set player health by using native set_user_health(index, health). The second param which is "health" can only read a number. So, if you don't convert the health from a string to a number, it will give you an error.

Lastly:
PHP Code:
    //Is the first character the @ symbol?
    
if (Arg1[0] == '@')
    {
        new 
Team 0
        
//Check which team was specified.
        //Note that we start from [1], this is okay
        // it just means the @ isn't included
        
if (equali(Arg1[1], "CT"))
        {
            
Team 2
        

        else if (
equali(Arg1[1], "T")) 
        {
            
Team 1
        

This code will working such this.

1. If you write amx_freeHP @ 100 = It will give all players free 100 health.
2. If you write amx_freeHP @CT 100 = It will give all counter-terrorist free 100 health.
3. If you write amx_freeHP @T 100 = It will give all terrorist free 100 health.

If I'm wrong, please correct me. ;)

Last edited by zmd94; 01-02-2015 at 02:25.
zmd94 is offline
s@ch
New Member
Join Date: Nov 2014
Old 01-02-2015 , 03:06   Re: Need help!!
Reply With Quote #7

Thanks for the reply mate
Just one more doubt

What is the meaning of if(!team)?

Last edited by s@ch; 01-02-2015 at 03:13.
s@ch is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 01-02-2015 , 03:49   Re: Need help!!
Reply With Quote #8

Its mean, the team is not being specified whether T team or CT team.
zmd94 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-02-2015 , 07:07   Re: Need help!!
Reply With Quote #9

if(!var) is the same as if(var==0) and check if the given variable is 0(false). When dealing with teams it is unassigned team(not t, ct or spec). If you use cstrike module the const is CS_TEAM_UNASSIGNED which is 0. This is why it checks like that.

PHP Code:
enum CsTeams {
    
CS_TEAM_UNASSIGNED 0,
    
CS_TEAM_T 1,
    
CS_TEAM_CT 2,
    
CS_TEAM_SPECTATOR 3
}; 
Also, when you initialize a variable without giving it a value it will be everytime 0, so you don't have to explicit:
PHP Code:
 new test new bool:test false new FloatfTest 0.0 
If you know C, then go and read here about pawn language: http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf

You will notice some differences between it and C:
-no pointers
-no types. Because everything is a integer cell we use tags for floats and booleans. A string is an array of cells.
-etc

PHP Code:
new ThisIsMyString[] = "Test"//you don't need to write the size between[], compiler is able to find it
new SomeArray[5]
SomeArray[0] = 'a'
SomeArray[1] = 'b'
SomeArray[2] = 'c'
SomeArray[3] = 'd'
SomeArray[4] = 'e' 
When you print SomeArray it will give you abcde. Note that this kind of assigment can't be done globally and need to be in a function, otherwise the copiler will throw an error.

The last cell from an array must be the null item, defined as EOS in amxx.(end of string)
If you try to store something in SomeArray[5] you can't.
So the usable cells of an array are from 0 to sizeof -1(defined as charsmax(string))

To remove the tag from a variable use _: in front of it's name. It's also used for enumeration(enum) when you want to untag it.

To check if the two variable tags match you can use tagof operator(read in pawn manual about it).
__________________

Last edited by HamletEagle; 01-02-2015 at 07:24.
HamletEagle is offline
s@ch
New Member
Join Date: Nov 2014
Old 01-02-2015 , 12:45   Re: Need help!!
Reply With Quote #10

//This function will switch slots a and b inside any array passed to this function.
swap_slots(array[], a, b)
{
//Note, you need to temporarily hold one of the slots before swapping them
//Otherwise, you can't swap both values! This is a classic problem.
//If you have a and b, setting b equal to a eliminates the original value in b.
new temp

temp = array[b]
array[b] = array[a]
array[a] = temp
}

new myArray[2]
myArray[0] = 5
myArray[1] = 6
swap_slots(myArray, 0, 1)
//myArray[0] is 6, myArray[1] is 5

Please tell me the use of the above statements ...and why shld we switch slots a and b? Once again thanks for the replies u gave guys...

Last edited by s@ch; 01-02-2015 at 12:46.
s@ch 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 16:35.


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