get user online - help
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

get user online - help

Started by Madman, 06 November, 2004, 19:43:41

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

local _,_,cmd=strfind(data, "%b<>%s+(%S+).+")
		local User = curUser.sName
		local _,_,junk=strfind(data, "%b<>%s+%S+%s+(%S+)")
			if cmd == "!attack" then
				local answer,victim = Attacks[random(getn(Attacks))], junk
				answer = gsub( answer, "(%[CURUSER%])", User )
				answer = gsub( answer, "(%[VIC%])", victim ) 
					SendToAll( answer.."|" )
			end

can any one make this code, so the user only can write a name that is online?

and that is sends a text to the user that he wrote wrong name... and the user is not online...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Herodes

#1
This is a nice opportunity to see how code can shrink ...
and how usefull or disastrous it can be

Here we go ..
part 1 : a very spread out  thing ...
local _,_,cmd = strfind(data, "%b<>%s+(%S+)")
	local _,_,otherUser = strfind( data, "%b<>%s+%S+%s+(%S+)")
	if cmd == "!attack" then
		local isUser = GetItemByName(otherUser)
		if (isUser) then
			local answer =  Attacks[random(getn(Attacks))]
			answer = gsub( answer, "(%[CURUSER%])", curUser.sName )
			answer = gsub( answer, "(%[VIC%])", otherUser )
			SendToAll( answer )
		end
	end

part2 : lets cut some stuff ...
this is fairly ok .. but it can go further ..
local _,_,cmd, otherUser = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if cmd == "!attack" then
		local otherUser = GetItemByName(otherUser)
		if (otherUser) then
			local answer =  Attacks[random(getn(Attacks))]
			answer = gsub( answer, "(%[CURUSER%])", curUser.sName )
			answer = gsub( answer, "(%[VIC%])", otherUser.sName )
			SendToAll( answer )
		end
	end

part 3 : Lets cut some more ...
making it in effect readable by anyone with a little knowledge ...
local _,_,cmd, otherUser = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if cmd == "!attack" then
		local otherUser = GetItemByName(otherUser)
		if (otherUser) then
			local answer =  Attacks[random(getn(Attacks))]
			answer = gsub( answer, "(%[CURUSER%])", curUser.sName )
			SendToAll( gsub( answer, "(%[VIC%])", otherUser.sName ))
		end
	end
part 4: now it is getting even shorter ..
this is comfy for most scripters .. although it is not read without effort as the above ..
local _,_,cmd, otherUser = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if cmd == "!attack" then
		local otherUser = GetItemByName(otherUser)
		if (otherUser) then
			local answer = gsub( Attacks[random(getn(Attacks))], "(%[CURUSER%])", curUser.sName )
			SendToAll( gsub( answer, "(%[VIC%])", otherUser.sName ))
		end
	end
part 5 : this is not recommended unless you feel comfortable with it ...
it is not easy to maintain ...
local _,_,cmd, otherUser = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if cmd == "!attack" then
		local otherUser = GetItemByName(otherUser)
		if (otherUser) then
			SendToAll( gsub( gsub( Attacks[random(getn(Attacks))], "(%[CURUSER%])", curUser.sName ), "(%[VIC%])", otherUser.sName ))
		end
	end

Madman

Thanks, that helped alot =)
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk