Raised This Month: $110 Target: $400
 27% 

Assistance w/ Random Response


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diazg
New Member
Join Date: Aug 2021
Old 08-03-2021 , 00:05   Assistance w/ Random Response
Reply With Quote #1

Hey, just recently started learning Sourcepawn and I'm trying to figure out how to reply with a random response from an array of strings. From looking around, an array is strings is done differently, but I'm not confident how to do it properly.

This is what I've currently got, but when run in server, I get random numbers rather than the actual strings (I get the same random numbers, so I'm assuming it's replacing these strings with those numbers).

PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo 
{
    
name "RandomFactTest",
    
author "Diazg",
    
description "Replies with a random fact",
    
version "1.0.0",
    
url "" 
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_fact"Random_Facts"Prints a random fact"); 
}

public 
Action Random_Facts(int clientint args)
{
    
char RandomFacts[5][] =  {"Fact Test1""Fact Test2""Fact Test3""Fact Test4""Fact Test5"}; 
    
int randomnum =  GetRandomInt(04); 
    
    
ReplyToCommand(client"%d"RandomFacts[randomnum]);
    return 
Plugin_Handled

Any assistance/explanation is more than welcomed and appreciated. Thank you in advance.
diazg is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 08-03-2021 , 00:38   Re: Assistance w/ Random Response
Reply With Quote #2

You should use the format specifier %s instead of %d.

%d is for integer
%s is for string

ReplyToCommand(client, "%s", RandomFacts[randomnum]);
__________________
FAQU is offline
diazg
New Member
Join Date: Aug 2021
Old 08-03-2021 , 01:06   Re: Assistance w/ Random Response
Reply With Quote #3

Quote:
Originally Posted by FAQU View Post
You should use the format specifier %s instead of %d.

%d is for integer
%s is for string

ReplyToCommand(client, "%s", RandomFacts[randomnum]);
Thank you so much, this fixed it!
diazg 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 17:26.


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