Quote:
Originally Posted by Ananisiki
How can i create a simple scramble with my own words?
Like /scramble word
|
just coded a small FS for that scramble thingy,
hope it helps you to understand how something like this could be done.
pawn Код:
/*
Created this in some mins, it's simple and meant to stay simple,
don't go searching for stuff which actually could've be done better.
Some parts could've been, but i did not care at the time of creation,
as this here is nothing seriouis, you could call it a "snippet" - CutX
*/
#include <a_samp>
#include <sscanf2>
#include <YSI\y_commands>
#define gray 0x8C8C8CFF
#define orange 0xFF641AFF
#define red 0xFF0000FF
new scram[30],word[30];//change size for longer scrambles
public OnFilterScriptInit()
{
word[0] = EOS;//jep it's needed here cuz there could
//be something else inside already at that address.
//needed for that check in OnPlayerText
return 1;
}
public OnPlayerText(playerid, text[])
{
if(word[0] != EOS)
{
if(!strcmp(text,word))//case sensitive
{
new msg[78],pn[MAX_PLAYER_NAME];
GetPlayerName(playerid,pn,sizeof pn);
format(msg,sizeof msg,"%s has solved the scramble! {FFFFFF}%s",pn,text);
SendClientMessageToAll(orange,msg);
word[0] = EOS;
GivePlayerMoney(playerid, 5000);//just use random(); if you want random cash
GameTextForPlayer(playerid,"~g~$ +5000",3000,3);
SendClientMessage(playerid,orange,"Congratulations on solving the scramble!");
return 0;
}
}
return 1;
}
YCMD:scramble(playerid, params[], help)
{
if(help) SendClientMessage(playerid, gray, "/scramble is used to generate a scramble");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,red,"You can't use this!");//replace this with your admin stuff
new s[30];//change size for longer scrambles
if(sscanf(params,"s[31]",s)) return SendClientMessage(playerid,red,"USAGE: /scramble [word]");
strcpy(word,s);
new msg[63];
format(msg, sizeof msg, "Scramble created! your word: %s",s);
SendClientMessage(playerid,-1,msg);
CreateScramble(s);
format(msg, sizeof msg, "Solve the scramble! {FFFFFF}%s",scram);
SendClientMessageToAll(orange,msg);
return 1;
}
stock CreateScramble(s[])
{
new tmp[2], num, len = strlen(s);
for(new i=0; s[i] != EOS; i++)
{
num = random(len);
tmp[0] = s[i];
tmp[1] = s[num];
s[num] = tmp[0];
s[i] = tmp[1];
}
strcpy(scram,s);
return 1;
}