Jump to content
  • 0

bindatcomand with switch


Question

Posted (edited)

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

14 answers to this question

Recommended Posts

Posted (edited)

 

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
Posted (edited)

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
Posted

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 ;(

Posted

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

Posted

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?

Posted (edited)

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
Posted

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.

Posted

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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...