PDA

View Full Version : check the first letter of scriptmenu response



Ni3ls
13th July 2015, 13:42
Hi all,

Im making some menu with a lot of scriptmenu responses for primary weapon and secondary weapon in the same .menu file
for all the primary weapons i put a "x" in front of the name. xgreasegun_mp, xkar98k_mp for example. In front of the the secondary weapons I wrote a "z", like zluger_mp and zcolt_mp.
I want to make a smart weapon function. If name of the response start with a "x" , remove the "x" and use it as self.primary. If it has a "z" in front, remove the "z" and use it as self.secondary.

How to do this? I dont have any clue at all

filthy_freak_
13th July 2015, 14:11
if(getSubStr(response, 0, 1) == "x")
{
newresponse = getSubStr(response, 1, response.size);
return newresponse;
}

IzNoGoD
13th July 2015, 15:27
if(response[0] == "x")
{
return getsubstr(response, 1);
}


For a single char you dont need to use substr
Substr will work without a third input, itll just go on until the end (might be lighter on cpu, not sure)

Ni3ls
13th July 2015, 16:10
Trying it with playermodels now
SNIPPET

if(menu == "huntmodel")
{
if(response == "menuopen")
{
self setclientcvar("dvar_yourhelmet", self.helmet);
self setclientcvar("dvar_yourbody", self.body);
self setclientcvar("dvar_yourhead", self.head);
}

if(response == "playerbody_american_normandy01")
{
self.body= response;
self setclientcvar("dvar_yourbody", self.body);
self closeMenu();
self closeInGameMenu();
self iprintlnbold("body:"+response);
}

It does show the right dvars when I open it. However, when I click on the first model with response "playerbody_american_normandy01" nothing happens.
huntmodel.menu

itemDef
{
name "body"
visible 1
rect 0 0 70 22
origin ORIGIN_CHOICE5
forecolor GLOBAL_UNFOCUSED_COLOR
type ITEM_TYPE_BUTTON
text "^7Normandy ^31"
textfont UI_FONT_NORMAL
textscale .30
textstyle ITEM_TEXTSTYLE_SHADOWED
textaligny 20
dvartest "language"
showDvar { "1" }
action
{
play "mouse_click";
scriptMenuResponse "playerbody_american_normandy01";
}
onFocus
{
play "mouse_over";
}
}

Ni3ls
13th July 2015, 19:03
Sorry for double post but else post will be too long

else if(menu == "huntmodel")
{

self closeMenu();
self closeInGameMenu();
self iprintlnbold("Response: "+response);
}
Even this is not working, but the menu is loaded with

self closeMenu();
self closeInGameMenu();
self openMenu("huntmodel");
and does open.
Tested with developer 1, but how to see if there is an error inside the menu?

IzNoGoD
14th July 2015, 00:08
Open extended console, check for errors (clientside)(as menus are mostly clientside)

Ni3ls
14th July 2015, 09:05
No errors at all :(

EDIT: Found the solution. It had another menudef name, so the menu what was called had another name. Thats why menuopen was working (menudef name is huntmodel) and the other not working (menudef name bodies)