Raised This Month: $ Target: $400
 0% 

Help with pluging in scripts


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
tinlab
Member
Join Date: Oct 2006
Location: malaysia
Old 11-10-2006 , 08:13   Help with pluging in scripts
Reply With Quote #1

i just went through the Animal Mod totorial and i wrote everything that i wanted it PAWN. is the right place to do it? i dunno im pretty new to this whole scripting thing. also dont i need more than scripts for the plugin to work? or will it work with just the single script. here is the entire script that i wrote. tell me what i need to do with it and if i did anything wrong please!

Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <vault>


#define CLASS_NONTHING 0 //class people will automaticly become
#define CLASS_DOG 1
#define CLASS_CAT 2
#define CLASS_HORSE 3
#define CLASS_COW 4
#degine CLASS_BIRD 5

#define MAXCLASSES 6 //we have 6 classes

new PlayerClass[33]
new PlayerXP[33]
new PlayerLevel[33]

new const CLASSESpMAXCLASSES] [] = {
    "None",
    "Dog",
    "Cat",
    "Horse",
    "Cow",
    "Bird"
}


new msgtext

//we have 7 levels
new const LEVELS[7] = {
    100, //100 xp for lvl 1
    200, //200 xp for lvl 2
    400, //Etc...
    800,
    1600,
    3200,
    6400
}

public plugin_init()
{
    register_plugin("Animal Mod", "1.0", "XunTric")
    register_cvar("sv_animalmod", "1") 
    //an off/on cvar for the animal mod
    register_event("DeathMsg", "DeathMsg", "a") 
    //register death mesage. this is where we can add XP when you kill someone
    //i registered it as "a"; a global event

    register_cvar("xp_per_kill", "20")
    //Xp per kill cvar
    //made it 20 Xp per kill

    register_cvar("saveXP", "1")
    //register a saveXp toggle cvar

    register_menucmd(register_menuid("menu_ChooseAnimal"),1023,"DoChooseAnimal");
    //a menu to choose the animal with

    register_event("ResetHUD", "ResetHUD", "b")
    //ResetHUD event, check if user has no class

    msgtext = get_user_msgid("statusText")
    //ShowHUD

    Register_clcmd("say /changeanimal", "ChangeAnimal")
    register_clcmd("say_team /changeanimal", "ChangeAnimal")
    //a change animal cmd for the players

}


public SaveXP(id)
{
    new authid[32];
    get_user_authid(id,authid,31);
    
    new vaultkey[64], vaultdata[64]
    
    //Save their class
    format(vaultkey,63,"ANIMAL-%s-class",authid);
    format(vaultdata,63,"%d",PlayerXP[id]
    set_vaultdata(laultkey,vaultdata);
    
    //save their levels
    format(vaultdata,63,"ANIMAL-%s-xp",authid);
    format(vaultdata,63'"%d",PlayerLevel[id]);
    set_vaultdata(vaultkey,vaultdata);
}


public clietn_connect(id)
{
    //only load there XP if our SaveXp cvar si 1
    if(get_cvar_num("saveXP") ==1) {
        
        LoadXP(id)
        
        //Add a message if you please
        client_print(id, print_chat, "Your [Animal Mod] XP Loaded!")
        client_print(id, Print_chat, "[Animal Mod] You are a %s With level %s and %s XP",PlayerClass[id], PlayerLevel[id], PlayerXP[id]
    }
}

Public client_disconnect(id)
{
    //only save their XP if our saveXP cvar is set to 1
    if(get_cvar_num("SaveXp") == 1) {
    
        SaveXP(id)
    }
}

//Call it whay you please
stock ChooseAnimal(id)
{
    new menu[192]
    
    //add keys for how many classes you have + exit key.
    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4
    
    //here we write the menu options.
    format(menu, 191, "Animal Mod: Choose Animal^n^n1. Dog^n2. Cat^n3. Horse^n4. Cow^n5. Bird^n^n0. Exit")
    
    //created a menu in pluging_init() and we let the plugin know that it has to show tis menu
    show_menu(id, keys, menu, -1, "menu_ChooseAnimal")
    
    return PLUGIN_CONTINUE
}


//this is where we write exactly what would happen if they choose one of these classes
public DoChooseAnimal(id, key)
{
    //rember that the keys starts on 0
    if(key == 0) {
        
        //lets check if the player allready has Dog.
        if(playerClass[id] == CLASS_DOG) {
            
            //make a message here if you please
            client_print(id, print_chat, "[Animal Mod] You already a dog! Choose a diffrent class!")
            
            //open the menu again
            ChooseAnimal(id)
            
            //exit
            return PLUGIN_HANDLED
        }
        
        //Now if the player didnt have dog allready, we will set his class to dog
        PlayerClass[id] = CLASS_DOG
        
        //make a message
        Client_print(id, Print_chat, "[AnimalMod} Good choice, you are now a dog!
    }
    
    //repeat to all the others
    
    if(key == 1) {
        
        if(playerClass[id] == CLASS_CAT) {
            
            client_print(id, print_chat, "[Animal Mod] You already a cat! Choose a diffrent class!")
            ChooseAnimal(id)
            return PLUGIN_HANDLED
        }
        
        PlayerClass[id] = CLASS_CAT
        Client_print(id, Print_chat, "[AnimalMod} Good choice, you are now a cat!
    }
    
        if(key == 2) {
        
        if(playerClass[id] == CLASS_HORSE) {
            
            client_print(id, print_chat, "[Animal Mod] You already a horse! Choose a diffrent class!")
            ChooseAnimal(id)
            return PLUGIN_HANDLED
        }
        
        PlayerClass[id] = CLASS_HORSE
        Client_print(id, Print_chat, "[AnimalMod} Good choice, you are now a horse!
    }
    
    
        if(key == 3) {
        
        if(playerClass[id] == CLASS_COW) {
            
            client_print(id, print_chat, "[Animal Mod] You already a cow! Choose a diffrent class!")
            ChooseAnimal(id)
            return PLUGIN_HANDLED
        }
        
        PlayerClass[id] = CLASS_COW
        Client_print(id, Print_chat, "[AnimalMod} Good choice, you are now a cow!
    }
    
        if(key == 4) {
        
        if(playerClass[id] == CLASS_BIRD) {
            
            client_print(id, print_chat, "[Animal Mod] You already a bidr! Choose a diffrent class!")
            ChooseAnimal(id)
            return PLUGIN_HANDLED
        }
        
        PlayerClass[id] = CLASS_BIRD
        Client_print(id, Print_chat, "[AnimalMod} Good choice, you are now a bird!
    }
    
    //show new HUD after picking class
    ShowHUD(id)
    
    return PLUGIN_HANDLED
}

public resetHUD(id)
{
    //lets check if the "sv_animalmod" is on. if its off, well stop the function.
    if(get_cvar_num("sv_animalmod") == 0) {
        return PLUGIN_HANDLED
    }
    
    //lets check if the player has no animal
    if (playerClass[id] == CLASS_NONTHING) {
        
        //if the player doesnt have an animal
        //open the choose animal menu for him
        ChoseAnimal(id)
        return PLUGIN_HANDLED
    }
    
    return PLUGIN_HANDLED
}

public DeathMsg() //note that i only had () not (id)
{
    //check if the "sv_animalmod" is on
    if(get_cvar_num("sv_animalmod") == 0) {
        return PLUGIN_HANDLED
    }
    
    //now creat a "attacker" varriable, sp the xp will be given to the killer
    new attacker = read_data(1)
    
    //now lets see if the player already has lvl 6 and doesnt need any more xp. if so stop the function
    //you can remove this if you want, and let the player gain as much xp as he wishes
    if(PlayerLevel[attacker] == 6) {
        retunr PLUGIN_HANDLED
    }
    
    //now we can add XP to the attacker
    playerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) {
        
        //add his level
        PlayerLevel[attacker +=1
        
        //now you can make a message
        client_print(attacker, pring_chat, "[Animal Mod] Conglations you gained a level!
        
        //save his Xp every time he gains a lvl incase the server crashes
        if(get_cvar_num("saveXP") ==1) {
            
            saveXP(attacker)
        }
        
        //show his new level on a HUD message
        showHUD(attacker)
    }
    
    //show new HUD of you didnt get level too.
    showHUD(attacker)
    
    return PLUGIN_CONTINUE
}

public ShowHUD(id)
{
    new HUD[51]
    
    //this is the stuff that will actually show in game
    format(HUD, 50, "[%s]Level: %i XP: %i", CLASSES[PlayerClass[id]], PlayerLevel[id], PlayerXP[id])
    
    message_begin_MSG_ONE, msgtext, {0,0,0}, id)
    write_byte(0)
    write_string(HUD)
    message_end()
    return
}
tinlab is offline
Send a message via AIM to tinlab Send a message via MSN to tinlab
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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