AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   Need help!! (https://forums.alliedmods.net/showthread.php?t=254288)

s@ch 01-01-2015 06:06

Need help!!
 
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:):wink:

zmd94 01-01-2015 07:38

Re: Need help!!
 
Just read this tutorial:

https://forums.alliedmods.net/showthread.php?t=94381

s@ch 01-01-2015 12:08

Re: Need help!!
 
Thank you bro for replying.will read that thread... Will posts my doubt's here...if u don't mind. :):wink:

zmd94 01-01-2015 12:13

Re: Need help!!
 
I'll wait. Hopefully I can help you as I'm also still learning.

s@ch 01-02-2015 01:50

Re: Need help!!
 
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

zmd94 01-02-2015 02:19

Re: Need help!!
 
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. ;)

s@ch 01-02-2015 03:06

Re: Need help!!
 
Thanks for the reply mate :)
Just one more doubt:P

What is the meaning of if(!team)?

zmd94 01-02-2015 03:49

Re: Need help!!
 
Its mean, the team is not being specified whether T team or CT team.

HamletEagle 01-02-2015 07:07

Re: Need help!!
 
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).

s@ch 01-02-2015 12:45

Re: Need help!!
 
//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...:):fox:

HamletEagle 01-03-2015 06:00

Re: Need help!!
 
Please use php tags around the code, it's hard to read as you wrote it. You should do it if you need in your plugin.
Not a fixed usage.

It's the same as swapping two variables values
PHP Code:

new var = 5
new var2 6
new aux
aux 
= var
var = 
var2
var2 
aux

//Now var is 6 and var 2 is 5 


zmd94 01-03-2015 06:13

Re: Need help!!
 
I don't know that. Nice explanation, HamletEagle.

HamletEagle 01-03-2015 07:29

Re: Need help!!
 
Not a big deal, you save the first one value, you make the first one equal to the last one and then the last one equal to the value that you saved at first step. This is because when you do var = var2 you loose var value and doing var2 = var will make both of them to have the same value as it was in var2.

PHP Code:

new var = 5
new var2 6
new aux
aux 
= var //now aux is 5
var = var2 //now var is 6
var2 aux//now var2 is 5 


HamletEagle 01-03-2015 13:52

Re: Need help!!
 
What ? I've already answered your question.

s@ch 01-05-2015 08:42

Re: Need help!!
 
thank you :)

s@ch 01-19-2015 08:21

Re: Need help!!
 
PHP Code:

if(get_cvar_num("sv_rsadvertise") == 1)
    {
        
set_task(adtime"advertise"___"b")
    } 

PHP Code:

#include <amxmodx>

#define PLUGIN     "c4 timer"
#define VERSION "1.1"
#define AUTHOR     "cheap_suit"

new g_c4timer
new mp_c4timer

new cvar_showteam
new cvar_flash
new cvar_sprite
new cvar_msg

new g_msg_showtimer
new g_msg_roundtime
new g_msg_scenario

#define MAX_SPRITES    2
new const g_timersprite[MAX_SPRITES][] = { "bombticking""bombticking1" }
new const 
g_message[] = "Detonation time intiallized....."

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar(PLUGINVERSIONFCVAR_SPONLY|FCVAR_SERVER)

    
cvar_showteam     register_cvar("amx_showc4timer""3")
    
cvar_flash     register_cvar("amx_showc4flash""0")
    
cvar_sprite     register_cvar("amx_showc4sprite""1")
    
cvar_msg     register_cvar("amx_showc4msg""0")
    
mp_c4timer     get_cvar_pointer("mp_c4timer")

    
g_msg_showtimer    get_user_msgid("ShowTimer")
    
g_msg_roundtime    get_user_msgid("RoundTime")
    
g_msg_scenario    get_user_msgid("Scenario")
    
    
register_event("HLTV""event_hltv""a""1=0""2=0")
    
register_logevent("logevent_plantedthebomb"3"2=Planted_The_Bomb")
}

public 
event_hltv()
    
g_c4timer get_pcvar_num(mp_c4timer)

public 
logevent_plantedthebomb()
{
    new 
showtteam get_pcvar_num(cvar_showteam)
    
    static 
players[32], numi
    
switch(showtteam)
    {
        case 
1get_players(playersnum"ace""TERRORIST")
        case 
2get_players(playersnum"ace""CT")
        case 
3get_players(playersnum"ac")
        default: return
    }
    for(
0num; ++iset_task(1.0"update_timer"players[i])
}

public 
update_timer(id)
{
    
message_begin(MSG_ONE_UNRELIABLEg_msg_showtimer_id)
    
message_end()
    
    
message_begin(MSG_ONE_UNRELIABLEg_msg_roundtime_id)
    
write_short(g_c4timer)
    
message_end()
    
    
message_begin(MSG_ONE_UNRELIABLEg_msg_scenario_id)
    
write_byte(1)
    
write_string(g_timersprite[clamp(get_pcvar_num(cvar_sprite), 0, (MAX_SPRITES 1))])
    
write_byte(150)
    
write_short(get_pcvar_num(cvar_flash) ? 20 0)
    
message_end()
    
    if(
get_pcvar_num(cvar_msg))
    {
        
set_hudmessage(25518000.440.8726.06.0)
        
show_hudmessage(idg_message)
    }


Hii guys..can you tell me the use of the above ??...i know i am asking too much..but i need you guys help

zmd94 01-19-2015 08:30

Re: Need help!!
 
http://www.amxmodx.org/api/amxmodx/set_task

s@ch 01-20-2015 05:22

Re: Need help!!
 
@zmd94 how to get a players score i mean.... i want an if statement like this

PHP Code:

if("player gets a specified score"

is there any statement/i don't knw what to call it...to retrieve the players score??

zmd94 01-20-2015 05:39

Re: Need help!!
 
http://www.amxmodx.org/api/amxmodx/get_user_frags

HamletEagle 01-20-2015 12:11

Re: Need help!!
 
Call it a native, since most of the functions that we use are called natives(if they come from another plugin or module).

You should search on the forum before asking simple questions, I mean, you will find the answer easier.


All times are GMT -4. The time now is 02:49.

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