Raised This Month: $ Target: $400
 0% 

AMX raffle conversion to sourcemod please


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ottobohn
Senior Member
Join Date: Sep 2007
Old 04-09-2009 , 15:06   AMX raffle conversion to sourcemod please
Reply With Quote #1

http://forums.alliedmods.net/showthr...ghlight=raffle

can someone convert this please?

otto
__________________
Director

Gaming with benefits.
www.n00bsalad.net
ottobohn is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 04-11-2009 , 19:58   Re: AMX raffle conversion to sourcemod please
Reply With Quote #2

PHP Code:
#pragma semicolon 1

#include <sourcemod>

#define PLUGIN_VERSION "1.0.0"

new bool:g_bBoughtRaffle[MAXPLAYERS+1];
new 
bool:g_bEnabled;

new 
Handle:g_hCvarCost;
new 
Handle:g_hCvarCustom;
new 
Handle:g_hCvarPrize;

public 
Plugin:myinfo =
{
    
name "Raffle",
    
author "bl4nk",
    
description "Allows players to buy raffle tickets and possibly win a prize",
    
version PLUGIN_VERSION,
    
url "http://forums.alliedmods.net"
};

public 
OnPluginStart()
{
    
CreateConVar("raffle_version"PLUGIN_VERSION"Raffle Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
g_hCvarCost CreateConVar("raffle_cost""500""Cost to buy a raffle ticket"FCVAR_PLUGINtrue0.0);
    
g_hCvarCustom CreateConVar("custom_prize""0""Sets the prize: 0 = all money gathered by raffle, 1 = value of cvar \"raffle_prize\", 2 = +100 health"FCVAR_PLUGINtrue0.0true2.0);
    
g_hCvarPrize CreateConVar("raffle_prize""2000""Amount of money the players wins when chosen in the raffle"FCVAR_PLUGINtrue0.0true1600.0);

    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);

    
RegConsoleCmd("raffle"Command_Raffle);
}

public 
OnClientDisconnect(client)
{
    
g_bBoughtRaffle[client] = false;
}

public 
Action:Command_Raffle(clientargs)
{
    if (!
g_bEnabled)
    {
        
ReplyToCommand(client"[SM] You cannot buy a raffle ticket until the next round.");
        return 
Plugin_Handled;
    }

    if (
g_bBoughtRaffle[client])
    {
        
ReplyToCommand(client"[SM] You can only buy one raffle ticket per round.");
        return 
Plugin_Handled;
    }

    new 
cost GetConVarInt(g_hCvarCost);
    if (
GetClientMoney(client) < cost)
    {
        
ReplyToCommand(client"[SM] You do not have enough money (tickets are $%i each)."cost);
        return 
Plugin_Handled;
    }

    
g_bBoughtRaffle[client] = true;
    
RemoveClientMoney(clientcost);

    
ReplyToCommand(client"[SM] You bought a raffle ticket!");

    return 
Plugin_Handled;
}

public 
Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bEnabled true;
    for (new 
1<= MaxClientsi++)
    {
        
g_bBoughtRaffle[i] = false;
    }
}

public 
Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bEnabled false;

    new 
Handle:hArray CreateArray(MAXPLAYERS);
    for (new 
1<= MaxClientsi++)
    {
        if (
g_bBoughtRaffle[i])
        {
            
PushArrayCell(hArrayi);
        }
    }

    
SortADTArray(hArraySort_RandomSort_Integer);

    new 
client GetArrayCell(hArray0);
    
PrintToChatAll("[SM] Player %N won the raffle!"client);

    
CloseHandle(hArray);

    switch(
GetConVarInt(g_hCvarCustom))
    {
        case 
0:
        {
            new 
count;
            for (new 
1<= MaxClientsi++)
            {
                if (
g_bBoughtRaffle[i])
                {
                    
count++;
                }
            }

            new 
prize GetConVarInt(g_hCvarCost) * count;
            
AddClientMoney(clientprize);

            
PrintToChat(client"[SM] You won the raffle and get $%i!"prize);
        }
        case 
1:
        {
            new 
prize GetConVarInt(g_hCvarPrize);
            
AddClientMoney(clientprize);

            
PrintToChat(client"[SM] You won the raffle and get $%i!"prize);
        }
        case 
2:
        {
            new 
health GetEntProp(clientProp_Send"m_iHealth");
            
SetEntProp(clientProp_Send"m_iHealth"health 100);

            
PrintToChat(client"[SM] You won the raffle and get +100 health!");
        }
    }
}

GetClientMoney(client)
{
    return 
GetEntProp(clientProp_Send"m_iAccount");
}

SetClientMoney(clientamount)
{
    
SetEntProp(clientProp_Send"m_iAccount"amount);
}

RemoveClientMoney(clientamount)
{
    new 
cash GetClientMoney(client);
    
cash -= amount;

    if (
cash 0)
    {
        
cash 0;
    }

    
SetClientMoney(clientcash);
}

AddClientMoney(clientamount)
{
    new 
cash GetClientMoney(client);
    
cash += amount;

    if (
cash 16000)
    {
        
cash 16000;
    }

    
SetClientMoney(clientcash);

raffle_cost "500" - Cost to buy a raffle ticket
custom_prize "0" - Sets the prize: 0 = all money gathered by raffle, 1 = value of cvar "raffle_prize", 2 = +100 health
raffle_prize "2000" - Amount of money the players wins when chosen in the raffle

The command to buy raffle tickets is "!raffle" or "/raffle" in chat, or the console command "raffle".

Last edited by bl4nk; 04-11-2009 at 23:07.
bl4nk is offline
Reply



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 10:21.


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