View Single Post
Author Message
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-17-2018 , 16:19   Regarding databases.
Reply With Quote #1

Hello everyone! I've recently started coding and I think I'm doing pretty well understanding sourcepawn in general. However when it comes to databases, it takes a dark turn.

I have no idea how to use them, and create them, getting data and all this yadayada. If someone could send me an example of how to set up a proper database script I would be really thankful.

I'm doing a project on my own, that's why I'm trying to learn sql. Already read the wiki page, didn't find it helpful enough. I'm trying to do a weapons menu, the selected weapon will be inserted into the database and saved. When the player spawns, the selected weapon will be given.

This is an example, I want a database to save all the information, thank you:
PHP Code:
#include <sourcemod>
#include <sdktools>

char g_sWeapon[MAXPLAYERS 1][32];

#define DEAGLE "weapon_deagle"

public void OnPluginStart()
{
    
RegConsoleCmd("sm_weapon"Cmd_Weapon);
}

public 
Action Cmd_Weapon(int iClientint iArgs)
{
    
Menu hMenu = new Menu(Menu_Weapon);
    
hMenu.SetTitle("Weapons");
    
hMenu.AddItem("""Deagle");
    
hMenu.Display(iClientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;
}

public 
int Menu_Weapon(Menu hMenuMenuAction hActionint iClientint iParam)
{
    switch (
hAction)
    {
        case 
MenuAction_Select:
        {
            switch (
iParam)
            {
                case 
0g_sWeapon[iClient] = DEAGLE;
            }
            
            
GiveClientWeapon(iClient);
        }
        
        case 
MenuAction_End:
            
delete hMenu;
    }
}

void GiveClientWeapon(int iClient)
{
    
int iWeapon GetPlayerWeaponSlot(iClient2);
    
    
RemovePlayerItem(iClientiWeapon);
    
AcceptEntityInput(iWeapon"Kill");
    
    
GivePlayerItem(iClientg_sKnife[iClient]);

Sincerely -

Armin (Mugiwara).

Last edited by mug1wara; 06-17-2018 at 16:24.
mug1wara is offline