AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   announcement plugin (https://forums.alliedmods.net/showthread.php?t=187574)

RuRuRu612754 06-15-2012 03:41

announcement plugin
 
hello

I created a plugin for my server announcement.
However, does not work.

How can I resolve this problem I do?

amxx.cfg
PHP Code:

announcement "1"

announcement_1 "1"
announcement_2 "0"
announcement_3 "0"
announcement_4 "0"
announcement_5 "0"

announcement_detail_1 "Welcome to this server"
announcement_detail_2 ""
announcement_detail_3 ""
announcement_detail_4 ""
announcement_detail_5 "" 

announcement.sma
PHP Code:

#include <amxmodx>

new announcement

new announcement_1
new announcement_2
new announcement_3
new announcement_4
new announcement_5

new announcement_detail_1
new announcement_detail_2
new announcement_detail_3
new announcement_detail_4
new announcement_detail_5

public plugin_init()
{
    
register_plugin("PLUGIN""PLUGIN""AUTHOR")

    
announcement register_cvar("announcement""1")

    
announcement_1 register_cvar("announce_1""0")
    
announcement_2 register_cvar("announce_2""0")
    
announcement_3 register_cvar("announce_3""0")
    
announcement_4 register_cvar("announce_4""0")
    
announcement_5 register_cvar("announce_5""0")

    
announcement_detail_1 register_cvar("announcement_detail_1""")
    
announcement_detail_2 register_cvar("announcement_detail_2""")
    
announcement_detail_3 register_cvar("announcement_detail_3""")
    
announcement_detail_4 register_cvar("announcement_detail_4""")
    
announcement_detail_5 register_cvar("announcement_detail_5""")

    
set_task(180.0"CmdAnnounce"0""0"b")
}

public 
CmdAnnounce(id)
{
    if(
get_pcvar_num(announcement))
    {
        if(
get_pcvar_num(announcement_1))
        {
            
client_print(0print_chat"%s"get_pcvar_num(announcement_detail_1))
        }
        if(
get_pcvar_num(announcement_2))
        {
            
client_print(0print_chat"%s"get_pcvar_num(announcement_detail_2))
        }
        if(
get_pcvar_num(announcement_3))
        {
            
client_print(0print_chat"%s"get_pcvar_num(announcement_detail_3))
        }
        if(
get_pcvar_num(announcement_4))
        {
            
client_print(0print_chat"%s"get_pcvar_num(announcement_detail_4))
        }
        if(
get_pcvar_num(announcement_5))
        {
            
client_print(0print_chat"%s"get_pcvar_num(announcement_detail_5))
        }
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED



iBrazilian 06-15-2012 03:46

Re: announcement plugin
 
Damn, that's horrible. Either way, try using enum, look in the tutorial sections..

enum
{
ANC_1,
ANC_2,
ANC_3
};

DjOptimuS 06-15-2012 06:25

Re: announcement plugin
 
client_print(0, print_chat, "%s", get_pcvar_num(announcement_detail_1))

you should use get_pcvar_string not num

Example:

PHP Code:

new szMessage1[128];
get_pcvar_string(announcement_detail_1szMessage1127)
// Then
client_print(0print_chat"%s"szMessage1


Exolent[jNr] 06-15-2012 09:46

Re: announcement plugin
 
Hard-coded to 5 announcements, better code than before.
Spoiler


More efficient to allow 0 to infinite announcements.
Spoiler


The 2nd code removes the announce_# cvar.
Also, the # in announcement_detail has been removed.

So it looks like this:

Code:

announce 1

annoucement_detail "Line #1"
//announcement_detail "Hello"
announcement_detail "Line #2"

Notice the 2nd announcement has // before it, so it will not be added to the plugin.
That is how you can disable your announcements.

RuRuRu612754 06-19-2012 04:49

Re: announcement plugin
 
@DjOptimuS
thanks!!

@Exolent[jNr]
thanks!!
i used this XD

OvidiuS 06-19-2012 07:24

Re: announcement plugin
 
I made something similiar while ago, some kind of reminder.
It may help you:
Spoiler


Exolent can you explain ArrayGetStringHandle, haven't seen it before, on amxmodx wiki says DoNotUse ..

Exolent[jNr] 06-19-2012 09:04

Re: announcement plugin
 
Code:
formatex(string, charsmax(string), "String: %a", ArrayGetStringHandle(array, index)) // is the same as ArrayGetString(array, index, arrayString, charsmax(arrayString)) formatex(string, charsmax(string), "String: %s", arrayString)

The difference is that the first doesn't require it to be stored in a variable, which also allows you to save some memory.
It may say do not use, but is perfectly safe if not used incorrectly. It is even used in one of the base AMXX plugins (maybe map chooser or something).


All times are GMT -4. The time now is 06:11.

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