Raised This Month: $43 Target: $400
 10% 

Help with this little roulette code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Yuusha
Junior Member
Join Date: Apr 2022
Old 07-11-2024 , 13:12   Help with this little roulette code
Reply With Quote #1

Hi, I'm trying to create a weapon roulette if it gives me a weapon or not, it compiles without errors but in the game when I write !ruleta and it tells me to win an awp it doesn't give me any weapon, I don't know what I'm doing wrong, I'm new to this:

#include <sourcemod>

new const String:g_items[][] = {
"sniper_awp",
"rifle_m60",
"grenade_launcher"
};

void GivePlayerItem(int client, const char[] item)
{
char command[64];
Format(command, sizeof(command), "give %s", item);
ClientCommand(client, command);
}

public Action:Command_Ruleta(client, args)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
if (GetRandomInt(1, 2) == 1) // 50% de probabilidad de tener suerte
{
// Seleccionar un arma aleatoria del array
int index = GetRandomInt(0, sizeof(g_items) - 1);
GivePlayerItem(client, g_items[index]);
PrintToChat(client, "¡Hoy tienes suerte! Has ganado un %s.", g_items[index]);
}
else
{
PrintToChat(client, "¡No tienes suerte hoy! Inténtalo de nuevo más tarde.");
}
}
return Plugin_Handled;
}

public void OnPluginStart()
{
RegConsoleCmd("sm_ruleta", Command_Ruleta, "Activa la ruleta de la suerte para obtener un arma.");
}

Last edited by Yuusha; 07-11-2024 at 13:15.
Yuusha is offline
little_froy
Senior Member
Join Date: May 2021
Old 07-11-2024 , 14:45   Re: Help with this little roulette code
Reply With Quote #2

the issue is "give" is a cheat command, you have to enable cheats on server or remove "FCVAR_CHEAT" the flag from the command.

however, there is a better solution:

#include <sdktools> and use its "GivePlayerItem"
https://sm.alliedmods.net/new-api/sd...GivePlayerItem

Last edited by little_froy; 07-11-2024 at 14:45.
little_froy is offline
Yuusha
Junior Member
Join Date: Apr 2022
Old 07-11-2024 , 18:35   Re: Help with this little roulette code
Reply With Quote #3

Quote:
Originally Posted by little_froy View Post
the issue is "give" is a cheat command, you have to enable cheats on server or remove "FCVAR_CHEAT" the flag from the command.

however, there is a better solution:

#include <sdktools> and use its "GivePlayerItem"
https://sm.alliedmods.net/new-api/sd...GivePlayerItem
is this how it is?

#include <sourcemod>
#include <sdktools>

new const String:g_items[][] = {
"weapon_rifle_m60",
"sniper_awp",
"weapon_grenade_launcher"
};

void GiveWeaponToPlayer(int client, const char[] weapon)
{
GivePlayerItem(client, weapon);
}

public Action:Command_Ruleta(client, args)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
if (GetRandomInt(1, 2) == 1) // 50% de probabilidad de tener suerte
{
int index = GetRandomInt(0, sizeof(g_items) - 1);
GiveWeaponToPlayer(client, g_items[index]);
PrintToChat(client, "¡Hoy tienes suerte! Has ganado un %s.", g_items[index]);
}
else
{
PrintToChat(client, "¡No tienes suerte hoy! Inténtalo de nuevo más tarde.");
}
}
return Plugin_Handled;
}

public void OnPluginStart()
{
RegConsoleCmd("sm_ruleta", Command_Ruleta, "Activa la ruleta de la suerte para obtener un arma.");
}
Yuusha is offline
101
Senior Member
Join Date: Nov 2023
Old 07-16-2024 , 08:14   Re: Help with this little roulette code
Reply With Quote #4

If you mean giving weapons to clients ,
Here is an example Give Players Weapons
101 is offline
Reply


Thread Tools
Display Modes

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


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