String combination in code -
pascallj - 27.06.2009
Hello everyone again,
I need this at a lot of things so it's a regular question:
Is it possible to put a combination of strings inside a code rule?
Example:
Код:
GivePlayerWeapon(playerid, (**), 500);
**= A combination of 2 strings.
I've got now this:
Код:
new wep0 = 1, wep1, wep2, wep3, wep4, wep5, wep6, wep7, wep8, wep9, wep10, wep11, wep12, wep13, wep14, wep15, wep16, wep17, wep18, wep19, wep20,
wep21, wep22, wep23, wep24, wep25, wep26, wep27, wep28, wep29, wep30, wep31, wep32, wep33, wep34, wep35, wep36, wep37, wep38, wep39, wep40, wep41,
wep42, wep43;
GivePlayerWeapon(playerid, (**), 500);
And when a player types: "/weapon [a number], a number is saved in a variable.
Now I want that ** a combination is of "wep" and then the variable so it reads this combination as 1 string and read then the string out.
Example:
I type: "/weapon 0"
The variable contains 0. The string wep0 contains 1. So, GivePlayerWeapon's weaponid is (wep0) and I get weapon with ID 1 and 500 ammo.
You can also see it like this in Vb.net:
Код:
Dim thevariable as Integer = 1
Msgbox("wep" & thevariable)
Re: String combination in code -
dice7 - 27.06.2009
wep0, wep1 and so on are not strings. They are integers. And you can use it like that. But I suggest you using arrays
Re: String combination in code -
pascallj - 27.06.2009
Yes you're right, but how can I use it? And what if I make them strings? How can I use it then. And I know it is not the best method, but I need this for a lot of other things too. And arrays... I think it isn't possible because, I need to make each integer/string it's own code. There is not a logic method in it.
Re: String combination in code -
dice7 - 27.06.2009
Oh, now I understand what you want. I think something like this should work
pawn Код:
new weap[10/*how many weapon ids*/] = {
14, 23, 13, 64, 45, 46, 7, 28, 39, 31 //weapon id's
};
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/weapon", true, 5)==0)
{
if(!strlen(cmdtext[6]))
{
SendClientMessage(playerid, 0xFF0000AA, "Use: /weapon [id]");
return 1;
}
new ID = strval(cmdtext[8]);
GivePlayerWeapon(playerid, weap[ID], 500);
return 1;
}
return 0;
}
Re: String combination in code -
pascallj - 28.06.2009
My code is now this:
Код:
if (strcmp(cmd, "/weapon", true) == 0) {
if (cmdtext[7] == 0) {
SendClientMessage(playerid, COLOR_RED, "Usage: /weapon [weapon number], '/weapon help[0-11]' for weapon numbers.");
return 1;
}
if (cmdtext[8] == 0) {
SendClientMessage(playerid, COLOR_RED, "Usage: /weapon [weapon number], '/weapon help[0-11]' for weapon numbers.");
return 1;
}
new packnumber[7];
format(packnumber, sizeof(packnumber), cmdtext[8]);
if (strcmp(packnumber, "help") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 0: Vist, Slot 1: Melee, Slot 2: Pistols, Slot 3: Shotguns");
SendClientMessage(playerid, COLOR_YELLOW, "Slot 4: SMG's, Slot 5: Assault, Slot 6: Rifles, Slot 7: Launcher & Minigun");
SendClientMessage(playerid, COLOR_YELLOW, "Slot 8: Bombs, Slot 9: Specials, Slot 10: Special melee, Slot 11: Visions & Parachute");
return 1;
}
if (strcmp(packnumber, "help0") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 0: Reset all weapons - 0, Unarmed - 1, Brass knuckles - 2");
return 1;
}
if (strcmp(packnumber, "help1") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 1: Golf club - 3, Nite stick - 4, Knife - 5, Baseball bat - 6");
SendClientMessage(playerid, COLOR_YELLOW, "Shovel - 7, Pool cue - 8, Katana - 9, Chainsaw - 10");
return 1;
}
if (strcmp(packnumber, "help2") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 2: 9mm - 11, Silenced 9mm - 12, Desert Eagle - 13");
return 1;
}
if (strcmp(packnumber, "help3") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 3: Shotgun - 14, Sawnoff shotgun - 15, Combat Shotgun - 16");
return 1;
}
if (strcmp(packnumber, "help4") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 4: Micro SMG - 17, SMG - 18, Tec 9 - 19");
return 1;
}
if (strcmp(packnumber, "help5") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 5: AK47 - 20, M4 - 21");
return 1;
}
if (strcmp(packnumber, "help6") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 6: Country rifle - 22, Sniper rifle - 23");
return 1;
}
if (strcmp(packnumber, "help7") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 7: Rocket Launcher - 24, HS Rocket Launcher - 25, Flamethrower - 26");
SendClientMessage(playerid, COLOR_YELLOW, "Minigun - 27");
return 1;
}
if (strcmp(packnumber, "help8") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 8: Satchel Charge - 28, Grenade - 29, Tear Gas - 30, Molotov Cocktail - 31");
return 1;
}
if (strcmp(packnumber, "help9") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 9: Spraycan - 32, Fire Extinguisher - 33, Camera - 34");
return 1;
}
if (strcmp(packnumber, "help10") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 10: Purple Dildo - 35, Small White Vibrator - 36, Large White Vibrator - 37");
SendClientMessage(playerid, COLOR_YELLOW, "Silver Vibrator - 38, Flowers - 39, Cane - 40");
return 1;
}
if (strcmp(packnumber, "help11") == 0) {
SendClientMessage(playerid, COLOR_YELLOW, "Slot 11: Nightvision Goggles - 41, Infrared Vision - 42, Parachute - 43");
return 1;
}
new weap[43] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33, 34, 35,
36, 37, 38, 39, 16, 17, 18, 41, 42, 43, 10, 11, 12, 13, 14, 15, 44, 45, 46 //weapon id's
};
new ID = strval(cmdtext[8]);
GivePlayerWeapon(playerid, weap[ID], 500);
return 1;
}
And it works, except that all numbers are one too far, because I want reset all weapons on 0. But i'll fix that later.
But i really don't understand what it does, That "weap[43]..." and "weap[ID]".
Re: String combination in code -
pascallj - 28.06.2009
Can anyone explain it?