AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help needed for my plugin! (https://forums.alliedmods.net/showthread.php?t=20469)

chRm 11-09-2005 07:54

Help needed for my plugin!
 
I made a small plugin just to start learning small but I come against some problems with it, how can i check if pa_lol is set to 0 and then stop the message from appearing whenever i say lol ??

Here's the code:

Code:
/* Plugin generated by AMXX-Studio */ /* My first plugin ever!!! The commands are say lol - shows lol message pa_lol 1|0 - 1 acivates lol message, 0 disables pa_killswitch 1|0 - 1 activates kill, 0 disbles it */ #include <amxmodx> public plugin_init()     {     register_plugin("killer_lol_plug", "0.1 beta", "Panais")     register_clcmd ( "say lol", "saylol", 0,"displays lol function" )     register_cvar ( "pa_lol", "1")     register_cvar ("pa_killswitch", "1")     register_concmd("pa_kill","do_kill",ADMIN_LEVEL_C," Kills people ") } public saylol(id) {     if (get_cvar_num("pa_lol")==1)//to display message     set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)     show_hudmessage(id, "I said lol :):):)")     return PLUGIN_HANDLED } public do_kill(id) { //kill function         if (get_cvar_num("pa_killswitch")==0) {         return PLUGIN_HANDLED     }         if (!(get_user_flags(id)&ADMIN_KICK)) {         console_print(id,"You have no access")         return PLUGIN_HANDLED     }     if (read_argc() == 0) { //verifies user 1         console_print(id,"You must specify a user first.")         return PLUGIN_HANDLED     }     new user[32], uid //verifies user 2     read_argv(1,user,32)     uid = find_player("bh",user)     if (uid == 0) {         console_print(id,"Invalid userid, please try again.")         return PLUGIN_HANDLED     }     user_kill (uid)     return PLUGIN_HANDLED }

haimmaik 11-09-2005 08:14

hmm.. im not sure what u want but i think that will do the job

Code:
public saylol(id) {     if (get_cvar_num("pa_lol")==1)//to display message     {     set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)     show_hudmessage(id, "I said lol ")     return PLUGIN_HANDLED     } return PLUGIN_HANDLED }

you need to add {} after if.. to include all the commands after it inside the if... (like in a function)

chRm 11-09-2005 08:28

I'm just starting to learn but do you mean like this?

Code:
public saylol(id) {       if (get_cvar_num("pa_lol")==1){pa_lol}//to display message       {     set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)       show_hudmessage(id, "I said lol ")       return PLUGIN_HANDLED       } }
Note the {pa_lol}

haimmaik 11-09-2005 08:32

no look
treat the
Code:
if (get_cvar_num("pa_lol")==1)
as it was a function

in a function its:
Code:
public name(args) {     // Begin   ... //everything inside the function }    //End

you also need begin and end to the if thing...
and also need to return PLUGIN_HANDLED outside the "if". so ur function should look like that

Code:
 public saylol(id) {       if (get_cvar_num("pa_lol")==1)//to display message       {     set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)       show_hudmessage(id, "I said lol ")       return PLUGIN_HANDLED       } return PLUGIN_HANDLED   }

NOTE:
IF has the same structure of a FUNCTION

chRm 11-09-2005 10:07

Oh now I understand. Thanks :)

haimmaik 11-09-2005 11:08

np :)

Charr 11-09-2005 15:15

Code:
 public saylol(id) {       if (get_cvar_num("pa_lol")==1)//to display message       {     set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)       show_hudmessage(id, "I said lol ")       return PLUGIN_HANDLED       } return PLUGIN_HANDLED   }
Should be:
Code:
 public saylol(id) {       if (get_cvar_num("pa_lol")==1)//to display message       {        set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)          show_hudmessage(id, "I said lol ")          return PLUGIN_HANDLED       } return PLUGIN_HANDLED   }

chRm 11-10-2005 07:47

Isn't it the same except for the extra spaces?

[ --<-@ ] Black Rose 11-10-2005 11:42

yes. :lol::P

Charr 11-10-2005 12:13

The second is properly idented, the first is not.

This is what happens when you don't ident right:
Code:

Warning: Loose Indentation


All times are GMT -4. The time now is 23:36.

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