AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   100% newb here (https://forums.alliedmods.net/showthread.php?t=55475)

st0rmstan 05-22-2007 16:04

100% newb here
 
I'm trying to learn this coding stuff, and I decided to make a simple plugin: When a player says /give_awp , he gets an awp. Later on, I'm going to make all the weapons available to be given, but I just want this simple plugin at first, so I can understand the coding that must be done to give weapons on a specified command.
All I know right now is that I have to:
Code:

#include <amxmodx>

public plugin_init()
{   
  register_plugin("Give Me A Weapon!", "1.0", "st0rmstan")
}

Yup, that's all I know :(

Deviance 05-22-2007 16:08

Re: 100% newb here
 
Code:
#include <amxmodx> #include <fun> public plugin_init() {        register_plugin("Give Me A Weapon!", "1.0", "st0rmstan")        register_clcmd("say /give_awp", "give_awp")        register_clcmd("say_team /give_awp", "give_awp") } public give_awp(id) {        give_item(id, "weapon_awp") }

Hope this helps.

Zenith77 05-22-2007 16:11

Re: 100% newb here
 
Please, do not post trivial problems such as this when their solutions can easily be found by looking at tutorials or other plugins. I know for a fact you could have gotten the register_clcmd() part down.

Also:

Code:
public give_awp(id) {        if (is_user_alive(id)) // Make sure user is actually alive.                 give_item(id, "weapon_awp") }

st0rmstan 05-22-2007 16:13

Re: 100% newb here
 
@Deviance, thankyou so much!
@Zenith, will not happen again ;)

Where can I find a list ALL the weapon codes like
give_item(id, "weapon_awp")

Deviance 05-22-2007 16:33

Re: 100% newb here
 
Code:

weapon_mp5navy
weapon_tmp
weapon_p90
weapon_mac10
weapon_ak47
weapon_sg552
weapon_m4a1
weapon_aug
weapon_scout
weapon_g3sg1
weapon_awp
weapon_m3
weapon_xm1014
weapon_m249
weapon_flashbang
weapon_hegrenade
item_assaultsuit
item_kevlar
weapon_smokegrenade
weapon_deagle
weapon_elite
weapon_famas
weapon_fiveseven
weapon_galil
weapon_glock18
weapon_p228
weapon_sg550
weapon_ump45
weapon_usp


st0rmstan 05-22-2007 17:07

Re: 100% newb here
 
your da bomb
+karma for your advice (zenith) and your help (dev) :)

ps:
im guessing if I wanted 2 commands, the code would read like:
Code:

#include <amxmodx>
#include <fun>

public plugin_init()
{
      register_plugin("Give Me A Weapon!", "1.0", "st0rmstan")

      register_clcmd("say /give_awp", "give_awp")
      register_clcmd("say_team /give_awp", "give_awp")
      register_clcmd("say /give_mp5", "give_mp5")
      register_clcmd("say_team /give_mp5", "give_mp5")


}

public give_awp(id)
{
if (is_user_alive(id))
      give_item(id, "weapon_awp")
}

public give_mp5(id)
{
if (is_user_alive(id))
      give_item(id, "weapon_mp5navy")
}



st0rmstan 05-22-2007 18:07

Re: 100% newb here
 
is that correct?

PS: what if a player had an m4a1 already, but he typed /give_m4a1, would that give him another one and bug out, or would it just not give him another one? I don't want any bugs :(

Zenith77 05-22-2007 18:40

Re: 100% newb here
 
For your say problem:

Code:
// put this in plugin_init(); register_clcmd("say", "CMDHook_Say"); // capture all say commands :) // put this some where else in the code... public CMDHook_Say(id) {      if (!is_user_alive(id))           return PLUGIN_CONTINUE; // show chat as normal      new args[32];      read_args(args, sizeof(args)-1);      new command[32], weapon[32];      parse(args, command, sizeof(command)-1, weapon, sizeof(weapon)-1);      if (equal(command, "/give"))      {           if (equal(weapon, "m4a1")                // do w/e you need to           return PLUGIN_HANDLED; // Don't show chat      }      return PLUGIN_CONTINUE; // appease the compiler. }

I kind of made the code generic, could be optimized (implement better methods) a lot more.
Anywho, this will allow you to do "/give m4a1", "/give ak47", etc instead of re-creating basically the same command over and over again.

TheNewt 05-22-2007 18:40

Re: 100% newb here
 
@st0rmstan: Well, thats something about any kind of scripting and coding. You try something, and keep trying until you get what you want. If there are bugs, you need to work out the bugs.

st0rmstan 05-22-2007 18:43

Re: 100% newb here
 
hm, what about this code? It's a little big :\
(I don't really understand what your's (zenith) does??)
Code:

#include <amxmodx>
#include <fun>

public plugin_init()
{
    register_plugin("show_me_weapons", "1.0", "st0rmstan"
    register_clcmd("say /ak47", "give_ak47")
    register_clcmd("say /m4a1", "give_m4a1")
    register_clcmd("say /scout", "give_scout")
    register_clcmd("say /awp", "give_awp")
    register_clcmd("say /para", "give_m249")
    register_clcmd("say /mp5", "give_mp5navy")
    register_clcmd("say /pump", "give_m3")
    register_clcmd("say /noobcannon", "give_xm1014")
    register_clcmd("say /tmp", "give_tmp")
    register_clcmd("say /p90", "give_p90")
    register_clcmd("say /mac10", "give_mac10")
    register_clcmd("say /sg552", "give_sg552")
    register_clcmd("say /bullpup", "give_aug")
    register_clcmd("say /aug", "give_aug")
    register_clcmd("say /autosniper", "give_autosniper")
    register_clcmd("say /flashbang", "give_flashbang")
    register_clcmd("say /hegrenade", "give_hegrenade")
    register_clcmd("say /assaultsuit", "give_assaultsuit")
    register_clcmd("say /kevlar", "give_kevlar")
    register_clcmd("say /smokegrenade", "give_smokegrenade")
    register_clcmd("say /deagle", "give_deagle")
    register_clcmd("say /elite", "give_elite")
    register_clcmd("say /elites", "give_elite")
    register_clcmd("say /famas", "give_famas")
    register_clcmd("say /fiveseven", "give_fiveseven")
    register_clcmd("say /galil", "give_galil")
    register_clcmd("say /glock", "give_glock")
    register_clcmd("say /p228", "give_p228")
    register_clcmd("say /228", "give_p228")
    register_clcmd("say /autosniper2", "give_sg550")
    register_clcmd("say /ump", "give_ump45")
    register_clcmd("say /ump45", "give_ump45")
    register_clcmd("say /usp", "give_usp")
    register_clcmd("say /allweapons", "all")
    register_clcmd("say /sniper_pack", "sniper_pack")
    register_clcmd("say /rifle_pack", "rifle_pack")
    register_clcmd("say /close_combat", "close_combat"
    register_clcmd("say /rambo", "rambo"
}

public give_ak47(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_ak47")
}

public give_m4a1(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_m4a1")
}

public give_scout(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_scout")
}

public give_awp(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_awp")
}

public give_m249(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_m249")
}

public give_mp5navy(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_mp5navy")
}

public give_m3(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_m3")
}

public give_xm1014(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_xm1014")
}

public give_tmp(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_tmp")
}

public give_p90(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_p90")
}

public give_mac10(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_mac10")
}

public give_sg552(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_sg552")
}

public give_aug(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_aug")
}

public give_autosniper(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_g3sg1")
}

public give_flashbang(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_flashbang")
}

public give_hegrenade(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_hegrenade")
}

public give_assaultsuit(id)
{
    if (is_user_alive(id))
        give_item(id, "item_assaultsuit")
}

public give_kevlar(id)
{
    if (is_user_alive(id))
        give_item(id, "item_kevlar")
}

public give_smokegrenade(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_smokegrenade")
}

public give_deagle(id)
{
    if (is_user_alive(id))
        give_item(id, "weapon_deagle")
}

public give_elite(id)
{
    if (is_user_alive(id))
        give_item(id, "elite")
}

public give_famas(id)
{
    if (is_user_alive(id))
        give_item(id, "famas")
}

public give_fiveseven(id)
{
    if (is_user_alive(id))
        give_item(id, "fiveseven")
}

public give_galil(id)
{
    if (is_user_alive(id))
        give_item(id, "galil")
}

public give_glock(id)
{
    if (is_user_alive(id))
        give_item(id, "glock18")
}

public give_p228(id)
{
    if (is_user_alive(id))
        give_item(id, "p228")
}

public give_sg550(id)
{
    if (is_user_alive(id))
        give_item(id, "sg550")
}

public give_ump45(id)
{
    if (is_user_alive(id))
        give_item(id, "ump45")
}

public give_usp(id)
{
    if (is_user_alive(id))
        give_item(id, "usp")
}

I don't know about it, because it's really big. Will that lag the server? It's not a huge deal if it does, I am getting a really good server soon.

PS:


All times are GMT -4. The time now is 10:32.

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