Jump to content
  • 0

bindatcomand with switch


Feilor

Question


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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(.@atcmd_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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

 

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(.@atcmd_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(.@atcmd_parameters$[0]);
	@desc = atoi(.@atcmd_parameters$[1]);
	if(.@atcmd_parameters$[0] == "entrar") @opcao = 1;
	if(.@atcmd_parameters$[0] == "info") @opcao = 2;
	if(.@atcmd_parameters$[0] == "trocar") @opcao = 3;
	if(.@atcmd_parameters$[0] == "sair") @opcao = 4;
	switch(@opcao){
		case 1:
			"script"
			end;

FYI:  dont use "case 0:" because the .@atcmd_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


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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(.@atcmd_parameters$[0]){
			case 0:
			case "entrar":
				end;
			case 1:
			case "info"
				end;
Edited by luan122
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

What is your script supposed to do?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

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 .@list$ , "entrar","info","trocar";
	for (.@i = 0 ; .@i < getarraysize(.@list$) ; .@i++)
		if (.@atcmd_parameters$[0] == .@list$[.@i]) .@num = .@i;

	switch(.@num) {
		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 (!.@num) {
		dispbottom "unknown demand.";
		.@demands$ = .@list$;
		for (.@i = 1 ; .@i < getarraysize(.@list$) ; .@i++) .@demands$ = .@demands$ + " , "+.@list$[.@i];
		dispbottom "Possible demands : "+.@demands$;
	}
}

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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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

 

Can I know when someone get hit by script?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   17
  • Joined:  12/31/11
  • Last Seen:  

someone? x.x

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

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


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

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...