AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Say & Print problem. (https://forums.alliedmods.net/showthread.php?t=188035)

Napoleon_be 06-21-2012 11:49

Say & Print problem.
 
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <colorchat>

#define VERSION "1.0.0"
#define TOTALGROUPS 7
#define MaxPlayers 32

new MAXPLAYERSSayText

bool
:is_valid_msg(const arg[]) {
    if( 
arg[0] == '@' || !strlen(arg)) { 
        return 
false
    
}
    return 
true
}

enum _:iGroups {
    
NONE,
    
BEGINNERS,
    
AMATURES,
    
SEMIPROS,
    
PROFESSIONALS,
    
MASTERS,
    
GODS
}

new const 
szGroups[TOTALGROUPS][MaxPlayers 1] = {
    
"None",
    
"Beginners",
    
"Amatures",
    
"Semi-pros",
    
"Professionals",
    
"Masters",
    
"Gods"
}

new const 
szDescription[TOTALGROUPS][] = {
    
"[Groups]^1 You don't need to earn any kills to join this group!",
    
"[Groups]^1 Earn^3 25^1 kills to join this group!",
    
"[Groups]^1 Earn^3 50^1 kills to join this group!",
    
"[Groups]^1 Earn^3 100^1 kills to join this group!",
    
"[Groups]^1 Earn^3 200^1 kills to join this group!",
    
"[Groups]^1 Earn^3 400^1 kills to join this group!",
    
"[Groups]^1 Earn^3 750^1 kills to join this group!"
}

new const 
szKillsNeeded[TOTALGROUPS] = {
    
0,
    
25,
    
50,
    
100,
    
200,
    
400,
    
750
}

new 
szCurrentGroup[MaxPlayers 1]
new 
szKills[MaxPlayers 1]

public 
plugin_init() {
    
register_plugin("Groups Joiner"VERSION"NapoleoN#")
    
    
// Commands
    
register_clcmd("say /groups""MenuGroups")
    
register_clcmd("say_team /groups""MenuGroups")
    
register_clcmd("say /setkills""SetKills")
    
    
register_clcmd("say""HandleSay")
    
    
// MaxPlayers & Message
    
SayText get_user_msgid("SayText")
    
MAXPLAYERS get_maxplayers()
    
register_message(SayText"MsgDuplicate")
    
    
// Events
    
register_event("DeathMsg""eDeath""a")
}

public 
eDeath() {
    if(
read_data(1) != read_data(2) || cs_get_user_team(read_data(1)) != cs_get_user_team(read_data(2))) {
        
szKills[read_data(1)]++
    }
}

public 
MsgDuplicate(id) {
    return 
PLUGIN_HANDLED
}

public 
HandleSay(id) {
    new 
arg[192], szName[MaxPlayers 1]; get_user_name(idszNamecharsmax(szName))
    
read_args(argcharsmax(arg))
    
remove_quotes(arg)
    
    if(
szCurrentGroup[id] != NONE) {
        if(
is_valid_msg(arg)) {
            (
is_user_alive(id) ? format(argcharsmax(arg), "^4[%s]^3 %s: ^1%s"szCurrentGroup[id], szNamearg) : format(argcharsmax(arg), "^4[%s]^3 *DEAD* %s: ^1%s"szCurrentGroup[id], szNamearg))
        }
    }
    else {
        (
is_user_alive(id) ? format(argcharsmax(arg), "^3%s:^1 %s"szNamearg) : format(argcharsmax(arg), "^3*DEAD* %s:^1 %s"szNamearg))
    }
    
    for(new 
1<= MAXPLAYERSi++) {
        if(!
is_user_connected(i)) {
            continue
        }
        if(
is_user_alive(id) && is_user_alive(i) || !is_user_alive(id) && !is_user_alive(i)) {
            
message_begin(MSG_ONESayText, {000}, i)
            
write_byte(id)
            
write_string(arg)
            
message_end()
        }
    }
    return 
PLUGIN_CONTINUE;
}

public 
MenuGroups(id) {
    new 
szTemp[500 char], Key[10]
    
    
formatex(szTempcharsmax(szTemp), "Groups Menu ^nCurrent Group:\r %s^n\wTotal Kills:\r %i"szCurrentGroup[id], szKills[id])
    new 
menu menu_create(szTemp"GroupsMenuHandler")
    
    for(new 
iiGroupsi++) {
        
formatex(szTempcharsmax(szTemp), "%s"szGroups[i])
        
num_to_str(iKeycharsmax(Key))
        
menu_additem(menuszTempKey)
    }
    
menu_display(idmenu)
}

public 
GroupsMenuHandler(idmenuitem) {
    if(
item == MENU_EXIT) {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
        
    if(
szKills[id] >= szKillsNeeded[item]) {
        
szCurrentGroup[id] = szGroups[item][id]
        
ColorChat(idGREEN"[Groups]^1 Congratulations! You joined the group^3 ^%s^1!"szGroups[item][id])
    }
    else if(
szKills[id] < szKillsNeeded[item]) {
        
ColorChat(idGREEN"[Groups]^1 You do not have enough kills to join this group!")
        
ColorChat(idGREEN"%s"szDescription[item][id])
    }
}
        
public 
SetKills(id) {
    
szKills[id] = 750


I don't know what i'm doing wrong.. But every time i join a server it prints out "Congratulations! You joined the group Beginners" for example. But the B of beginners is missing so it prints eginners. I have that with every single thing.

Also, when i talk in chat, it only displays 1 letter of the whole word...
Someone please help?

hornet 06-21-2012 12:05

Re: Problem
 
Code:

ColorChat(id, GREEN, "%s", szDescription[item][id])
Code:

ColorChat(id, GREEN, "[Groups]^1 Congratulations! You joined the group^3 ^%s^1!", szGroups[item][id])
Remove the second array dimension from those lines. While your testing your plugin your going to be player with index 1. Your telling it to print from position id which = 1.

Exolent[jNr] 06-21-2012 12:06

Re: Problem
 
PHP Code:

        ColorChat(idGREEN"[Groups]^1 Congratulations! You joined the group^3 ^%s^1!"szGroups[item][id]) 

^%s

Remove the ^

Also, what hornet said.

ConnorMcLeod 06-21-2012 12:29

Re: Problem
 
Change your title.

Napoleon_be 06-21-2012 12:53

Re: Say & Print problem.
 
Thanks it works, what about the say problem? It's only showing the second letter of the word...

Exolent[jNr] 06-21-2012 13:03

Re: Say & Print problem.
 
szCurrentGroup[id] -> szGroups[iCurrentGroup[id]]

+ other fixes
Code:
#include <amxmodx> #include <cstrike> #include <colorchat> #define VERSION "1.0.0" #define TOTALGROUPS 7 #define MaxPlayers 32 new MAXPLAYERS, SayText bool:is_valid_msg(const arg[]) {     if( arg[0] == '@' || !strlen(arg)) {         return false     }     return true } enum _:iGroups {     NONE,     BEGINNERS,     AMATURES,     SEMIPROS,     PROFESSIONALS,     MASTERS,     GODS } new const szGroups[TOTALGROUPS][MaxPlayers + 1] = {     "None",     "Beginners",     "Amatures",     "Semi-pros",     "Professionals",     "Masters",     "Gods" } new const szDescription[TOTALGROUPS][] = {     "[Groups]^1 You don't need to earn any kills to join this group!",     "[Groups]^1 Earn^3 25^1 kills to join this group!",     "[Groups]^1 Earn^3 50^1 kills to join this group!",     "[Groups]^1 Earn^3 100^1 kills to join this group!",     "[Groups]^1 Earn^3 200^1 kills to join this group!",     "[Groups]^1 Earn^3 400^1 kills to join this group!",     "[Groups]^1 Earn^3 750^1 kills to join this group!" } // why is this noted as string? //new const szKillsNeeded[TOTALGROUPS] = { new const iKillsNeeded[TOTALGROUPS] = {     0,     25,     50,     100,     200,     400,     750 } // why is this noted as string? //new szCurrentGroup[MaxPlayers + 1] new iCurrentGroup[MaxPlayers + 1] // why is this noted as string? //new szKills[MaxPlayers + 1] new iKills[MaxPlayers + 1] public plugin_init() {     register_plugin("Groups Joiner", VERSION, "NapoleoN#")         // Commands     register_clcmd("say /groups", "MenuGroups")     register_clcmd("say_team /groups", "MenuGroups")     register_clcmd("say /setkills", "SetKills")         register_clcmd("say", "HandleSay")         // MaxPlayers & Message     SayText = get_user_msgid("SayText")     MAXPLAYERS = get_maxplayers()     register_message(SayText, "MsgDuplicate")         // Events     register_event("DeathMsg", "eDeath", "a") } public eDeath() {     // save CPU     new killer = read_data(1)     new victim = read_data(2)     if(killer != victim || cs_get_user_team(killer) != cs_get_user_team(victim)) {         iKills[killer]++     } } public MsgDuplicate(id) {     return PLUGIN_HANDLED } public HandleSay(id) {     new arg[192], szName[MaxPlayers + 1]; get_user_name(id, szName, charsmax(szName))     read_args(arg, charsmax(arg))     remove_quotes(arg)         if(iCurrentGroup[id] != NONE) {         if(is_valid_msg(arg)) {             (is_user_alive(id) ? format(arg, charsmax(arg), "^4[%s]^3 %s: ^1%s", szGroups[iCurrentGroup[id]], szName, arg) : format(arg, charsmax(arg), "^4[%s]^3 *DEAD* %s: ^1%s", szGroups[iCurrentGroup[id]], szName, arg))         }     }     else {         (is_user_alive(id) ? format(arg, charsmax(arg), "^3%s:^1 %s", szName, arg) : format(arg, charsmax(arg), "^3*DEAD* %s:^1 %s", szName, arg))     }         // save CPU     new alive = is_user_alive(id)         for(new i = 1; i <= MAXPLAYERS; i++) {         if(!is_user_connected(i)) {             continue         }         if(id == i || alive == is_user_alive(i)) {             message_begin(MSG_ONE, SayText, {0, 0, 0}, i)             write_byte(id)             write_string(arg)             message_end()         }     }     return PLUGIN_CONTINUE; } public MenuGroups(id) {     new szTemp[500 char], Key[10]         formatex(szTemp, charsmax(szTemp), "Groups Menu ^nCurrent Group:\r %s^n\wTotal Kills:\r %i", szGroups[iCurrentGroup[id]], iKills[id])     new menu = menu_create(szTemp, "GroupsMenuHandler")         for(new i; i < iGroups; i++) {         formatex(szTemp, charsmax(szTemp), "%s", szGroups[i])         num_to_str(i, Key, charsmax(Key))         menu_additem(menu, szTemp, Key)     }     menu_display(id, menu) } public GroupsMenuHandler(id, menu, item) {     if(item == MENU_EXIT) {         menu_destroy(menu)         return PLUGIN_HANDLED     }             if(iKills[id] >= iKillsNeeded[item]) {         // why do you use random indexes that make no sense?         //szCurrentGroup[id] = szGroups[item][id]         iCurrentGroup[id] = item         ColorChat(id, GREEN, "[Groups]^1 Congratulations! You joined the group^3 ^%s^1!", szGroups[item])     }     // no need to check for kills since it will always be true here if failed above     //else if(szKills[id] < szKillsNeeded[item]) {     else {         ColorChat(id, GREEN, "[Groups]^1 You do not have enough kills to join this group!")         ColorChat(id, GREEN, "%s", szDescription[item])     } }         public SetKills(id) {     iKills[id] = 750 }

Napoleon_be 06-21-2012 13:40

Re: Say & Print problem.
 
Thanks for your help, works perfectly.


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

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