AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hello, new to writing fresh code. (https://forums.alliedmods.net/showthread.php?t=46082)

ecko1988 10-18-2006 04:12

Hello, new to writing fresh code.
 
I have been tinkering with Code for ages, but never really writing up code of my own. This is my first attempt, but i'm not sure what i've done wrong. Could somone just proof check it for me.

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <engine_stocks> #include <fun> #include <harbu> new id new isonapill[33] public plugin_init() {         register_plugin("Adrenaline pills","0.0.0.0","Dean Booker AKA Ecko Mantle");         register_srvcmd("item_apill","item_apill"); } public item_apill() {         if(isonapill[id] = 1)         {                return PLUGIN_HANDLED         }         else         {         set_user_maxspeed 450         client_cmd(id, "cl_forwardspeed 450.0")         client_cmd(id, "cl_sidespeed 450.0")         client_cmd(id, "cl_backspeed 450.0")         client_cmd(id, "say /me takes an Adrenaline Pill.")         client_cmd(id, print_chat, "[Umbrella] You take an Adrenaline Pill.")         client_cmd(set_task(30.0, "apill_end", id)         isonapill[id] = 1         return PLUGIN_HANDLED; } public apill_end() {         set_user_maxspeed 350         client_cmd(id, "cl_forwardspeed 350.0")         client_cmd(id, "cl_sidespeed 350.0")         client_cmd(id, "cl_backspeed 350.0")         isonapill[id] = 0         return PLUGIN_HANDLED }


Any pointers would be great!

Regards,
Ecko

jim_yang 10-18-2006 04:30

Re: Hello, new to writing fresh code.
 
you need to compile it , then you will find many many many mistakes.

Emp` 10-18-2006 09:27

Re: Hello, new to writing fresh code.
 
heres one that should work (compare the 2)
Code:
#include <amxmodx> //only include things your using #include <fun> #define MAX_PLAYERS 32 //we dont need to make id global new isonapill[33] public plugin_init() {         register_plugin("Adrenaline pills","0.0.0.0","Dean Booker AKA Ecko Mantle");         //register it as a console command so we can get the id properly         register_concmd("item_apill","item_apill",ADMIN_ALL)         //register it again for admins that want to set it to everyone         register_concmd("item_apill_all","item_apill_all",ADMIN_KICK) } public item_apill_all(id) {         for(new i=1; i<MAX_PLAYERS; i++) //there is a better way to get players, but im in a hurry         {              if(is_user_connected(i))                  item_apill(i)         } } public item_apill(id)//we get the id here {         if(isonapill[id] = 1 || 1>id>MAX_PLAYERS)//stop if it isnt a proper id (a different ent or the server console), note that MAX_PLAYERS is defined at the top         {                return PLUGIN_HANDLED         }         if(is_user_alive(id)) //can only set maxspeed on alive people               set_user_maxspeed(id,450.0)         client_cmd(id, "cl_forwardspeed 450.0")         client_cmd(id, "cl_sidespeed 450.0")         client_cmd(id, "cl_backspeed 450.0")         client_cmd(id, "say /me takes an Adrenaline Pill.")         client_cmd(id, print_chat, "[Umbrella] You take an Adrenaline Pill.")         set_task(30.0, "apill_end", id)//your passing the id         isonapill[id] = 1         return PLUGIN_HANDLED; } public apill_end(id)//we passed the id, so lets keep it {         if(is_user_alive(id)) //again only alive people              set_user_maxspeed(id, 350.0)         client_cmd(id, "cl_forwardspeed 350.0")         client_cmd(id, "cl_sidespeed 350.0")         client_cmd(id, "cl_backspeed 350.0")         isonapill[id] = 0         return PLUGIN_HANDLED }

jim_yang 10-18-2006 09:54

Re: Hello, new to writing fresh code.
 
Quote:

client_cmd(id, print_chat, "[Umbrella] You take an Adrenaline Pill.")
client_cmd(set_task(30.0, "apill_end", id)//your passing the id
are you kidding?

schnitzelmaker 10-18-2006 10:50

Re: Hello, new to writing fresh code.
 
Code:
client_print(id, print_chat, "[Umbrella] You take an Adrenaline Pill.") set_task(30.0, "apill_end", id)//your passing the id

wonsae 10-18-2006 10:53

Re: Hello, new to writing fresh code.
 
PHP Code:

#include <amxmodx>
#include <fun>
new isonapill[33]
public 
plugin_init()
{
        
register_plugin("Adrenaline pills","0.0.0.0","Dean Booker AKA Ecko Mantle");
        
register_srvcmd("item_apill","item_apill");
}
public 
item_apill()
{
 new 
arg[32], id
 read_argv
(1,arg,32)
 
id str_to_num(arg)
        if(
isonapill[id] = 1)
        {
               return 
PLUGIN_HANDLED
        
}
        else
        {
         
set_user_maxspeed(id450.0)
         
client_cmd(id"cl_forwardspeed 450.0")
         
client_cmd(id"cl_sidespeed 450.0")
         
client_cmd(id"cl_backspeed 450.0")
         
client_cmd(id"say /me takes an Adrenaline Pill.")
         
client_print(idprint_chat"[Umbrella] You take an Adrenaline Pill.")
         
set_task(30.0"apill_end"id)
         
isonapill[id] = 1
 
}
        return 
PLUGIN_HANDLED;
}
public 
apill_end(id)
{
        
set_user_maxspeed(id320.0)
        
client_cmd(id"cl_forwardspeed 320.0")
        
client_cmd(id"cl_sidespeed 320.0")
        
client_cmd(id"cl_backspeed 320.0")
        
isonapill[id] = 0
        
return PLUGIN_HANDLED


I'm guessing it's for TSRP.

Zenith77 10-18-2006 12:03

Re: Hello, new to writing fresh code.
 
Quote:

Originally Posted by jim_yang (Post 392533)
are you kidding?

Nothing is really wrong, I'm assuming he is new. The only problem he is having is dealing with concepts, which everybody does when they begin.

Some things:
  • Try to understand what functions are, how they are executed, and how they work.
  • Know how parameters are passed to functions, and what they are.
  • Functions cannot be executed on clients, commands can though.
  • That's all, just some quick points.

ecko1988 10-18-2006 20:13

Re: Hello, new to writing fresh code.
 
Thanks, i'll look into the bits on more detail that i was lacking.


All times are GMT -4. The time now is 04:52.

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