Jump to content
  • 0
Feilor

bindatcomand with switch

Question

I want to use bindatcommand and manipulate it with switch, my players will be able to use numbers or characters like:

@command 1 msg or @command broadcast msg

 

My doubts are:

before use switch([email protected]_parameters$[0]) will I need to use atoi to get number?

can I use case "broadcast": on this?

Thanks :)

Edited by luan122
Link to comment
Share on other sites

14 answers to this question

Recommended Posts

 

I'm sorry I did the question by my cellphone, let me explain:

I made a function to players get out of a pvp room, but they can use it to avoid others players... So I want to prevent it and know if is possible to cancel the event (actualy i'm using sleep2 to count down) and keeps player on the map.

 

you can consider to use progressbar and not sleep2

 

Thanks to show me this option will be usefull :)

 

 

Hey you're right, a progress bar would be nice.

 

I already sent the script to him but I'll add that, it'll be nicer.

 

Thanks /no1

I made alot of changes on the script hahaha I will show it to you soon, including the progressbar :P

 

 

@Community

I got answer for all my questions here they are:

 

 

My doubts are:

before use switch([email protected]_parameters$[0]) will I need to use atoi to get number?

can I use case "broadcast": on this?

 

 

I did this to solve the problem:

OnInit:
	bindatcmd("tokens"		,"TokensFunc::OnTokens",0,99);
	end;

OnTokens:
	@opcao = atoi([email protected]_parameters$[0]);
	@desc = atoi([email protected]_parameters$[1]);
	if([email protected]_parameters$[0] == "entrar") @opcao = 1;
	if([email protected]_parameters$[0] == "info") @opcao = 2;
	if([email protected]_parameters$[0] == "trocar") @opcao = 3;
	if([email protected]_parameters$[0] == "sair") @opcao = 4;
	switch(@opcao){
		case 1:
			"script"
			end;

FYI:  dont use "case 0:" because the [email protected]_parameters$[0] always come as 0 (idk why but it is okay)

 

 

 

 

I'm sorry I did the question by my cellphone, let me explain:

I made a function to players get out of a pvp room, but they can use it to avoid others players... So I want to prevent it and know if is possible to cancel the event (actualy i'm using sleep2 to count down) and keeps player on the map.

 

 

@Kurofly helped me with this and teach me this:

-	script	pvpexit	-1,{
OnInit:
	.TimeToExit = 5; //amount of time before exiting (in seconds)
	bindatcmd "exit",strnpcinfo(0)+"::OnExit";
	end;

OnExit:
	dispbottom "You will exit the map after "+.TimeToExit+" seconds if you're not hurt.";
	@prev_hp = Hp;
	addtimer 100,strnpcinfo(0)+"::OnTimer";
	end;

OnTimer:
	@exittimer++;
	if (Hp < @prev_hp) { dispbottom "You've been hit! exitting cancel..." ; end;  }
        @prev_hp = Hp;
	if (@exittimer >= .TimeToExit*10) { @exittimer = 0 ; warp getsavepoint(0),getsavepoint(1),getsavepoint(2) ; end; }
	addtimer 100,strnpcinfo(0)+"::OnTimer";
}
Edited by luan122
Link to comment
Share on other sites

Tell us exactly what you need to do, that's not really clear ^^

 

You can't use switch with strings because it's supposed to be used with numbers.

Link to comment
Share on other sites

I'm thinking something like this:
@token 0 or @token entrar

the code will be:

OnInit:
bindatcmd("tokens"		,"TokensFunc::OnTokens",0,99);
	end;

OnTokens:
		switch([email protected]_parameters$[0]){
			case 0:
			case "entrar":
				end;
			case 1:
			case "info"
				end;
Edited by luan122
Link to comment
Share on other sites

It is a room that i don't want to use NPC, so the players will use @token (the system is called token) and the token will have a bunch of commands like:

@tokens entrar (entrar = enter)
@tokens info

@tokens trocar (trocar = change)

 

or the player can use:

@tokens 1

@tokens 2

@tokens 3

 

I want to use the both way so I used switch to do that (since switch on languages can do the same i thought I could here :P

 

I have a command called @vip src mod that does the same but I really don't want to make this a src (since the script is easier to change).

 

I'm Brazilian sorry for the bad english ;(

Link to comment
Share on other sites

Guess you can't do that with switch, you'll have to put if statements.

You could do something like this

-	script	tokens	-1,{
OnInit:
	bindatcmd "tokens",strnpcinfo(0)+"::OnTokens";
	end;

OnTokens:
	setarray [email protected]$ , "entrar","info","trocar";
	for ([email protected] = 0 ; [email protected] < getarraysize([email protected]$) ; [email protected]++)
		if ([email protected]_parameters$[0] == [email protected]$[[email protected]]) [email protected] = [email protected];

	switch([email protected]) {
		case 1:
			warp "<location>",<x>,<y>;
			break;
		case 2:
			dispbottom "this is the info";
			break;
		case 3:
			//don't know what you mean by change
			break;
	}
	if ([email protected]) {
		dispbottom "unknown demand.";
		[email protected]$ = [email protected]$;
		for ([email protected] = 1 ; [email protected] < getarraysize([email protected]$) ; [email protected]++) [email protected]$ = [email protected]$ + " , "[email protected]$[[email protected]];
		dispbottom "Possible demands : "[email protected]$;
	}
}

using an array position to convert a string to a number

 

Or you could use 1, 2, 3, etc.. as parameters and so use atoi

 

Combinning the two would be too complicated for what you intend to do

Link to comment
Share on other sites

I will try on my way... if not possible I will turn it a src based since the complexion to do with script, thanks!

Link to comment
Share on other sites

I did with script :P
But used if instead of setarray (easier and noob :( )
and unfortunally I cant use 0 since @tokens keeps [email protected]_parameters$[0] on 0 lol

 

Can I know when someone get hit by script?

Link to comment
Share on other sites

When someone get hit by script? What do you mean by that?

 

You know if you explain what you want to do in details I can surely do it for you. It's up to you.

Link to comment
Share on other sites

I'm sorry I did the question by my cellphone, let me explain:

I made a function to players get out of a pvp room, but they can use it to avoid others players... So I want to prevent it and know if is possible to cancel the event (actualy i'm using sleep2 to count down) and keeps player on the map.

Edited by luan122
Link to comment
Share on other sites

Sorry totally forgot you meanwhile ><

 

But dude I really don't get it, could you please send me a pm to clearly explain the concept to me?

 

Tell me what is supposed to do your script? for whom? why? how? what features?

 

Send me a pm so that I can ask some questions directly.

Link to comment
Share on other sites

I'm sorry I did the question by my cellphone, let me explain:

I made a function to players get out of a pvp room, but they can use it to avoid others players... So I want to prevent it and know if is possible to cancel the event (actualy i'm using sleep2 to count down) and keeps player on the map.

 

you can consider to use progressbar and not sleep2

  • Upvote 1
Link to comment
Share on other sites

Hey you're right, a progress bar would be nice.

 

I already sent the script to him but I'll add that, it'll be nicer.

 

Thanks /no1

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.