AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   switch problems (https://forums.alliedmods.net/showthread.php?t=29407)

shino 06-05-2006 07:08

switch problems
 
i would like to "rename" all weapons from CSW_*** to "***"...
i was thinking of something like this:
Code:
switch(weap) {     case CSW_AK47: "ak47"     case CSW_AUG: "aug"     case CSW_AWP: "awp"     case CSW_DEAGLE: "deagle"     case CSW_ELITE: "elite"     case CSW_FAMAS: "famas"     case CSW_FIVESEVEN: "fiveseven"     case CSW_G3SG1: "g3sg1"     case CSW_GALIL: "galil"     case CSW_GLOCK18: "glock18"     case CSW_HEGRENADE: "hegrenade"     case CSW_KNIFE: "knife"     case CSW_M249: "m249"     case CSW_M3: "m3"     case CSW_M4A1: "m4a1"     case CSW_MAC10: "mac10"     case CSW_MP5NAVY: "mp5navy"     case CSW_P228: "p228"     case CSW_P90: "p90"     case CSW_SCOUT: "scout"     case CSW_SG550: "sg550"     case CSW_SG552: "sg552"     case CSW_TMP: "tmp"     case CSW_UMP45: "ump45"     case CSW_USP: "usp"     case CSW_XM1014: "xm1014" }

help, please :)

Hawk552 06-05-2006 08:37

What's your question?

If you're looking to use give_item, those won't work, you'll need to use weapon_<name>.

shino 06-05-2006 09:17

sorry.

here's the code:
Code:
public plugin_init() {     register_plugin( PLUGINNAME, VERSION, AUTHOR )     register_event( "Damage", "DealDamage", "be" ); } public DealDamage(id,headshot) {     new victim, attacker, damage, weap, iweap     victim = id     attacker = get_user_attacker(victim, weap)     damage = read_data(2)     switch(iweap) {         case weap == CSW_AK47: "ak47"         case weap == CSW_AUG: "aug"         case weap == CSW_AWP: "awp"         case weap == CSW_DEAGLE: "deagle"         case weap == CSW_ELITE: "elite"         case weap == CSW_FAMAS: "famas"         case weap == CSW_FIVESEVEN: "fiveseven"         case weap == CSW_G3SG1: "g3sg1"         case weap == CSW_GALIL: "galil"         case weap == CSW_GLOCK18: "glock18"         case weap == CSW_HEGRENADE: "hegrenade"         case weap == CSW_KNIFE: "knife"         case weap == CSW_M249: "m249"         case weap == CSW_M3: "m3"         case weap == CSW_M4A1: "m4a1"         case weap == CSW_MAC10: "mac10"         case weap == CSW_MP5NAVY: "mp5navy"         case weap == CSW_P228: "p228"         case weap == CSW_P90: "p90"         case weap == CSW_SCOUT: "scout"         case weap == CSW_SG550: "sg550"         case weap == CSW_SG552: "sg552"         case weap == CSW_TMP: "tmp"         case weap == CSW_UMP45: "ump45"         case weap == CSW_USP: "usp"         case weap == CSW_XM1014: "xm1014"     }     if (weap == CSW_AK47 || weap == CSW_AUG || weap == CSW_AWP || weap == CSW_DEAGLE ||     weap == CSW_ELITE || weap == CSW_FAMAS || weap == CSW_FIVESEVEN || weap == CSW_G3SG1 ||     weap == CSW_GALIL || weap == CSW_GLOCK18 || weap == CSW_HEGRENADE || weap == CSW_KNIFE ||     weap == CSW_M249 || weap == CSW_M3 || weap == CSW_M4A1 || weap == CSW_MAC10 ||     weap == CSW_MP5NAVY || weap == CSW_P228 || weap == CSW_P90 || weap == CSW_SCOUT ||     weap == CSW_SG550 || weap == CSW_SG552 || weap == CSW_TMP || weap == CSW_UMP45 ||     weap == CSW_USP || weap == CSW_XM1014) {         if (damage > 0) {             user_silentkill(victim)                     make_deathmsg(attacker,victim,headshot,iweap)         }     } }
that's how i imagined it, but it doesn't work

Xanimos 06-05-2006 16:12

That is not how switches work. Switches are essentially a bunch of if statments.
Code:
swith(weap) {     case CSW_GLOCK18: <somthing>     case CSW_USP: <something2> }

is the same as doing

Code:
if(weap == CSW_GLOCK18)     <something> else if(weap == CSW_USP)     <something2>

But switches are faster when using a lot of cases.

v3x 06-06-2006 05:09

Code:
new szweap[21]; get_weaponname(attacker , szweap , 20); make_deathmsg(attacker , victim , headshot , szweap);


All times are GMT -4. The time now is 16:30.

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