AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with pluging in scripts (https://forums.alliedmods.net/showthread.php?t=47108)

tinlab 11-10-2006 08:13

Help with pluging in scripts
 
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
}


Drak 11-10-2006 09:28

Re: Help with pluging in scripts
 
Quote:

Originally Posted by tinlab (Post 401809)
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!

Scripts and plugins are the same thing. And compile what you have there, and test it your self.

tinlab 11-10-2006 19:07

Re: Help with pluging in scripts
 
Quote:

Originally Posted by SixTwin (Post 401827)
Scripts and plugins are the same thing. And compile what you have there, and test it your self.

i dont no how to compile thats why i wrote this...

Brad 11-10-2006 19:43

Re: Help with pluging in scripts
 
Compiling Plugins (AMX Mod X)

tinlab 11-10-2006 20:53

Re: Help with pluging in scripts
 
Quote:

Originally Posted by Brad (Post 402014)

i did the online compiler on the amxx site and every time it came up with errors, aot of errors, and i fix aolt, most were just stupid mistakes, but some i
(84 -- 85) : error 001: expected token: ",", but found "-identifier-"
and
(156) : error 037: invalid string (possibly non-terminated string)

and some others as well. please help!

[ --<-@ ] Black Rose 11-11-2006 05:43

Re: Help with pluging in scripts
 
Code:

#degine --> #define ( line 12 )

CLASSESpMAXCLASSES] --> CLASSES[MAXCLASSES]        ( line 20 )

Register_clcmd != register_clcmd        ( line 68 )

you have forgotten a ) at the end        ( line 84 )

laultkey --> vaultkey        ( line 85 )

format(vaultdata,63'"%d",PlayerLevel[id]); --> format(vaultdata,63,"%d",PlayerLevel[id]);        ( line 89 )

LoadXP(id) does not exist.        ( line 99 )

Print_chat --> print_chat, also forgot a ) at the end of the line        ( line 103 )

Public --> public        ( line 107 )

playerClass[id] --> PlayerClass[id]        ( line 141, 164, 177, 191, 204, 225 )

Client_print --> client_print, Print_chat --> print_chat, you have forgotten a " and a ) at the end        ( line 157, 172, 185, 199, 208 )

ChoseAnimal(id) --> ChooseAnimal(id)        ( line 229 )

retunr --> return        ( line 249 )

playerXP[attacker] --> PlayerXP[attacker], you have forgot the "if (" at the beginning        ( line 253 )

PlayerLevel[attacker --> PlayerLevel[attacker]        ( line 256 )

pring_chat --> print_chat, you have forgotten a " and a ) at the end        ( line 259 )

saveXP(attacker) --> SaveXP(attacker)        ( line 264 )

showHUD(attacker) --> ShowHUD(attacker)        ( line 268, 272 ) ( also remove the one at line 268 since the one at 272 will be called anyways )

message_begin_MSG_ONE, msgtext, {0,0,0}, id) --> message_begin(MSG_ONE_UNRELIABLE, msgtext, {0,0,0}, id)        ( line 284 )


tinlab 11-11-2006 09:42

Re: Help with pluging in scripts
 
thx rose that helped alot


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

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