AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to.. (https://forums.alliedmods.net/showthread.php?t=16944)

MichielM 08-23-2005 08:44

How to..
 
hi, i want to use the following code to make that tsx money plugin work on my tsrp server. (when someone dies, drops his cash out of his wallet, and it will display a money model on ground.)
now the problem is its using VaultX, and the author deleted it from the plugins page :cry:

Is there any way to get this work if i havnt got VaultX, or somebody has got another good working plugin like this??

this is the tsx_money plugin:

Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <vaultx>
#include <arrayx>

// Float: Money, Int: Time till next pickup
// Money holder
new money

new hud_plugin[100]

// Init. Self explanatory
public plugin_init()
{
        // Money Mod, S3 Edition.
        register_plugin("Money","[S3]","Twilight Suzuka")
        forward_plugin("money_forward");

        // Say catcher
        register_clcmd("say","handle_say")

        // Money for Inventory Mod.
        register_srvcmd("inv_money","inv_money")

        // Make sure we can pickup money
        register_touch("tsx_money","player","touch_money")

        // Register Death Message, so we can force money drop.
        register_event("DeathMsg","death","a","2!0")

        // CVAR for how much money someone gets when they first enter the server.
        register_cvar("tsx_start_money","1000.0")

        // CVAR for death money drop
        register_cvar("tsx_death_money","1000.0")

        // CVAR for money exchange
        register_cvar("tsx_exchange_type","1")

        money = new_array();
        forward_array(money,"money_call")
}

public hud_forward(str[]) format(hud_plugin,99,"%s",str)

// Precache the money model.
public plugin_precache() precache_model("models/money.mdl")

// On death, if the dead is connected, drop money.
public death() if(is_user_connected(read_data(2)) ) drop_money(read_data(2),get_cvar_float("tsx_death_money") )

// Load money on authorization.
public client_authorized(id) load_money(id);

public client_disconnect(id) remove_cell(money,id);

// Require the modules needed
public plugin_modules()
{
        require_module("VaultX");
        require_module("Engine");
        require_module("ArrayX");
}

// Handle Say
public handle_say(id)
{
        new message[200]
        read_argv(1,message,199)

        // If the say message is a give, transfer the money.
        if(equali(message,"/givemoney",10) || equali(message,"givemoney",9))
        {       
                // Get who we are looking at
                new tid, body
                get_user_aiming ( id, tid, body, 200 )

                // If they exist
                if(!tid || tid > get_maxplayers())
                {
                        // Check to see if we can send cross the map
                        if(!get_cvar_num("tsx_exchange_type") ) money_notify(id,"MM","No one to give money to!")
                        else
                        {
                                // Get the second arg and third arg
                                replace(message,255,"/givemoney","")
                                replace(message,255,"givemoney","")
                                trim(message)
       
                                new arg[32], arg2[32]
                                parse(message,arg,31,arg2,31)               
       
                                // Send money through the...air.

                                tid = cmd_target(0,arg,10)
                                if(!tid) money_notify(id,"MM","No one to give money to!")
                                else transfer_money(id,tid,floatstr(arg2))
                        }
                }
                else
                {
                        // Get the second arg.
                        replace(message,255,"/givemoney","")
                        replace(message,255,"givemoney","")
                        trim(message)
       
                        new arg[32], arg2[32]
                        parse(message,arg,31,arg2,31)

                        // Transfer money
                        transfer_money(id,tid,floatstr(arg))
                }
                       
                // Make sure we don't say the command.
                return PLUGIN_HANDLED;
        }

        // If it is a drop, force a drop.
        if(equali(message,"/dropmoney",10) || equali(message,"dropmoney",9))
        {
                replace(message,255,"/dropmoney","")
                replace(message,255,"dropmoney","")
                trim(message)

                new arg[32], arg2[32]
                parse(message,arg,31,arg2,31)

                drop_money(id,floatstr(arg))

                return PLUGIN_HANDLED;
        }

        // If its not money, let it go on.
        return PLUGIN_CONTINUE;
}

// When you touch the money, pick it up.
public touch_money(id,tid)
{
        // Make sure the player is connected, and able to pick up money.
        if( (get_cell_int(money,tid) < floatround(halflife_time()) ) && is_user_alive(tid) && is_user_connected(tid) )
        {
                // If they can pick it up, pick it up.
                change_money(tid,entity_get_float(id,EV_FL_fuser1))

                new money_str[100], amount[50]
                format_float(amount,entity_get_float(id,EV_FL_fuser1))

                format(money_str,49,"You have picked up %s",amount)
                money_notify(tid,"MM",money_str)

                // Make sure they cannot pick it up twice.
                remove_entity(id);

                // Dont let em pick up for a small amount of time.
                set_cell_int(money,tid,floatround(halflife_time() + 1.0))
        }

        return PLUGIN_CONTINUE;
}

// Drop Money Function.
public drop_money(id,Float:amount)
{
        // Always make sure they drop as much as possible.
        if(!user_has_amount(id,amount)) amount = get_cell_float(money,id)
       
        // Remove their money
        change_money(id,amount * -1.0)

        // Make sure they can get away before picking it up again.
        set_cell_int(money,id,floatround(halflife_time() + 5.0))

        // Make the Entity

        new Float:origin[3];
        entity_get_vector(id,EV_VEC_origin,origin)

        new ent = create_entity("info_target")

        if(!ent) return 0;

        new Float:mins[3] = { -2.5, -2.5, -2.5 }
        new Float:maxs[3] = { 2.5, 2.5, -2.5 }
        new Float:angle[3] = { 0.0, 0.0, 0.0 }

        angle[1] = float(random_num(0,270))

        entity_set_size(ent,mins,maxs)
        entity_set_vector(ent,EV_VEC_angles,angle);

        entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER);
        entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS);

        entity_set_float(ent,EV_FL_fuser1,amount);
        entity_set_string(ent,EV_SZ_classname,"tsx_money");

        entity_set_model(ent,"models/money.mdl");
        entity_set_origin(ent,origin);

        new price2[100], message[200]
        format_float(price2,amount)
        format(message,199,"You have dropped %s!",price2)

        money_notify(id,"MM",message)

        return 1;
}

// Does the user have the right amount of money?
public user_has_amount(id,Float:amount) return ( get_cell_float(money,id) >= amount )

// Simplified money message.
public money_notify(id,addon[],str[]){
        new message[200]
        format(message,199,"[%s] -  %s",addon,str)
        client_print(id,print_chat,message)

        return 1;
}

// Change Money through Inv Mod
public inv_money()
{
        // Get id and amount, send it to change_money.
        new arg[32]
        read_argv(1,arg,31)
        new id = cmd_target(0,arg,10)
        if(!id) return 0;
       
        read_argv(2,arg,31)
        change_money(id,floatstr(arg))

        return 1;
}

// Change the amount of money someone has
public change_money(id,Float:amount)
{
        set_cell_float(money,id,get_cell_float(money,id) + amount)
        save_money(id)
        return 1;
}

// Transfer money between two people.
public transfer_money(id,tid,Float:amount)
{
        // If they cannot give that much money, don't let them.
        if(!user_has_amount(id,amount)) return (money_notify(id,"MM","You do not have enough money!"))
       
        // Switch the money around.
        change_money(id,amount * -1.0)
        change_money(id,amount)

        // Format the price
        new price2[200]
        format_float(price2,amount)

        // Get everyones name

        new tname[32], name[32]
        get_user_name(tid,tname,31)
        get_user_name(id,name,31)

        // Notify everyone to what happened
        new message[200]
        format(message,199,"You gave %s %s",tname,price2)
        money_notify(id,"MM",message)

        format(message,199,"You received %s from %s",price2,name)
        money_notify(tid,"MM",message)

        // Save it
        save_money(id)
        save_money(tid)

        return 1;
}

// Save the money to VaultX.
public save_money(id)
{
        new moneystr[128],key[64], authid[36]
        get_user_authid(id, authid ,35);

        format(moneystr,127,"%f",get_cell_float(money,id))
        format(key,63,"%s-money",authid)

        set_vaultxpath("addons/amxmodx/data/tsx_money.ini")
        set_vaultxdata(key,moneystr)

        return 1;
}

// Load the money from VaultX.
public load_money(id)
{
        new moneystr[128],key[64], authid[36]

        get_user_authid(id, authid ,35);
        format(key,63,"%s-money",authid)

        set_vaultxpath("addons/amxmodx/data/tsx_money.ini")
        get_vaultxdata(key,moneystr,127)

        if(equali(moneystr,"")) set_cell_float(money,id,get_cvar_float("tsx_start_money")), save_money(id);
        else set_cell_float(money,id,floatstr(moneystr) )

        set_cell_int(money,id,floatround(halflife_time()) )

        return 1;
}

// Catch the callback
public handle_hud_callback(id)
{
        // Send our money to the hud
        display_money(id);
       
        // Make sure all other plugins may catch as well.
        return PLUGIN_CONTINUE;
}

public display_money(id)
{
        // Format the price
        new amount[200]
        format_float(amount,get_cell_float(money,id))

        // Format the message
        new message[200]
        format(message,199,"Money in wallet: %s ^n",amount)

        // Send it to the hud
        send_to_main_hud(id,message)
        return 1;
}

// Sends an array callback, so other plugins know what your array id is.
stock forward_plugin(func[])
{
        new source[100],filename[100],other[100]
        get_plugin ( -1,source,99,other,99,other,99,other,99,other,99 )

        for(new i = 0; i < get_pluginsnum(); i++)
        {
                get_plugin ( i,filename,99,other,99,other,99,other,99,other,99 )

                new check = callfunc_begin ( func, filename )
                if(check > 0)
                {
                        callfunc_push_str ( source )
                        new block = callfunc_end ( )

                        if(block == PLUGIN_HANDLED) return;
                }
        }
        return;
}

// Sends an array callback, so other plugins know what your array id is.
stock forward_array(id,func[])
{
        for(new i = 0; i < get_pluginsnum(); i++)
        {
                new filename[100],other[100]
                get_plugin ( i,filename,99,other,99,other,99,other,99,other,99 )

                new check = callfunc_begin ( func, filename )
                if(check > 0)
                {
                        callfunc_push_int ( id )
                        new block = callfunc_end ( )

                        if(block == PLUGIN_HANDLED) return;
                }
        }
        return;
}

// Change the float into a presentable string.
stock format_float(output[],Float:price)
{
        new startfrac = floatround ( price, floatround_floor  )
        new Float:frac = floatfract ( price )
        frac *= 100.0;
        new endfrac = floatround ( frac )

        if(endfrac < 10) format(output,199,"$%i.0%i",startfrac,endfrac)
        else format(output,199,"$%i.%i",startfrac,endfrac)

        return 1;
}

// Sends a message to the main hud for a player
stock send_to_main_hud(id,message[])
{
        new check = callfunc_begin ( "add_tsx_hudmessage", hud_plugin  )
        // Allows the user to decide whether or not they want the hudmessage plugin.
        if(check == 1)
        {
                callfunc_push_int ( id )
                callfunc_push_str(message);
                callfunc_end ()
        }
       
        return PLUGIN_HANDLED;
}


Twilight Suzuka 08-23-2005 14:35

Hey you dick, thats my code!
Its never going to work because it isn't converted to the new ArrayX.

Just use XenRP, look for it in the approved plugins list.

MichielM 08-23-2005 15:11

Firts of all i'm not gonna use XenRP cause it doesnt work, and i already got a good working plugin.then,, i only asked for someone who can HELP me, not call me dick and shit like that. U better delete your TSX rp plugin, because it also needs VaultX.. hope u enjoy deleting!!!

Twilight Suzuka 08-23-2005 15:16

Actually TSX has been superceded into XenRP, both of which work.


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

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